Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
|
Go to the documentation of this file.
40 #include "../library/lib.h"
60 static const void* s_vpMagicNumber = (
void*)
"lines_u";
78 static void vInputLines(
lines_u* spCtx);
94 if(!uipInput || !uiLength){
95 XTHROW(spEx,
"input is NULL or empty");
100 memset((
void*)spCtx, 0,
sizeof(
lines_u));
101 spCtx->uipInput = (uint32_t*)
vpMemAlloc(vpMem, ((
sizeof(uint32_t) * uiLength)));
102 memcpy((
void*)spCtx->uipInput, (
void*)uipInput, (
sizeof(uint32_t) * uiLength));
103 spCtx->uiLength = uiLength;
104 spCtx->vpMem = vpMem;
105 spCtx->spException = spEx;
110 spCtx->vpValidate = s_vpMagicNumber;
131 void* vpMem = spCtx->
vpMem;
132 memset(vpCtx, 0,
sizeof(
lines_u));
152 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
153 if(!uipLine || !uipRelOffset){
175 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
189 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
206 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
222 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
231 if (!spLines || !uiLineCount) {
236 if (uiLineCount < 5) {
238 for (ui = 0; ui < uiLineCount; ui += 1) {
239 spThis = &spLines[ui];
249 aint uiR = uiLineCount - 1;
252 uiM = uiL + (uiR - uiL) / 2;
253 spThis = &spLines[uiM];
254 if (uiCharIndex >= (spThis->uiCharIndex + spThis->uiLineLength)) {
258 if (uiCharIndex < spThis->uiCharIndex) {
266 spThis = &spLines[uiL];
267 if ((uiCharIndex >= spThis->uiCharIndex) && (uiCharIndex < (spThis->uiCharIndex + spThis->uiLineLength))) {
283 static void vInputLines(
lines_u* spCtx) {
284 aint uiLineIndex = 0;
285 aint uiCharIndex = 0;
286 aint uiTextLength = 0;
290 uint32_t* uipInput = spCtx->
uipInput;
293 while (uiCharIndex < uiLen) {
294 uiChar = uipInput[uiCharIndex];
295 if (uiChar ==
LF || uiChar ==
VT || uiChar ==
FF || uiChar ==
NEL || uiChar ==
LS || uiChar ==
PS ) {
308 }
else if (uiChar ==
CR) {
312 if ((uiCharIndex < (uiLen - 1)) && (uipInput[uiCharIndex + 1] ==
LF)) {
335 if (uiTextLength > 0) {
aint uiLineIndex
zero-based line number
exception * spException
Pointer to an exception structure to report fatal errors back to the application's catch block.
void vMemDtor(void *vpCtx)
Destroys a Memory component. Frees all memory allocated.
void * vpLinesuCtor(exception *spEx, const uint32_t *uipInput, aint uiLength)
The linesu object constructor.
#define LS
Line Separator.
aint uiIterator
Used by the iterator.
line_u * spLinesuNext(void *vpCtx)
Returns the next line from the iterator.
Carries detailed information about the characters and line endings. One for each line in the input gr...
#define CR
Carriage Return.
aint uiTextLength
number of Unicode text characters in the line, excluding line end characters
void vExContext()
Handles bad context pointers.
aint uiLength
Number of integers in the array.
The lines object context.
#define XTHROW(ctx, msg)
Exception throw macro.
uint_fast32_t aint
The APG parser's unsigned integer type.
void * vpMemAlloc(void *vpCtx, aint uiBytes)
Allocates memory.
aint uiLineCount
Number of lines in the array.
aint uiVecLen(void *vpCtx)
Get the vector length. That is, the number of elements on the vector.
void * vpVecCtor(void *vpMem, aint uiElementSize, aint uiInitialAlloc)
The vector object constructor.
uint32_t * uipInput
Pointer to the 32-bit integer array.
abool bLinesuFindLine(void *vpCtx, aint uiOffset, aint *uipLine, aint *uipRelOffset)
Find the line that the given integer is in.
A structure to describe the type and location of a caught exception.
const void * vpValidate
A "magic number" to validate the context.
line_u * spLines
Pointer to the first line.
abool bExValidate(exception *spException)
Test an exception structure for validity.
line_u * spLinesuFirst(void *vpCtx)
Initialize an iterator over the lines.
void * vpVecFirst(void *vpCtx)
Get the first element one the vector. The vector is not altered.
void * vpMemCtor(exception *spException)
Construct a memory component.
void * vpVecLines
Pointer to a vector of parsed lines.
uint8_t abool
abool is the APG bool type.
uint32_t uiaLineEnd[3]
the actual string of line ending character(s), if any
#define PS
Paragraph Separator.
void * vpMem
Pointer to a memory object for allocating all memory associated with this object.
void vLinesuDtor(void *vpCtx)
The linesu object destructor.
aint uiLinesuCount(void *vpCtx)
Returns the number of lines.
Header file for the 32-bit integer version of the lines objects.
void * vpVecPush(void *vpCtx, void *vpElement)
Adds one element to the end of the array.
aint uiLinesuLength(void *vpCtx)
Returns the number of integers in the 32-bit integer array.
aint uiLineLength
number of Unicode characters in the line, including line end characters
void vVecClear(void *vpCtx)
Clears all used elements in a vector component.
aint uiCharIndex
zero-based index of the first Unicode character of the line
APG Version 7.0 is licensed under the
2-Clause BSD License,
an Open Source Initiative Approved License.