Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
|
Go to the documentation of this file.
44 #include "../library/lib.h"
53 static const void* s_vpMagicNumber = (
void*)
"lines";
71 static void vInputLines(
lines* spCtx);
87 if(!cpInput || !uiLength){
88 XTHROW(spEx,
"input is NULL or empty");
93 memset((
void*)spCtx, 0,
sizeof(
lines));
97 memcpy((
void*)spCtx->cpInput, (
void*)cpInput, (
sizeof(
char) * uiLength));
98 spCtx->uiLength = uiLength;
101 spCtx->vpMem =
vpMem;
102 spCtx->spException = spEx;
107 spCtx->vpValidate = s_vpMagicNumber;
128 memset(vpCtx, 0,
sizeof(
lines));
149 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
150 if(!uipLine || !uipRelOffset){
172 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
187 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
204 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
220 if(vpCtx && (spCtx->
vpValidate == s_vpMagicNumber)){
229 if (!spLines || !uiLineCount) {
234 if (uiLineCount < 5) {
236 for (ui = 0; ui < uiLineCount; ui += 1) {
237 spThis = &spLines[ui];
247 aint uiR = uiLineCount - 1;
250 uiM = uiL + (uiR - uiL) / 2;
251 spThis = &spLines[uiM];
252 if (uiCharIndex >= (spThis->uiCharIndex + spThis->uiLineLength)) {
256 if (uiCharIndex < spThis->uiCharIndex) {
264 spThis = &spLines[uiL];
265 if ((uiCharIndex >= spThis->uiCharIndex) && (uiCharIndex < (spThis->uiCharIndex + spThis->uiLineLength))) {
281 static void vInputLines(
lines* spCtx) {
282 aint uiLineIndex = 0;
283 aint uiCharIndex = 0;
284 aint uiTextLength = 0;
288 const char* cpInput = spCtx->
cpInput;
291 while (uiCharIndex < uiLen) {
292 cChar = cpInput[uiCharIndex];
306 }
else if (cChar ==
CR) {
310 if ((uiCharIndex < (uiLen - 1)) && (cpInput[uiCharIndex + 1] ==
LF)) {
333 if (uiTextLength > 0) {
aint uiLineLength
The number of characters in the line, including the line end characters.
Header file for the lines object.
void * vpLinesCtor(exception *spEx, const char *cpInput, aint uiLength)
The lines object constructor.
void vMemDtor(void *vpCtx)
Destroys a Memory component. Frees all memory allocated.
void * vpMem
Pointer to a memory object for allocating all memory associated with this object.
aint uiLinesLength(void *vpCtx)
Returns the number of text characters.
void vExContext()
Handles bad context pointers.
abool bLinesFindLine(void *vpCtx, aint uiOffset, aint *uipLine, aint *uipRelOffset)
Find the line that the given character is in.
const void * vpValidate
A "magic number" to validate the context.
#define XTHROW(ctx, msg)
Exception throw macro.
The lines object context.
uint_fast32_t aint
The APG parser's unsigned integer type.
char * cpInput
Pointer to the character array.
void * vpMemAlloc(void *vpCtx, aint uiBytes)
Allocates memory.
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.
line * spLines
Pointer to the first line.
A structure to describe the type and location of a caught exception.
aint uiIterator
Used by the iterator.
aint uiLineIndex
The zero-based line index.
abool bExValidate(exception *spException)
Test an exception structure for validity.
aint uiLineCount
Number of lines in the array.
aint uiTextLength
The number of characters in the line, excluding the line end characters.
void * vpVecFirst(void *vpCtx)
Get the first element one the vector. The vector is not altered.
Defines the characteristics of a single line.
void * vpMemCtor(exception *spException)
Construct a memory component.
line * spLinesNext(void *vpCtx)
Returns the next line of text from the iterator.
aint uiLength
Number of characters in the array.
exception * spException
Pointer to an exception structure to report fatal errors back to the application's catch block.
line * spLinesFirst(void *vpCtx)
Initialize an iterator over the lines.
void * vpMem
Pointer to a memory object for allocating all memory associated with this object.
void vLinesDtor(void *vpCtx)
The lines object destructor.
uint8_t abool
abool is the APG bool type.
void * vpVecLines
Pointer to a vector of parsed lines.
char caLineEnd[3]
The actual, null-terminated string of line ending character(s), if any.
void * vpVecPush(void *vpCtx, void *vpElement)
Adds one element to the end of the array.
void vVecClear(void *vpCtx)
Clears all used elements in a vector component.
aint uiCharIndex
The zero-based index of the first character of the line.
aint uiLinesCount(void *vpCtx)
Returns the number of lines of text.
APG Version 7.0 is licensed under the
2-Clause BSD License,
an Open Source Initiative Approved License.