Leptonica 1.68
C Image Processing Library
|
Functions for handling byte arrays, in analogy with C++ 'strings'. More...
Go to the source code of this file.
Functions for handling byte arrays, in analogy with C++ 'strings'.
Functions for handling byte arrays, in analogy with C++ 'strings' Creation, copy, clone, destruction L_BYTEA *l_byteaCreate() L_BYTEA *l_byteaInitFromMem() L_BYTEA *l_byteaInitFromFile() L_BYTEA *l_byteaInitFromStream() L_BYTEA *l_byteaCopy() L_BYTEA *l_byteaClone() void l_byteaDestroy() Accessors size_t l_byteaGetSize() l_uint8 *l_byteaGetData() l_uint8 *l_byteaCopyData() Appending l_int32 l_byteaAppendData() l_int32 l_byteaAppendString() l_int32 l_byteaExtendArrayToSize() Join/Split l_int32 l_byteaJoin() l_int32 l_byteaSplit() Search l_int32 l_byteaFindEachSequence() Output to file l_int32 l_byteaWrite() l_int32 l_byteaWriteStream() The internal data array is always null-terminated, for ease of use in the event that it is an ascii string without null bytes.
Definition in file bytearray.c.
L_BYTEA* l_byteaCreate | ( | size_t | nbytes | ) |
Input: n (determines initial size of data array) Return: l_bytea, or null on error
Notes: (1) The allocated array is n + 1 bytes. This allows room for null termination.
Definition at line 75 of file bytearray.c.
References CALLOC, L_Bytea::data, ERROR_PTR, INITIAL_ARRAYSIZE, L_Bytea::nalloc, NULL, PROCNAME, and L_Bytea::refcount.
Referenced by l_byteaInitFromMem(), l_byteaInitFromStream(), main(), pathJoin(), ptraConcatenatePdfToData(), and substituteObjectNumbers().
Input: data (to be copied to the array) size (amount of data) Return: l_bytea, or null on error
Definition at line 104 of file bytearray.c.
References L_Bytea::data, ERROR_PTR, l_byteaCreate(), NULL, PROCNAME, size, and L_Bytea::size.
Referenced by convertSegmentedFilesToPdf(), l_byteaCopy(), l_byteaSplit(), main(), ptraConcatenatePdfToData(), and saConvertFilesToPdfData().
L_BYTEA* l_byteaInitFromFile | ( | const char * | fname | ) |
Input: fname Return: l_bytea, or null on error
Definition at line 131 of file bytearray.c.
References ERROR_PTR, fopenReadStream(), l_byteaInitFromStream(), NULL, and PROCNAME.
Referenced by main(), and saConcatenatePdfToData().
L_BYTEA* l_byteaInitFromStream | ( | FILE * | fp | ) |
Input: stream Return: l_bytea, or null on error
Definition at line 157 of file bytearray.c.
References L_Bytea::data, ERROR_PTR, FREE, l_binaryReadStream(), l_byteaCreate(), NULL, PROCNAME, and L_Bytea::size.
Referenced by l_byteaInitFromFile().
Input: bas (source lba) copyflag (L_COPY, L_CLONE) Return: clone or copy of bas, or null on error
Notes: (1) If cloning, up the refcount and return a ptr to .
Definition at line 190 of file bytearray.c.
References L_Bytea::data, ERROR_PTR, l_byteaInitFromMem(), L_CLONE, NULL, PROCNAME, L_Bytea::refcount, and L_Bytea::size.
void l_byteaDestroy | ( | L_BYTEA ** | pba | ) |
Input: &ba (<will be="" set="" to="" null="" before="" returning>="">) Return: void
Notes: (1) Decrements the ref count and, if 0, destroys the lba. (2) Always nulls the input ptr. (3) If the data has been previously removed, the lba will have been nulled, so this will do nothing.
Definition at line 220 of file bytearray.c.
References L_Bytea::data, FREE, L_WARNING, NULL, PROCNAME, and L_Bytea::refcount.
Referenced by convertSegmentedFilesToPdf(), l_byteaJoin(), main(), pathJoin(), ptraConcatenatePdfToData(), saConcatenatePdfToData(), and saConvertFilesToPdfData().
size_t l_byteaGetSize | ( | L_BYTEA * | ba | ) |
Input: ba Return: size of stored byte array, or 0 on error
Definition at line 256 of file bytearray.c.
References ERROR_INT, PROCNAME, and L_Bytea::size.
Referenced by l_byteaAppendData(), l_byteaAppendString(), main(), and ptraConcatenatePdfToData().
Input: ba &size (<returned> size of data in lba) Return: ptr to existing data array, or NULL on error
Notes: (1) The returned ptr is owned by . Do not free it!
Definition at line 277 of file bytearray.c.
References L_Bytea::data, ERROR_PTR, NULL, PROCNAME, and L_Bytea::size.
Referenced by l_byteaCopyData(), l_byteaFindEachSequence(), l_byteaJoin(), l_byteaSplit(), l_byteaWriteStream(), main(), parseTrailerPdf(), ptraConcatenatePdfToData(), and substituteObjectNumbers().
Input: ba &size (<returned> size of data in lba) Return: copy of data in use in the data array, or null on error.
Notes: (1) The returned data is owned by the caller. The input still owns the original data array.
Definition at line 304 of file bytearray.c.
References ERROR_PTR, l_binaryCopy(), l_byteaGetData(), NULL, and PROCNAME.
Referenced by pathJoin(), and ptraConcatenatePdfToData().
Input: ba newdata (byte array to be appended) size (size of data array) Return: 0 if OK, 1 on error
Definition at line 334 of file bytearray.c.
References L_Bytea::data, ERROR_INT, l_byteaExtendArrayToSize(), l_byteaGetSize(), L_Bytea::nalloc, PROCNAME, L_Bytea::size, and size.
Referenced by l_byteaJoin(), ptraConcatenatePdfToData(), and substituteObjectNumbers().
Input: ba str (null-terminated string to be appended) Return: 0 if OK, 1 on error
Definition at line 367 of file bytearray.c.
References L_Bytea::data, ERROR_INT, l_byteaExtendArrayToSize(), l_byteaGetSize(), L_Bytea::nalloc, PROCNAME, L_Bytea::size, and size.
Referenced by main(), pathJoin(), ptraConcatenatePdfToData(), and substituteObjectNumbers().
Input: ba size (new size of lba data array) Return: 0 if OK; 1 on error
Definition at line 400 of file bytearray.c.
References L_Bytea::data, ERROR_INT, L_Bytea::nalloc, NULL, PROCNAME, reallocNew(), and size.
Referenced by l_byteaAppendData(), and l_byteaAppendString().
Input: ba1 &ba2 (data array is added to the one in ba1, and then ba2 is destroyed) Return: 0 if OK, 1 on error
Notes: (1) It is a no-op, not an error, for to be null.
Definition at line 434 of file bytearray.c.
References ERROR_INT, l_byteaAppendData(), l_byteaDestroy(), l_byteaGetData(), NULL, and PROCNAME.
Referenced by main().
Input: ba1 (lba to split; array bytes nulled beyond the split loc) splitloc (location in ba1 to split; ba2 begins there) &ba2 (<return> with data starting at splitloc) Return: 0 if OK, 1 on error
Definition at line 466 of file bytearray.c.
References ERROR_INT, l_byteaGetData(), l_byteaInitFromMem(), NULL, PROCNAME, and L_Bytea::size.
Referenced by main().
Input: ba sequence (subarray of bytes to find in data) seqlen (length of sequence, in bytes) &na (<return> byte positions of each occurrence of ) Return: 0 if OK, 1 on error
Definition at line 509 of file bytearray.c.
References arrayFindEachSequence(), ERROR_INT, l_byteaGetData(), NULL, PROCNAME, and size.
Referenced by main(), and parseTrailerPdf().
Input: fname (output file) ba startloc (first byte to output) endloc (last byte to output; use 0 to write to the end of the data array) Return: 0 if OK, 1 on error
Definition at line 547 of file bytearray.c.
References ERROR_INT, fopenWriteStream(), l_byteaWriteStream(), NULL, and PROCNAME.
Input: stream (opened for binary write) ba startloc (first byte to output) endloc (last byte to output; use 0 to write to the end of the data array) Return: 0 if OK, 1 on error
Definition at line 581 of file bytearray.c.
References ERROR_INT, l_byteaGetData(), PROCNAME, and size.
Referenced by l_byteaWrite(), and main().
const l_int32 INITIAL_ARRAYSIZE = 200 [static] |
Definition at line 58 of file bytearray.c.
Referenced by l_byteaCreate().