X11workbench Toolkit
1.0
|
Generic Utility functions for copying and manipulating text. More...
Modules | |
XML-specific Text Utilities | |
Specialized text utility functions for parsing XML data. | |
Macros | |
#define | NEXT_WORD(pX, pY, pZ) {while(*(pX) && *(pX) <= ' '){(pX)++;} (pY)=(pZ)=(pX); while(*(pX)>' '){(pX)++;} (pZ)=(pX);} |
Obtain the 'next word' within a string pointed to by pX, bounded by pY and pZ. More... | |
Functions | |
char * | WBCopyString (const char *pSrc) |
A simple utility that returns a WBAlloc() copy of a 0-byte terminated string. More... | |
char * | WBCopyStringN (const char *pSrc, unsigned int nMaxChars) |
A simple utility that returns a WBAlloc() copy of a string up to a maximum length (can also be 0-byte terminated) More... | |
void | WBCatString (char **ppDest, const char *pSrc) |
A simple utility that concatenates a string onto the end of a 0-byte terminated WBAlloc() string. More... | |
void | WBCatStringN (char **ppDest, const char *pSrc, unsigned int nMaxChars) |
A simple utility that concatenates a string onto the end of a 0-byte terminated WBAlloc() string up to a maximum length (can also be 0-byte terminated) More... | |
void | WBDeQuoteString (char *pszStr) |
De-Quote a string 'in place', that is modifying the original string by removing quotes. More... | |
void | WBNormalizeXMLString (char *pString) |
De-Quote and 'normalize' an XML string 'in place', that is modifying the original string by removing quotes and translationg things like '&' '>' etc. More... | |
int | WBStringLineCount (const char *pSrc, unsigned int nMaxChars) |
Determine how many 'lines' are in a block of text by counting 'linefeed' characters. More... | |
const char * | WBStringNextLine (const char *pSrc, unsigned int *pnMaxChars) |
Locate the next line in a block of text, returning its pointer (and updating remaining length) More... | |
Generic Utility functions for copying and manipulating text.
Utility functions for copying and manipulating text, such as string copying and concatenation. These function standardize common string operations and allocate new buffers with 'WBAlloc()' as needed. This can greatly simplify working with string-based data.
These generic string functions are compatible with Multi-Byte character sets, with the assumption that a standard UTF-8 or multi-byte character consists of 1 or more non-zero bytes, and that the end of a multi-byte or UTF-8 string is marked with a zero byte.
For working specifically with Multi-Byte Character Sets (MBCS), see Multi-Byte Character Set utility functions.
#define NEXT_WORD | ( | pX, | |
pY, | |||
pZ | |||
) | {while(*(pX) && *(pX) <= ' '){(pX)++;} (pY)=(pZ)=(pX); while(*(pX)>' '){(pX)++;} (pZ)=(pX);} |
Obtain the 'next word' within a string pointed to by pX, bounded by pY and pZ.
pX | A pointer to a 0-byte terminated string; returned as the 'current' pointer within that string for further parsing |
pY | A pointer to the word that was found within the string |
pZ | A pointer to the character just following the found word. If pY == pZ, no word was found (and *pX should be 0) |
use this function in a loop to parse out the "next word" within the string until *pX == 0 or pY == pZ
Definition at line 1263 of file platform_helper.h.
void WBCatString | ( | char ** | ppDest, |
const char * | pSrc | ||
) |
A simple utility that concatenates a string onto the end of a 0-byte terminated WBAlloc() string.
ppDest | A pointer to a pointer to a WBAlloc() string containing the first portion of the concatenated result (also the return value) |
pSrc | A pointer to a character string to concatenate onto the end of the first string |
This function concatenates two strings together. The first parameter must point to the character pointer variable that points to the first string to be concatenated. This must either be a WBAlloc() pointer or NULL, and the string itself must be 0-byte terminated. The second parameter points to a 0-byte terminated string, which does not have to be a WBAlloc() string. The function will overwrite the first pointer with WBAlloc() copy of the result of concatenating the two strings.
On error, the function does NOT modify ppDest and aborts the concatenate operation.
Header File: platform_helper.h
Definition at line 1495 of file platform_helper.c.
void WBCatStringN | ( | char ** | ppDest, |
const char * | pSrc, | ||
unsigned int | nMaxChars | ||
) |
A simple utility that concatenates a string onto the end of a 0-byte terminated WBAlloc() string up to a maximum length (can also be 0-byte terminated)
ppDest | A pointer to a pointer to a WBAlloc() string containing the first portion of the concatenated result (also the return value) |
pSrc | A pointer to a character string to concatenate onto the end of the first string (can be 0-byte terminated) |
nMaxChars | The maximum number of characters to be concatenated, or until a 0-byte is found in pSrc |
This function concatenates two strings together. The first parameter must point to the character pointer variable that points to the first string to be concatenated. This must either be a WBAlloc() pointer or NULL, and the string itself must be 0-byte terminated. The second parameter points to a POSSIBLY 0-byte terminated string, which does not have to be a WBAlloc() string. The function will overwrite the first pointer with WBAlloc() copy of the result of concatenating the two strings. The string 'pSrc' will be concatenated up to 'nMaxChars' or until a 0-byte is found, whichever happens first.
On error, the function does NOT modify pszStr1 and aborts the concatenate operation.
Header File: platform_helper.h
Definition at line 1548 of file platform_helper.c.
char* WBCopyString | ( | const char * | pSrc | ) |
A simple utility that returns a WBAlloc() copy of a 0-byte terminated string.
pSrc | A pointer to the original ASCII string (0-byte terminated) |
This function creates a 'WBAlloc() copy of szStr, up to the 0-byte. The returned string ALWAYS ends in a zero byte. The caller must deallocate the returned pointer using 'WBFree()'.
The function returns NULL on error.
Header File: platform_helper.h
Definition at line 1432 of file platform_helper.c.
char* WBCopyStringN | ( | const char * | pSrc, |
unsigned int | nMaxChars | ||
) |
A simple utility that returns a WBAlloc() copy of a string up to a maximum length (can also be 0-byte terminated)
pSrc | A pointer to the original ASCII string (can be 0-byte terminated) |
nMaxChars | The maximum number of characters to be copied, or until a 0-byte is found |
This function creates a 'WBAlloc() copy of pStr, up to 'nMaxChars' or until a 0-byte is found, whichever happens first. The returned string ALWAYS ends in a zero byte. The caller must deallocate the returned pointer using 'WBFree()'.
The function returns NULL on error.
Header File: platform_helper.h
Definition at line 1462 of file platform_helper.c.
void WBDeQuoteString | ( | char * | pszStr | ) |
De-Quote a string 'in place', that is modifying the original string by removing quotes.
pszStr | A pointer to a (0-byte terminated) ASCII string that may contain quotes. Quotes are removed 'in place' |
Often you need to be able to remove quote characters from a string in a standardized manner. This function handles just about every standard quoting method available, including the use of double-quotes to indicate a quote within a quoted string, the use of single or double quotes, etc.
Header File: platform_helper.h
Definition at line 1606 of file platform_helper.c.
void WBNormalizeXMLString | ( | char * | pString | ) |
De-Quote and 'normalize' an XML string 'in place', that is modifying the original string by removing quotes and translationg things like '&' '>' etc.
pszStr | A pointer to a (0-byte terminated) ASCII string that may contain quotes. Quotes are removed 'in place' |
Often you need to be able to remove quote characters and otherwise 'normalize' an XML string in a standardized manner. This function handles just about every standard quoting method available, including the use of double-quotes, as well as special character indicators like '&' and '>', to indicate a quote or special character within a quoted string, as well as allowing the the use of either single or double quotes, etc.
Header File: platform_helper.h
Definition at line 1672 of file platform_helper.c.
int WBStringLineCount | ( | const char * | pSrc, |
unsigned int | nMaxChars | ||
) |
Determine how many 'lines' are in a block of text by counting 'linefeed' characters.
pSrc | A const pointer to an ASCII or UTF8 string (may end in zero byte) |
nMaxChars | The maximum number of characters in the buffer |
Use this function to determine how many lines are in the block of text. A line is considered to be a string of 1 or more characters, ending in a zero byte [or end of text as determined by 'nMaxChars'], or one of the following sequences: <CRLF>, <LF>, <CR>, or <LFCR>
Header File: platform_helper.h
Definition at line 1744 of file platform_helper.c.
const char* WBStringNextLine | ( | const char * | pSrc, |
unsigned int * | pnMaxChars | ||
) |
Locate the next line in a block of text, returning its pointer (and updating remaining length)
pSrc | A const pointer to an ASCII or UTF8 string (may end in a zero byte) |
pnMaxChars | A pointer to an integer containing maximum number of characters in the buffer |
Use this function to find the 'next line' in a block of text. It will also update the number of characters remaining in the buffer, and store the result in '*pnMaxChars'. If 'pnMaxChars' is NULL, the string buffer is assumed to terminate with a zero-byte.
Header File: platform_helper.h
Definition at line 1774 of file platform_helper.c.