|
mdz_ansi_dyn Overview and Reference
mdz_ansi_dyn - very lightweight, speedy and portable ANSI C 89/90 compliant library for processing single-byte strings. Minimal dependencies, metadata encapsulated, optional dynamic memory use.
The source code is highly-portable and conforms to the ANSI C 89/90 standard. Builds are available for Win32/Win64, Linux, FreeBSD, Android, macOS.
mdz_ansi_dyn Advantages
1. High Portability: The entire codebase conforms to the ANSI C 89/90 standard.
2. Minimal Dependencies: mdz_ansi_dyn functions solely depend on standard C-library functions. This means you can integrate the library into your code without any additional dependencies beyond the standard platform libraries/APIs.
3. Performance: The library functions are highly optimized for speed, particularly for operations like searching. Especially when processing very large string (e.g., hundreds of megabytes or gigabytes).
4. Flexibilty: Most library functions offer both "left position" and "right position" parameters, allowing you to limit the processing area. Additionally, the library provides more string functions than comparable libraries such as STL, Boost, or GLib.
5. Extended Error-Checking: All functions use strict error-checking mechanisms and return specific error codes pointing the problem precisely.
6. Extended Control: The functions perform only explicit operations. For example, when an "insert" function is called, it will return an error if there is not enough capacity in string - no implicit memory allocations/reservations will be made.
7. Optional dynamic memory: There is possibility to set dynamic memory management functions like malloc, realloc, free to use dynamic memory for storing/processing very long strings.
8. Metadata encapsulated: String controls its Size and Capacity, thus making automatical checking and if necessary adjustment during each string function call.
Please refer to mdz_ansi_dyn Wiki for API details.
mdz_ansi_dyn API Reference
mdz_ansi_dyn is dynamically-sized contiguous single-byte string, containing ASCII (0..127) and "ANSI" (128 - 255) characters.
String may contain 0-terminators ('\0') inside, and must end with 0-terminator.
Capacity - how many bytes of memory is reserved for string content.
Size - how many characters are actually residing in a string.
"reserve" functions allocate/reallocate memory dynamically using malloc() /realloc() .
"attach" functionality allows attaching contiguous block of memory to string, for using string functions on it.
Init/destroy functions:
mdz_ansi_dyn_init
mdz_ansi_dyn_setAllocFunctions
mdz_ansi_dyn_create
mdz_ansi_dyn_attach
mdz_ansi_dyn_destroy
Status functions:
mdz_ansi_dyn_sizeMetadata
mdz_ansi_dyn_size
mdz_ansi_dyn_capacity
mdz_ansi_dyn_data
mdz_ansi_dyn_dataConst
Insert/remove functions:
mdz_ansi_dyn_insert
mdz_ansi_dyn_removeFrom
mdz_ansi_dyn_remove
mdz_ansi_dyn_trimLeft
mdz_ansi_dyn_trimRight
mdz_ansi_dyn_trim
Find functions:
mdz_ansi_dyn_findSingle
mdz_ansi_dyn_find
mdz_ansi_dyn_rfindSingle
mdz_ansi_dyn_rfind
mdz_ansi_dyn_firstOf
mdz_ansi_dyn_firstNotOf
mdz_ansi_dyn_lastOf
mdz_ansi_dyn_lastNotOf
Miscellaneous functions:
mdz_ansi_dyn_compare
mdz_ansi_dyn_count
mdz_ansi_dyn_replace
mdz_ansi_dyn_reverse
Initialize mdz_ansi_dyn library and license. This function should be called before any other function of the library.
mdz_bool mdz_ansi_dyn_init(const unsigned long* pnFirstNameHash, const unsigned long* pnLastNameHash, const unsigned long* pnEmailHash, const unsigned long* pnLicenseHash);
Parameter | Description |
pnFirstNameHash | user first name hash code |
pnLastNameHash | user last name hash code |
pnEmailHash | user e-mail hash code |
pnLicenseHash | license hash code |
Return | Description |
mdz_true | if the initialization succeeded, otherwise mdz_false |
mdz_ansi_dyn Reference
Set allocation functions for dynamic memory-management. If functions are not set - library is only using static memory, thus no dynamic memory allocations.
void mdz_ansi_dyn_setAllocFunctions(mdz_AllocFunc pAllocFunc, mdz_ReallocFunc pReallocFunc, mdz_FreeFunc pFreeFunc);
Parameter | Description |
pAllocFunc | pointer to allocate memory function. Used in string-creation functions like mdz_ansi_dyn_create() . Can be NULL |
pReallocFunc | pointer to re-allocate memory function. Used in string-resizing fuinctons like mdz_ansi_dyn_insert() . Can be NULL |
pFreeFunc | pointer to free memory function. Used in string-destroying functions like mdz_ansi_dyn_destroy() . Can be NULL |
mdz_ansi_dyn Reference
Create empty string with Capacity nCapacity and Size 0. This function uses dynamic-memory allocator malloc() function set in mdz_ansi_dyn_setAllocFunctions()
mdz_AnsiDyn* mdz_ansi_dyn_create(size_t nCapacity, enum mdz_error* penError);
Parameter | Description |
nCapacity | initial capacity of string data in bytes |
penError | if not NULL , error will be written there. There are following errors possible: |
| Value | Description |
| MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
| MDZ_ERROR_CAPACITY | nCapacity > maximal-possible capacity (SIZE_MAX minus size of string Metadata, returned by mdz_ansi_dyn_sizeMetadata() and 0-terminator byte) |
| MDZ_ERROR_ALLOC_FUNC | dynamic-memory allocator malloc() function is not set (using mdz_ansi_dyn_setAllocFunctions() ) |
| MDZ_ERROR_ALLOCATION | could not alocate memory |
| MDZ_ERROR_NONE | function succeeded |
Return | Description |
NULL | function failed |
Result | pointer to string for use in other mdz_ansi_dyn functions |
mdz_ansi_dyn Reference
Attach string to pre-allocated pcBuffer of nBufferSize bytes. If penError is not NULL , error will be written there
mdz_AnsiDyn* mdz_ansi_dyn_attach(char* pcBuffer, size_t nBufferSize, enum mdz_error* penError);
Parameter | Description |
pcBuffer | pointer to pre-allocated buffer to attach. Thus minimal pcBuffer size is size of string Metadata, returned by mdz_ansi_dyn_sizeMetadata() + 0-terminator byte (in this case Capacity is 0) |
nBufferSize | size of pcBuffer in bytes; should be at least size of Metadata (returned by mdz_ansi_dyn_sizeMetadata() ) + 0-terminator byte, in this case Capacity is 0 |
penError | if not NULL , error will be written there. There are following errors possible: |
| Value | Description |
| MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
| MDZ_ERROR_DATA | pcBuffer is NULL |
| MDZ_ERROR_CAPACITY | nBufferSize < size of string Metadata (returned by mdz_ansi_dyn_sizeMetadata() ) + 0-terminator byte |
| MDZ_ERROR_NONE | function succeeded |
Return | Description |
NULL | function failed |
Result | pointer to string for use in other mdz_ansi_dyn functions |
mdz_ansi_dyn Reference
Destroy string. If string is created using mdz_ansi_dyn_create() - free() function set in mdz_ansi_dyn_setAllocFunctions() will be used for destroying.
enum mdz_error mdz_ansi_dyn_destroy(mdz_AnsiDyn* psAnsi);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
Return | Description |
MDZ_ERROR_FREE_FUNC | could not destroy string created with mdz_ansi_dyn_create() , because free() function is not set (using mdz_ansi_dyn_setAllocFunctions() ) |
MDZ_ERROR_NONE | function succeeded |
mdz_ansi_dyn Reference
Return size of string Metadata
size_t mdz_ansi_dyn_sizeMetadata(void);
Return | Description |
Size | of string Metadata |
mdz_ansi_dyn Reference
Return Size of string Data in characters/bytes.
size_t mdz_ansi_dyn_size(const mdz_AnsiDyn* psAnsi);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
Return | Description |
0 | if psAnsi is NULL |
Size | otherwise |
mdz_ansi_dyn Reference
Return Capacity of string Data in characters/bytes.
size_t mdz_ansi_dyn_capacity(const mdz_AnsiDyn* psAnsi);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
Return | Description |
0 | if psAnsi is NULL |
Size | otherwise |
mdz_ansi_dyn Reference
Return pointer to string Data.
char* mdz_ansi_dyn_data(mdz_AnsiDyn* psAnsi);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
Return | Description |
0 | if psAnsi is NULL |
Data | otherwise |
mdz_ansi_dyn Reference
Return const pointer to string Data.
const char* mdz_ansi_dyn_dataConst(const mdz_AnsiDyn* psAnsi);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
Return | Description |
0 | if psAnsi is NULL |
Data | otherwise |
mdz_ansi_dyn Reference
Insert pcItems from nLeftPos position. Data and pcItems cannot overlap. New Size is written in psAnsi. If there is not enouhgh Capacity , realloc() function set in mdz_ansi_dyn_setAllocFunctions() will be used
enum mdz_error mdz_ansi_dyn_insert(mdz_AnsiDyn** ppsAnsi, size_t nLeftPos, const char* pcItems, size_t nCount);
Parameter | Description |
ppsAnsi | pointer to address of string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() . If after reallocation string address will be changed, new address will be stored here |
nLeftPos | 0-based position to insert. If nLeftPos == Size items are appended. nLeftPos > Size is not allowed |
pcItems | items to insert. Cannot be NULL |
nCount | number of items to insert. Cannot be 0 |
Return | Description |
MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
MDZ_ERROR_DATA | psAnsi is NULL |
MDZ_ERROR_CAPACITY | Capacity is 0 or too large |
MDZ_ERROR_TERMINATOR | there is no 0-terminator on Data[Size ] position |
MDZ_ERROR_ITEMS | pcItems is NULL |
MDZ_ERROR_ZERO_COUNT | nCount is 0 |
MDZ_ERROR_BIGLEFT | nLeftPos > Size |
MDZ_ERROR_BIGCOUNT | Size + nCount > Capacity |
MDZ_ERROR_OVERLAP | [Data; Data + Size + nCount ] area and pcItems overlap |
MDZ_ERROR_ATTACHED | string has not enough capacity for insertion, but is attached (using mdz_ansi_dyn_attach() ), thus cannot be reallocated |
MDZ_ERROR_REALLOC_FUNC | could not realloc string created with mdz_ansi_dyn_create() , because realloc() function is not set (using mdz_ansi_dyn_setAllocFunctions() ) |
MDZ_ERROR_ALLOCATION | string reallocation failed |
MDZ_ERROR_NONE | function succeeded |
mdz_ansi_dyn Reference
Find first occurrence of cItem . Returns 0-based position of match (if found), or SIZE_MAX if not found or error happened. If penError is not NULL , error will be written there
size_t mdz_ansi_dyn_findSingle(const mdz_AnsiDyn* psAnsi, size_t nLeftPos, size_t nRightPos, char cItem, enum mdz_error* penError);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
nLeftPos | 0-based start position to search from left. Use 0 to search from the beginning of Data |
nRightPos | 0-based end position to search up to. Use Size-1 to search till the end of Data |
cItem | character to find |
penError | if not NULL , error will be written there. There are following errors possible: |
| Value | Description |
| MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
| MDZ_ERROR_DATA | psAnsi is NULL |
| MDZ_ERROR_CAPACITY | Capacity is too large |
| MDZ_ERROR_BIGSIZE | Size > Capacity |
| MDZ_ERROR_TERMINATOR | there is no 0-terminator on Data[Size ] position |
| MDZ_ERROR_BIGRIGHT | nRightPos >= Size |
| MDZ_ERROR_BIGLEFT | nLeftPos > nRightPos |
| MDZ_ERROR_NONE | function succeeded |
Return | Description |
SIZE_MAX | if cItem not found or error happened |
Result | 0-based position of first match |
mdz_ansi_dyn Reference
Find first occurrence of pcItems using optimized Boyer-Moore-Horspool search. Returns 0-based position of match (if found), or SIZE_MAX if not found or error happened. If penError is not NULL , error will be written there
size_t mdz_ansi_dyn_find(const mdz_AnsiDyn* psAnsi, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount, enum mdz_error* penError);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
nLeftPos | 0-based start position to search from left. Use 0 to search from the beginning of Data |
nRightPos | 0-based end position to search up to. Use Size-1 to search till the end of Data |
pcItems | items to find. Cannot be NULL |
nCount | number of items to find. Cannot be 0 |
penError | if not NULL , error will be written there. There are following errors possible: |
| Value | Description |
| MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
| MDZ_ERROR_DATA | psAnsi is NULL |
| MDZ_ERROR_CAPACITY | Capacity is too large |
| MDZ_ERROR_BIGSIZE | Size > Capacity |
| MDZ_ERROR_TERMINATOR | there is no 0-terminator on Data[Size ] position |
| MDZ_ERROR_ITEMS | pcItems is NULL |
| MDZ_ERROR_ZERO_COUNT | nCount is 0 |
| MDZ_ERROR_BIGRIGHT | nRightPos >= Size |
| MDZ_ERROR_BIGLEFT | nLeftPos > nRightPos |
| MDZ_ERROR_BIGCOUNT | nCount is bigger than search area (between nLeftPos and nRightPos ) |
| MDZ_ERROR_NONE | function succeeded |
Return | Description |
SIZE_MAX | if pcItems not found or error happened |
Result | 0-based position of first match |
mdz_ansi_dyn Reference
Find last occurrence of cItem . Returns 0-based position of match (if found), or SIZE_MAX if not found or error happened. If penError is not NULL , error will be written there
size_t mdz_ansi_dyn_rfindSingle(const mdz_AnsiDyn* psAnsi, size_t nLeftPos, size_t nRightPos, char cItem, enum mdz_error* penError);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
nLeftPos | 0-based end position to find up to. Use 0 to search till the beginning of Data |
nRightPos | 0-based start position to find from right. Use Size-1 to search from the end of Data |
cItem | character to find |
penError | if not NULL , error will be written there. There are following errors possible: |
| Value | Description |
| MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
| MDZ_ERROR_DATA | psAnsi is NULL |
| MDZ_ERROR_CAPACITY | Capacity is too large |
| MDZ_ERROR_BIGSIZE | Size > Capacity |
| MDZ_ERROR_TERMINATOR | there is no 0-terminator on Data[Size ] position |
| MDZ_ERROR_BIGRIGHT | nRightPos >= Size |
| MDZ_ERROR_BIGLEFT | nLeftPos > nRightPos |
| MDZ_ERROR_NONE | function succeeded |
Return | Description |
SIZE_MAX | if cItem not found or error happened |
Result | 0-based position of first match |
mdz_ansi_dyn Reference
Find last occurrence of pcItems using optimized Boyer-Moore-Horspool search. Returns 0-based position of match (if found), or SIZE_MAX if not found or error happened. If penError is not NULL , error will be written there
size_t mdz_ansi_dyn_rfind(const mdz_AnsiDyn* psAnsi, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount, enum mdz_error* penError);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
nLeftPos | 0-based end position to find up to. Use 0 to search till the beginning of Data |
nRightPos | 0-based start position to find from right. Use Size-1 to search from the end of Data |
pcItems | items to find. Cannot be NULL |
nCount | number of items to find. Cannot be 0 |
penError | if not NULL , error will be written there. There are following errors possible: |
| Value | Description |
| MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
| MDZ_ERROR_DATA | psAnsi is NULL |
| MDZ_ERROR_CAPACITY | Capacity is too large |
| MDZ_ERROR_BIGSIZE | Size > Capacity |
| MDZ_ERROR_TERMINATOR | there is no 0-terminator on Data[Size ] position |
| MDZ_ERROR_ITEMS | pcItems is NULL |
| MDZ_ERROR_ZERO_COUNT | nCount is 0 |
| MDZ_ERROR_BIGRIGHT | nRightPos >= Size |
| MDZ_ERROR_BIGLEFT | nLeftPos > nRightPos |
| MDZ_ERROR_BIGCOUNT | nCount is bigger than search area (between nLeftPos and nRightPos ) |
| MDZ_ERROR_NONE | function succeeded |
Return | Description |
SIZE_MAX | if pcItems not found or error happened |
Result | 0-based position of first match |
mdz_ansi_dyn Reference
Find first occurrence of any item of pcItems . Returns 0-based position of match (if found), or SIZE_MAX if not found or error happened. If penError is not NULL , error will be written there
size_t mdz_ansi_dyn_firstOf(const mdz_AnsiDyn* psAnsi, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount, enum mdz_error* penError);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
nLeftPos | 0-based end position to find up to. Use 0 to search till the beginning of Data |
nRightPos | 0-based start position to find from right. Use Size-1 to search till the end of Data |
pcItems | items to find. Cannot be NULL |
nCount | number of items to find. Cannot be 0 |
penError | if not NULL , error will be written there. There are following errors possible: |
| Value | Description |
| MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
| MDZ_ERROR_DATA | psAnsi is NULL |
| MDZ_ERROR_CAPACITY | Capacity is too large |
| MDZ_ERROR_BIGSIZE | Size > Capacity |
| MDZ_ERROR_TERMINATOR | there is no 0-terminator on Data[Size ] position |
| MDZ_ERROR_ITEMS | pcItems is NULL |
| MDZ_ERROR_ZERO_COUNT | nCount is 0 |
| MDZ_ERROR_BIGRIGHT | nRightPos >= Size |
| MDZ_ERROR_BIGLEFT | nLeftPos > nRightPos |
| MDZ_ERROR_NONE | function succeeded |
Return | Description |
SIZE_MAX | if no item of pcItems found or error happened |
Result | 0-based position of first match |
mdz_ansi_dyn Reference
Find first non-occurrence of any item of pcItems . Returns 0-based position of match (if found), or SIZE_MAX if not found or error happened. If penError is not NULL , error will be written there
size_t mdz_ansi_dyn_firstNotOf(const mdz_AnsiDyn* psAnsi, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount, enum mdz_error* penError);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
nLeftPos | 0-based end position to find up to. Use 0 to search till the beginning of Data |
nRightPos | 0-based start position to find from right. Use Size-1 to search till the end of Data |
pcItems | items to find. Cannot be NULL |
nCount | number of items to find. Cannot be 0 |
penError | if not NULL , error will be written there. There are following errors possible: |
| Value | Description |
| MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
| MDZ_ERROR_DATA | psAnsi is NULL |
| MDZ_ERROR_CAPACITY | Capacity is too large |
| MDZ_ERROR_BIGSIZE | Size > Capacity |
| MDZ_ERROR_TERMINATOR | there is no 0-terminator on Data[Size ] position |
| MDZ_ERROR_ITEMS | pcItems is NULL |
| MDZ_ERROR_ZERO_COUNT | nCount is 0 |
| MDZ_ERROR_BIGRIGHT | nRightPos >= Size |
| MDZ_ERROR_BIGLEFT | nLeftPos > nRightPos |
| MDZ_ERROR_NONE | function succeeded |
Return | Description |
SIZE_MAX | if no item of pcItems found or error happened |
Result | 0-based position of first match |
mdz_ansi_dyn Reference
Find last occurrence of any item of pcItems . Returns 0-based position of match (if found), or SIZE_MAX if not found or error happened. If penError is not NULL , error will be written there
size_t mdz_ansi_dyn_lastOf(const mdz_AnsiDyn* psAnsi, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount, enum mdz_error* penError);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
nLeftPos | 0-based end position to find up to. Use 0 to search till the beginning of Data |
nRightPos | 0-based start position to find from right. Use Size-1 to search till the end of Data |
pcItems | items to find. Cannot be NULL |
nCount | number of items to find. Cannot be 0 |
penError | if not NULL , error will be written there. There are following errors possible: |
| Value | Description |
| MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
| MDZ_ERROR_DATA | psAnsi is NULL |
| MDZ_ERROR_CAPACITY | Capacity is too large |
| MDZ_ERROR_BIGSIZE | Size > Capacity |
| MDZ_ERROR_TERMINATOR | there is no 0-terminator on Data[Size ] position |
| MDZ_ERROR_ITEMS | pcItems is NULL |
| MDZ_ERROR_ZERO_COUNT | nCount is 0 |
| MDZ_ERROR_BIGRIGHT | nRightPos >= Size |
| MDZ_ERROR_BIGLEFT | nLeftPos > nRightPos |
| MDZ_ERROR_NONE | function succeeded |
Return | Description |
SIZE_MAX | if no item of pcItems found or error happened |
Result | 0-based position of first match |
mdz_ansi_dyn Reference
Find last non-occurrence of any item of pcItems . Returns 0-based position of match (if found), or SIZE_MAX if not found or error happened. If penError is not NULL , error will be written there
size_t mdz_ansi_dyn_lastNotOf(const mdz_AnsiDyn* psAnsi, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount, enum mdz_error* penError);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
nLeftPos | 0-based end position to find up to. Use 0 to search till the beginning of Data |
nRightPos | 0-based start position to find from right. Use Size-1 to search till the end of Data |
pcItems | items to find. Cannot be NULL |
nCount | number of items to find. Cannot be 0 |
penError | if not NULL , error will be written there. There are following errors possible: |
| Value | Description |
| MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
| MDZ_ERROR_DATA | psAnsi is NULL |
| MDZ_ERROR_CAPACITY | Capacity is too large |
| MDZ_ERROR_BIGSIZE | Size > Capacity |
| MDZ_ERROR_TERMINATOR | there is no 0-terminator on Data[Size ] position |
| MDZ_ERROR_ITEMS | pcItems is NULL |
| MDZ_ERROR_ZERO_COUNT | nCount is 0 |
| MDZ_ERROR_BIGRIGHT | nRightPos >= Size |
| MDZ_ERROR_BIGLEFT | nLeftPos > nRightPos |
| MDZ_ERROR_NONE | function succeeded |
Return | Description |
SIZE_MAX | if no item of pcItems found or error happened |
Result | 0-based position of first match |
mdz_ansi_dyn Reference
Remove nCount item(s) starting from 0-based nLeftPos position
enum mdz_error mdz_ansi_dyn_removeFrom(mdz_AnsiDyn* psAnsi, size_t nLeftPos, size_t nCount);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
nLeftPos | 0-based start position to remove item(s) from. Use 0 to remove from the beginning of Data |
nCount | number of item(s) to remove. Cannot be 0 |
Return | Description |
MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
MDZ_ERROR_DATA | psAnsi is NULL |
MDZ_ERROR_CAPACITY | Capacity is too large |
MDZ_ERROR_BIGSIZE | Size > Capacity |
MDZ_ERROR_TERMINATOR | there is no 0-terminator on Data[Size ] position |
MDZ_ERROR_ZERO_SIZE | Size is 0 (string is empty) |
MDZ_ERROR_ZERO_COUNT | nCount is 0 |
MDZ_ERROR_BIGLEFT | nLeftPos >= Size |
MDZ_ERROR_BIGCOUNT | nCount is bigger than remove area (between nLeftPos and Size ) |
MDZ_ERROR_NONE | function succeeded |
mdz_ansi_dyn Reference
Remove all ocurrences of nCount item(s) matching to pcItems , residing between nLeftPos and nRightPos
enum mdz_error mdz_ansi_dyn_remove(mdz_AnsiDyn* psAnsi, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount, mdz_bool bFromLeft);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
nLeftPos | 0-based start position to remove item(s) from. Use 0 to search from the beginning of Data |
nRightPos | 0-based end position to remove item(s) up to. Use Size-1 to search till the end of Data |
pcItems | items to remove. Cannot be NULL |
nCount | number of item(s) to remove. Cannot be 0 |
bFromLeft | mdz_true if search for items to remove from left side, otherwise from right |
Return | Description |
MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
MDZ_ERROR_DATA | psAnsi is NULL |
MDZ_ERROR_CAPACITY | Capacity is too large |
MDZ_ERROR_BIGSIZE | Size > Capacity |
MDZ_ERROR_TERMINATOR | there is no 0-terminator on Data[Size ] position |
MDZ_ERROR_ZERO_SIZE | Size is 0 (string is empty) |
MDZ_ERROR_ITEMS | pcItems is NULL |
MDZ_ERROR_ZERO_COUNT | nCount is 0 |
MDZ_ERROR_BIGRIGHT | nRightPos >= Size |
MDZ_ERROR_BIGLEFT | nLeftPos > nRightPos |
MDZ_ERROR_BIGCOUNT | nCount is bigger than search area (between nLeftPos and nRightPos ) |
MDZ_ERROR_NONE | function succeeded |
mdz_ansi_dyn Reference
Remove items which are contained in pcItems from left, until first non-contained in pcItems item is reached.
enum mdz_error mdz_ansi_dyn_trimLeft(mdz_AnsiDyn* psAnsi, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
nLeftPos | 0-based start position to trim item(s) from left. Use 0 to trim from the beginning of Data |
nRightPos | 0-based end position to trim item(s) up to. Use Size-1 to trim till the end of Data |
pcItems | items to trim. Cannot be NULL |
nCount | number of items to trim. Cannot be 0 |
Return | Description |
MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
MDZ_ERROR_DATA | psAnsi is NULL |
MDZ_ERROR_CAPACITY | Capacity is too large |
MDZ_ERROR_BIGSIZE | Size > Capacity |
MDZ_ERROR_TERMINATOR | there is no 0-terminator on Data[Size ] position |
MDZ_ERROR_ZERO_SIZE | Size is 0 (string is empty) |
MDZ_ERROR_ITEMS | pcItems is NULL |
MDZ_ERROR_ZERO_COUNT | nCount is 0 |
MDZ_ERROR_BIGRIGHT | nRightPos >= Size |
MDZ_ERROR_BIGLEFT | nLeftPos > nRightPos |
MDZ_ERROR_NONE | function succeeded |
mdz_ansi_dyn Reference
Remove items which are contained in pcItems from right, until first non-contained in pcItems item is reached.
enum mdz_error mdz_ansi_dyn_trimRight(mdz_AnsiDyn* psAnsi, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
nLeftPos | 0-based end position to trim item(s) up to. Use 0 to trim till the beginning of Data |
nRightPos | 0-based start position to trim item(s) from right. Use Size-1 to trim from the end of Data |
pcItems | items to trim. Cannot be NULL |
nCount | number of items to trim. Cannot be 0 |
Return | Description |
MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
MDZ_ERROR_DATA | psAnsi is NULL |
MDZ_ERROR_CAPACITY | Capacity is too large |
MDZ_ERROR_BIGSIZE | Size > Capacity |
MDZ_ERROR_TERMINATOR | there is no 0-terminator on Data[Size ] position |
MDZ_ERROR_ZERO_SIZE | Size is 0 (string is empty) |
MDZ_ERROR_ITEMS | pcItems is NULL |
MDZ_ERROR_ZERO_COUNT | nCount is 0 |
MDZ_ERROR_BIGRIGHT | nRightPos >= Size |
MDZ_ERROR_BIGLEFT | nLeftPos > nRightPos |
MDZ_ERROR_NONE | function succeeded |
mdz_ansi_dyn Reference
Remove items which are contained in pcItems from left and from right, until first non-contained in pcItems item is reached.
enum mdz_error mdz_ansi_dyn_trim(mdz_AnsiDyn* psAnsi, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
nLeftPos | 0-based start position to trim item(s) from left. Use 0 to trim from the beginning of Data |
nRightPos | 0-based start position to trim item(s) from right. Use Size-1 to trim from the end of Data |
pcItems | items to trim. Cannot be NULL |
nCount | number of items to trim. Cannot be 0 |
Return | Description |
MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
MDZ_ERROR_DATA | psAnsi is NULL |
MDZ_ERROR_CAPACITY | Capacity is too large |
MDZ_ERROR_BIGSIZE | Size > Capacity |
MDZ_ERROR_TERMINATOR | there is no 0-terminator on Data[Size ] position |
MDZ_ERROR_ZERO_SIZE | Size is 0 (string is empty) |
MDZ_ERROR_ITEMS | pcItems is NULL |
MDZ_ERROR_ZERO_COUNT | nCount is 0 |
MDZ_ERROR_BIGRIGHT | nRightPos >= Size |
MDZ_ERROR_BIGLEFT | nLeftPos > nRightPos |
MDZ_ERROR_NONE | function succeeded |
mdz_ansi_dyn Reference
Compare content of Data with pcItems . If penError is not NULL , error will be written there
enum mdz_ansi_compare_result mdz_ansi_dyn_compare(const mdz_AnsiDyn* psAnsi, size_t nLeftPos, const char* pcItems, size_t nCount, mdz_bool bPartialCompare, enum mdz_error* penError);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
nLeftPos | 0-based start position to compare from left. Use 0 to compare from the beginning of Data |
pcItems | items to compare. Cannot be NULL |
nCount | number of items to compare. Cannot be 0 |
bPartialCompare | if mdz_true compare only nCount items, otherwise compare full strings |
penError | if not NULL , error will be written there. There are following errors possible: |
| Value | Description |
| MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
| MDZ_ERROR_DATA | psAnsi is NULL |
| MDZ_ERROR_CAPACITY | Capacity is too large |
| MDZ_ERROR_BIGSIZE | Size > Capacity |
| MDZ_ERROR_TERMINATOR | there is no 0-terminator on Data[Size ] position |
| MDZ_ERROR_ITEMS | pcItems is NULL |
| MDZ_ERROR_ZERO_COUNT | nCount is 0 |
| MDZ_ERROR_BIGLEFT | nLeftPos >= Size |
| MDZ_ERROR_BIGCOUNT | nCount is bigger than compare area (between nLeftPos and Size ) |
| MDZ_ERROR_NONE | function succeeded |
Return | Description |
MDZ_COMPARE_EQUAL or MDZ_COMPARE_NONEQUAL | Result of comparison |
mdz_ansi_dyn Reference
Counts number of pcItems substring occurences in Data. If penError is not NULL , error will be written there
size_t mdz_ansi_dyn_count(const mdz_AnsiDyn* psAnsi, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount, mdz_bool bAllowOverlapped, mdz_bool bFromLeft, enum mdz_error* penError);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
nLeftPos | 0-based start position to search from left. Use 0 to search from the beginning of Data |
nRightPos | 0-based end position to search up to. Use Size-1 to search till the end of Data |
pcItems | items to find. Cannot be NULL |
nCount | number of items to find. Cannot be 0 |
bAllowOverlapped | mdz_true if overlapped substrings should be counted, otherwise mdz_false |
bFromLeft | mdz_true if search for items to count from left side, otherwise from right |
penError | if not NULL , error will be written there. There are following errors possible: |
| Value | Description |
| MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
| MDZ_ERROR_DATA | psAnsi is NULL |
| MDZ_ERROR_CAPACITY | Capacity is too large |
| MDZ_ERROR_BIGSIZE | Size > Capacity |
| MDZ_ERROR_TERMINATOR | there is no 0-terminator on Data[Size ] position |
| MDZ_ERROR_ITEMS | pcItems is NULL |
| MDZ_ERROR_ZERO_COUNT | nCount is 0 |
| MDZ_ERROR_BIGRIGHT | nRightPos >= Size |
| MDZ_ERROR_BIGLEFT | nLeftPos > nRightPos |
| MDZ_ERROR_BIGCOUNT | nCount is bigger than search area (between nLeftPos and nRightPos ) |
| MDZ_ERROR_NONE | function succeeded |
Return | Description |
SIZE_MAX | if error happened |
Result | count of substring occurences. 0 if not found |
mdz_ansi_dyn Reference
Replace every occurence of pcItemsBefore with pcItemsAfter in Data. If there is not enouhgh Capacity , realloc() function set in mdz_ansi_dyn_setAllocFunctions() will be used
enum mdz_error mdz_ansi_dyn_replace(mdz_AnsiDyn** ppsAnsi, size_t nLeftPos, size_t nRightPos, const char* pcItemsBefore, size_t nCountBefore, const char* pcItemsAfter, size_t nCountAfter, mdz_bool bFromLeft, enum mdz_ansi_replace_type enReplacementType);
Parameter | Description |
ppsAnsi | pointer to address of string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() . If after reallocation string address will be changed, new address will be stored here |
nLeftPos | 0-based start position to search from left. Use 0 to search from the beginning of Data |
nRightPos | 0-based end position to search up to. Use Size-1 to search till the end of Data |
pcItemsBefore | items to find. Cannot be NULL |
nCountBefore | number of items to find. Cannot be 0 |
pcItemsAfter | pointer to items to replace with. Can be NULL |
nCountAfter | number of items to replace. Can be 0 |
bFromLeft | mdz_true if search for items to replace from left side, otherwise from right |
enReplacementType | type of replacement when nCountAfter > nCountBefore (thus Size is growing). For now only MDZ_ANSI_REPLACE_DUAL is supported (please refer to description of mdz_ansi_replace_type enum) |
Return | Description |
MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
MDZ_ERROR_DATA | psAnsi is NULL |
MDZ_ERROR_CAPACITY | Capacity is 0 or too large |
MDZ_ERROR_BIG_SIZE | Size > Capacity |
MDZ_ERROR_ZERO_SIZE | Size is 0 (string is empty) |
MDZ_ERROR_TERMINATOR | there is no 0-terminator on Data[Size ] position |
MDZ_ERROR_ITEMS | pcItemsBefore is NULL |
MDZ_ERROR_ZERO_COUNT | nCountBefore is 0 |
MDZ_ERROR_BIG_RIGHT | nRightPos >= Size |
MDZ_ERROR_BIG_LEFT | nLeftPos > nRightPos |
MDZ_ERROR_BIG_COUNT | nCount is bigger than search area (between nLeftPos and nRightPos ) |
MDZ_ERROR_OVERLAP | Data overlaps with pcItemsBefore , or Data overlaps with pcItemsAfter |
MDZ_ERROR_BIG_REPLACE | new Size after replacement > Capacity |
MDZ_ERROR_OVERLAP_REPLACE | Data after replacement - overlaps with pcItemsBefore , or Data after replacement - overlaps with pcItemsAfter |
MDZ_ERROR_ATTACHED | string has not enough capacity for replacements, but is attached (using mdz_ansi_dyn_attach() ), thus cannot be reallocated |
MDZ_ERROR_REALLOC_FUNC | could not realloc string created with mdz_ansi_dyn_create() , because realloc() function is not set (using mdz_ansi_dyn_setAllocFunctions() ) |
MDZ_ERROR_ALLOCATION | string reallocation failed |
MDZ_ERROR_NONE | function succeeded |
mdz_ansi_dyn Reference
Reverses characters in string, like "1234" into "4321".
enum mdz_error mdz_ansi_dyn_reverse(mdz_AnsiDyn* psAnsi, size_t nLeftPos, size_t nRightPos);
Parameter | Description |
psAnsi | pointer to string returned by mdz_ansi_dyn_create() or mdz_ansi_dyn_attach() |
nLeftPos | 0-based start position to search from left. Use 0 to search from the beginning of Data |
nRightPos | 0-based end position to search up to. Use Size-1 to search till the end of Data |
Return | Description |
MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_dyn_init() or invalid |
MDZ_ERROR_DATA | psAnsi is NULL |
MDZ_ERROR_CAPACITY | Capacity is too large |
MDZ_ERROR_BIG_SIZE | Size > Capacity |
MDZ_ERROR_TERMINATOR | there is no 0-terminator on Data[Size ] position |
MDZ_ERROR_BIG_RIGHT | nRightPos >= Size |
MDZ_ERROR_BIG_LEFT | nLeftPos >= nRightPos |
MDZ_ERROR_NONE | function succeeded |
mdz_ansi_dyn Reference
|