|
mdz_ansi_alg Overview and Reference
mdz_ansi_alg - very lightweight and versatile C library, containing string-processing algorithms for handling contiguous single-byte (ASCII/ANSI) strings.
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_alg Advantages
1. High Portability: The entire codebase conforms to the ANSI C 89/90 standard.
2. Minimal Dependencies: mdz_ansi_alg 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. No Memory Overhead: The functions are designed to process input data without making internal memory allocations or using dynamic memory.
Please refer to mdz_ansi_alg Wiki for API details.
mdz_ansi_alg API Reference
mdz_ansi_alg is algorithms library for processing contiguous single-byte string, containing ASCII (0..127) and "ANSI" (128 - 255) characters.
There are no memory allocations happen inside functions and there is no dynamic memory use.
String - String may contain 0-terminators ('\0') inside, and MUST end with 0-terminator.
Item - single element/character of String or of buffer passed as parameter for insertion, removing, find, etc. For this single-byte string library Item is always a byte.
Capacity - how many bytes of memory is reserved for string content. Capacity does NOT include ending 0-terminator byte
Size - how many characters are actually residing in a string.
Init functions:
mdz_ansi_alg_init
Insert/remove functions:
mdz_ansi_alg_insert
mdz_ansi_alg_append
mdz_ansi_alg_removeFrom
mdz_ansi_alg_remove
mdz_ansi_alg_trimLeft
mdz_ansi_alg_trimRight
mdz_ansi_alg_trim
Find functions:
mdz_ansi_alg_findSingle
mdz_ansi_alg_find
mdz_ansi_alg_rfindSingle
mdz_ansi_alg_rfind
mdz_ansi_alg_firstOf
mdz_ansi_alg_firstNotOf
mdz_ansi_alg_lastOf
mdz_ansi_alg_lastNotOf
Miscellaneous functions:
mdz_ansi_alg_equal
mdz_ansi_alg_compare
mdz_ansi_alg_count
mdz_ansi_alg_replace
mdz_ansi_alg_reverse
Initializes mdz_ansi_alg library and license. This function should be called before any other function of the library.
mdz_bool mdz_ansi_alg_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_alg Reference
Insert pcItems into pcData from nLeftPos position. pcData and pcItems cannot overlap. New size is returned in pnDataSize .
Size and capacity - do not include 0-terminator; thus size and capacity of empty string with no free space are 0
enum mdz_error mdz_ansi_alg_insert(char* pcData, size_t* pnDataSize, size_t nDataCapacity, size_t nLeftPos, const char* pcItems, size_t nCount);
Parameter | Description |
pcData | pointer to string. It should end with 0-terminator and have enough capacity for insertion of pcItems |
pnDataSize | pointer to current Size . Size is 0 for empty string. If insertion succeeded, new size is returned here |
nDataCapacity | maximal capacity of pcData buffer. nDataCapacity does not include 0-terminator byte, thus pcData buffer should be at least 1 byte bigger than nDataCapacity |
nLeftPos | 0-based position to insert. If nLeftPos == Size , pcItems is appended. nLeftPos > Size is not allowed |
pcItems | items to insert. Cannot be NULL , but can contain 0-terminators inside |
nCount | length of pcItems to insert, or 0 for pcItems length until 0-terminator |
Return | Description |
MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_alg_init() or invalid |
MDZ_ERROR_DATA | pcData is NULL |
MDZ_ERROR_SIZE | pnDataSize is NULL |
MDZ_ERROR_CAPACITY | nDataCapacity is 0 (no space for insertion) or SIZE_MAX (no space for 0-terminator) |
MDZ_ERROR_BIG_SIZE | Size > Capacity |
MDZ_ERROR_TERMINATOR | there is no 0-terminator in the end of pcData ([Size ] position) |
MDZ_ERROR_ITEMS | pcItems is NULL |
MDZ_ERROR_ZERO_COUNT | pcItems is empty and nCount is 0 |
MDZ_ERROR_BIG_LEFT | nLeftPos > Size |
MDZ_ERROR_BIG_COUNT | Size + nCount > nDataCapacity |
MDZ_ERROR_OVERLAP | pcData + pcItems memory - overlap with pcItems |
MDZ_ERROR_NONE | function succeeded, new size is written in pnDataSize |
mdz_ansi_alg Reference
Append pcItems to pcData . pcData and pcItems cannot overlap. New size is returned in pnDataSize .
Size and capacity - do not include 0-terminator; thus size and capacity of empty string with no free space are 0
enum mdz_error mdz_ansi_alg_append(char* pcData, size_t* pnDataSize, size_t nDataCapacity, const char* pcItems, size_t nCount);
Parameter | Description |
pcData | pointer to string. It should end with 0-terminator and have enough capacity for appending of pcItems |
pnDataSize | pointer to current Size . Size is 0 for empty string. If appending succeeded, new size is returned here |
nDataCapacity | maximal capacity of pcData buffer. nDataCapacity does not include 0-terminator byte, thus pcData buffer should be at least 1 byte bigger than nDataCapacity |
pcItems | items to append. Cannot be NULL , but can contain 0-terminators inside |
nCount | length of pcItems to append, or 0 for pcItems length until 0-terminator |
Return | Description |
MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_alg_init() or invalid |
MDZ_ERROR_DATA | pcData is NULL |
MDZ_ERROR_SIZE | pnDataSize is NULL |
MDZ_ERROR_BIG_SIZE | Size > Capacity |
MDZ_ERROR_CAPACITY | nDataCapacity is 0 (no space for appending) or SIZE_MAX (no space for 0-terminator) |
MDZ_ERROR_TERMINATOR | there is no 0-terminator in the end of pcData ([Size ] position) |
MDZ_ERROR_ITEMS | pcItems is NULL |
MDZ_ERROR_ZERO_COUNT | pcItems is empty and nCount is 0 |
MDZ_ERROR_BIG_COUNT | Size + nCount > nDataCapacity |
MDZ_ERROR_OVERLAP | pcData + pcItems memory - overlap with pcItems |
MDZ_ERROR_NONE | function succeeded, new size is written in pnDataSize |
mdz_ansi_alg Reference
Find first occurrence of cItem in pcData . 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_alg_findSingle(const char* pcData, size_t nLeftPos, size_t nRightPos, char cItem, enum mdz_error* penError);
Parameter | Description |
pcData | pointer to string |
nLeftPos | 0-based start position to search from left. Use 0 to search from the beginning of pcData |
nRightPos | 0-based end position to search up to. Use Size-1 to search till the end of pcData |
cItem | Item 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_alg_init() or invalid |
| MDZ_ERROR_DATA | pcData is NULL |
| MDZ_ERROR_BIG_RIGHT | nRightPos is SIZE_MAX |
| MDZ_ERROR_BIG_LEFT | 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_alg Reference
Find first occurrence of pcItems in pcData 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_alg_find(const char* pcData, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount, enum mdz_error* penError);
Parameter | Description |
pcData | pointer to string |
nLeftPos | 0-based start position to search from left. Use 0 to search from the beginning of pcData |
nRightPos | 0-based end position to search up to. Use Size-1 to search till the end of pcData |
pcItems | items to find. Cannot be NULL , but can contain 0-terminators inside |
nCount | length of pcItems to find, or 0 for pcItems length until 0-terminator |
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_alg_init() or invalid |
| MDZ_ERROR_DATA | pcData is NULL |
| MDZ_ERROR_BIG_RIGHT | nRightPos is SIZE_MAX |
| MDZ_ERROR_BIG_LEFT | nLeftPos > nRightPos |
| MDZ_ERROR_ITEMS | pcItems is NULL |
| MDZ_ERROR_ZERO_COUNT | pcItems is empty and nCount is 0 |
| MDZ_ERROR_BIG_COUNT | 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_alg Reference
Find last occurrence of cItem in pcData . 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_alg_rfindSingle(const char* pcData, size_t nLeftPos, size_t nRightPos, char cItem, enum mdz_error* penError);
Parameter | Description |
pcData | pointer to string |
nLeftPos | 0-based end position to find up to. Use 0 to search till the beginning of pcData |
nRightPos | 0-based start position to find from right. Use Size-1 to search from the end of pcData |
cItem | Item 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_alg_init() or invalid |
| MDZ_ERROR_DATA | pcData is NULL |
| MDZ_ERROR_BIG_RIGHT | nRightPos is SIZE_MAX |
| MDZ_ERROR_BIG_LEFT | 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_alg Reference
Find last occurrence of pcItems in pcData 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_alg_rfind(const char* pcData, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount, enum mdz_error* penError);
Parameter | Description |
pcData | pointer to string |
nLeftPos | 0-based end position to find up to. Use 0 to search till the beginning of pcData |
nRightPos | 0-based start position to find from right. Use Size-1 to search from the end of pcData |
pcItems | items to find. Cannot be NULL , but can contain 0-terminators inside |
nCount | length of pcItems to find, or 0 for pcItems length until 0-terminator |
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_alg_init() or invalid |
| MDZ_ERROR_DATA | pcData is NULL |
| MDZ_ERROR_BIG_RIGHT | nRightPos is SIZE_MAX |
| MDZ_ERROR_BIG_LEFT | nLeftPos > nRightPos |
| MDZ_ERROR_ITEMS | pcItems is NULL |
| MDZ_ERROR_ZERO_COUNT | pcItems is empty and nCount is 0 |
| MDZ_ERROR_BIG_COUNT | 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_alg Reference
Find first occurrence of any Item of pcItems in pcData . 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_alg_firstOf(const char* pcData, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount, enum mdz_error* penError);
Parameter | Description |
pcData | pointer to string |
nLeftPos | 0-based end position to find up to. Use 0 to search till the beginning of pcData |
nRightPos | 0-based start position to find from right. Use Size-1 to search till the end of pcData |
pcItems | items to find. Cannot be NULL , but can contain 0-terminators inside |
nCount | length of pcItems to find, or 0 for pcItems length until 0-terminator |
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_alg_init() or invalid |
| MDZ_ERROR_DATA | pcData is NULL |
| MDZ_ERROR_BIG_RIGHT | nRightPos is SIZE_MAX |
| MDZ_ERROR_BIG_LEFT | nLeftPos > nRightPos |
| MDZ_ERROR_ITEMS | pcItems is NULL |
| MDZ_ERROR_ZERO_COUNT | pcItems is empty and nCount is 0 |
| 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_alg Reference
Find first non-occurrence of any Item of pcItems in pcData . 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_alg_firstNotOf(const char* pcData, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount, enum mdz_error* penError);
Parameter | Description |
pcData | pointer to string |
nLeftPos | 0-based end position to find up to. Use 0 to search till the beginning of pcData |
nRightPos | 0-based start position to find from right. Use Size-1 to search till the end of pcData |
pcItems | items to find. Cannot be NULL , but can contain 0-terminators inside |
nCount | length of pcItems to find, or 0 for pcItems length until 0-terminator |
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_alg_init() or invalid |
| MDZ_ERROR_DATA | pcData is NULL |
| MDZ_ERROR_BIG_RIGHT | nRightPos is SIZE_MAX |
| MDZ_ERROR_BIG_LEFT | nLeftPos > nRightPos |
| MDZ_ERROR_ITEMS | pcItems is NULL |
| MDZ_ERROR_ZERO_COUNT | pcItems is empty and nCount is 0 |
| 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_alg Reference
Find last occurrence of any Item of pcItems in pcData . 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_alg_lastOf(const char* pcData, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount, enum mdz_error* penError);
Parameter | Description |
pcData | pointer to string |
nLeftPos | 0-based end position to find up to. Use 0 to search till the beginning of pcData |
nRightPos | 0-based start position to find from right. Use Size-1 to search till the end of pcData |
pcItems | items to find. Cannot be NULL , but can contain 0-terminators inside |
nCount | length of pcItems to find, or 0 for pcItems length until 0-terminator |
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_alg_init() or invalid |
| MDZ_ERROR_DATA | pcData is NULL |
| MDZ_ERROR_BIG_RIGHT | nRightPos is SIZE_MAX |
| MDZ_ERROR_BIG_LEFT | nLeftPos > nRightPos |
| MDZ_ERROR_ITEMS | pcItems is NULL |
| MDZ_ERROR_ZERO_COUNT | pcItems is empty and nCount is 0 |
| 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_alg Reference
Find last non-occurrence of any Item of pcItems in pcData . 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_alg_lastNotOf(const char* pcData, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount, enum mdz_error* penError);
Parameter | Description |
pcData | pointer to string |
nLeftPos | 0-based end position to find up to. Use 0 to search till the beginning of pcData |
nRightPos | 0-based start position to find from right. Use Size-1 to search till the end of pcData |
pcItems | items to find. Cannot be NULL , but can contain 0-terminators inside |
nCount | length of pcItems to find, or 0 for pcItems length until 0-terminator |
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_alg_init() or invalid |
| MDZ_ERROR_DATA | pcData is NULL |
| MDZ_ERROR_BIG_RIGHT | nRightPos is SIZE_MAX |
| MDZ_ERROR_BIG_LEFT | nLeftPos > nRightPos |
| MDZ_ERROR_ITEMS | pcItems is NULL |
| MDZ_ERROR_ZERO_COUNT | pcItems is empty and nCount is 0 |
| 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_alg Reference
Remove nCount characters/bytes from pcData , starting from 0-based nLeftPos position
enum mdz_error mdz_ansi_alg_removeFrom(char* pcData, size_t* pnDataSize, size_t nLeftPos, size_t nCount);
Parameter | Description |
pcData | pointer to string. It should end with 0-terminator |
pnDataSize | pointer to current Size . If removal succeed, new size is returned here |
nLeftPos | 0-based start position to remove characters/bytes from. Use 0 to remove from the beginning of pcData |
nCount | number of characters/bytes to remove. Cannot be 0 |
Return | Description |
MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_alg_init() or invalid |
MDZ_ERROR_DATA | pcData is NULL |
MDZ_ERROR_SIZE | pnDataSize is NULL |
MDZ_ERROR_ZERO_SIZE | Size is 0 (string is empty) |
MDZ_ERROR_TERMINATOR | there is no 0-terminator in the end of pcData ([Size ] position) |
MDZ_ERROR_ZERO_COUNT | pcItems is empty and nCount is 0 |
MDZ_ERROR_BIG_LEFT | nLeftPos >= Size |
MDZ_ERROR_BIG_COUNT | nLeftPos + nCount > Size |
MDZ_ERROR_NONE | function succeeded, new size is written in pnDataSize |
mdz_ansi_alg Reference
Remove all ocurrences of pcItems from pcData , residing between nLeftPos and nRightPos
enum mdz_error mdz_ansi_alg_remove(char* pcData, size_t* pnDataSize, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount, mdz_bool bFromLeft);
Parameter | Description |
pcData | pointer to string. It should end with 0-terminator |
pnDataSize | pointer to current Size . If removal succeed, new size is returned here |
nLeftPos | 0-based start position to remove pcItems from. Use 0 to search from the beginning of pcData |
nRightPos | 0-based end position to remove pcItems up to. Use Size-1 to search till the end of pcData |
pcItems | items to remove. Cannot be NULL , but can contain 0-terminators inside |
nCount | length of pcItems , or 0 for pcItems length until 0-terminator |
bFromLeft | mdz_true if search for pcItems to remove from left side, otherwise from right |
Return | Description |
MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_alg_init() or invalid |
MDZ_ERROR_DATA | pcData is NULL |
MDZ_ERROR_SIZE | pnDataSize is NULL |
MDZ_ERROR_ZERO_SIZE | Size is 0 (string is empty) |
MDZ_ERROR_TERMINATOR | there is no 0-terminator in the end of pcData ([Size ] position) |
MDZ_ERROR_ITEMS | pcItems is NULL |
MDZ_ERROR_ZERO_COUNT | pcItems is empty and nCount 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_NONE | function succeeded, new size is written in pnDataSize |
mdz_ansi_alg Reference
Remove leading characters/bytes contained in pcItems from pcData , starting from nLeftPos until first Item non-contained in pcItems is reached.
enum mdz_error mdz_ansi_alg_trimLeft(char* pcData, size_t* pnDataSize, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount);
Parameter | Description |
pcData | pointer to string. It should end with 0-terminator |
pnDataSize | pointer to current Size . If removal succeed, new size is returned here |
nLeftPos | 0-based start position to trim from left. Use 0 to trim from the beginning of pcData |
nRightPos | 0-based end position to trim up to. Use Size-1 to trim till the end of pcData |
pcItems | items to trim. Cannot be NULL , but can contain 0-terminators inside |
nCount | length of pcItems to trim, or 0 for pcItems length until 0-terminator |
Return | Description |
MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_alg_init() or invalid |
MDZ_ERROR_DATA | pcData is NULL |
MDZ_ERROR_SIZE | pnDataSize is NULL |
MDZ_ERROR_ZERO_SIZE | Size is 0 (string is empty) |
MDZ_ERROR_TERMINATOR | there is no 0-terminator in the end of pcData ([Size ] position) |
MDZ_ERROR_ITEMS | pcItems is NULL |
MDZ_ERROR_ZERO_COUNT | pcItems is empty and nCount is 0 |
MDZ_ERROR_BIG_RIGHT | nRightPos >= Size |
MDZ_ERROR_BIG_LEFT | nLeftPos > nRightPos |
MDZ_ERROR_NONE | function succeeded, new size is written in pnDataSize |
mdz_ansi_alg Reference
Remove trailing characters/bytes contained in pcItems from pcData , starting from nRightPos until first Item non-contained in pcItems is reached.
enum mdz_error mdz_ansi_alg_trimRight(char* pcData, size_t* pnDataSize, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount);
Parameter | Description |
pcData | pointer to string. It should end with 0-terminator |
pnDataSize | pointer to current Size . If removal succeed, new size is returned here |
nLeftPos | 0-based end position to trim up to. Use 0 to trim till the beginning of pcData |
nRightPos | 0-based start position to trim from right. Use Size-1 to trim from the end of pcData |
pcItems | items to trim. Cannot be NULL , but can contain 0-terminators inside |
nCount | length of pcItems to trim, or 0 for pcItems length until 0-terminator |
Return | Description |
MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_alg_init() or invalid |
MDZ_ERROR_DATA | pcData is NULL |
MDZ_ERROR_SIZE | pnDataSize is NULL |
MDZ_ERROR_ZERO_SIZE | Size is 0 (string is empty) |
MDZ_ERROR_TERMINATOR | there is no 0-terminator in the end of pcData ([Size ] position) |
MDZ_ERROR_ITEMS | pcItems is NULL |
MDZ_ERROR_ZERO_COUNT | pcItems is empty and nCount is 0 |
MDZ_ERROR_BIG_RIGHT | nRightPos >= Size |
MDZ_ERROR_BIG_LEFT | nLeftPos > nRightPos |
MDZ_ERROR_NONE | function succeeded, new size is written in pnDataSize |
mdz_ansi_alg Reference
Remove leading and trailing characters/bytes contained in pcItems pcData , starting from nLeftPos and from nRightPos , until first Item non-contained in pcItems is reached.
enum mdz_error mdz_ansi_alg_trim(char* pcData, size_t* pnDataSize, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount);
Parameter | Description |
pcData | pointer to string. It should end with 0-terminator |
pnDataSize | pointer to current Size . If removal succeed, new size is returned here |
nLeftPos | 0-based start position to trim from left. Use 0 to trim from the beginning of pcData |
nRightPos | 0-based start position to trim from right. Use Size-1 to trim from the end of pcData |
pcItems | items to trim. Cannot be NULL , but can contain 0-terminators inside |
nCount | length of pcItems to trim, or 0 for pcItems length until 0-terminator |
Return | Description |
MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_alg_init() or invalid |
MDZ_ERROR_DATA | pcData is NULL |
MDZ_ERROR_SIZE | pnDataSize is NULL |
MDZ_ERROR_ZERO_SIZE | Size is 0 (string is empty) |
MDZ_ERROR_TERMINATOR | there is no 0-terminator in the end of pcData ([Size ] position) |
MDZ_ERROR_ITEMS | pcItems is NULL |
MDZ_ERROR_ZERO_COUNT | pcItems is empty and nCount is 0 |
MDZ_ERROR_BIG_RIGHT | nRightPos >= Size |
MDZ_ERROR_BIG_LEFT | nLeftPos > nRightPos |
MDZ_ERROR_NONE | function succeeded, new size is written in pnDataSize |
mdz_ansi_alg Reference
Compares pcData with pcItems on equalty by length and content. If penError is not NULL , error will be written there
enum mdz_ansi_compare_result mdz_ansi_alg_equal(const char* pcData, size_t nDataSize, const char* pcItems, size_t nCount, enum mdz_error* penError);
Parameter | Description |
pcData | pointer to string |
nDataSize | Size of pcData |
pcItems | items to compare. Cannot be NULL , but can contain 0-terminators inside |
nCount | length of pcItems to compare, or 0 for pcItems length until 0-terminator |
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_alg_init() or invalid |
| MDZ_ERROR_DATA | pcData is NULL |
| MDZ_ERROR_SIZE | Size is 0 (empty string) |
| MDZ_ERROR_ITEMS | pcItems is NULL |
| MDZ_ERROR_ZERO_COUNT | pcItems is empty and nCount is 0 |
| MDZ_ERROR_NONE | function succeeded |
Return | Description |
MDZ_ANSI_COMPARE_ERROR | if there is error |
MDZ_COMPARE_EQUAL | if pcData and pcItems are equal |
MDZ_COMPARE_NONEQUAL | if pcData and pcItems are not equal |
mdz_ansi_alg Reference
Compare content of pcData with pcItems . If penError is not NULL , error will be written there
enum mdz_ansi_compare_result mdz_ansi_alg_compare(const char* pcData, size_t nDataSize, size_t nLeftPos, const char* pcItems, size_t nCount, enum mdz_error* penError);
Parameter | Description |
pcData | pointer to string |
nDataSize | Size of pcData |
nLeftPos | 0-based start position to compare from left. Use 0 to compare from the beginning of pcData |
pcItems | items to compare. Cannot be NULL , but can contain 0-terminators inside |
nCount | length of pcItems to compare, or 0 for pcItems length until 0-terminator |
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_alg_init() or invalid |
| MDZ_ERROR_DATA | pcData is NULL |
| MDZ_ERROR_SIZE | Size is 0 (empty string) |
| MDZ_ERROR_ITEMS | pcItems is NULL |
| MDZ_ERROR_ZERO_COUNT | pcItems is empty and nCount is 0 |
| MDZ_ERROR_BIG_LEFT | nLeftPos >= Size |
| MDZ_ERROR_BIG_COUNT | nLeftPos + nCount > Size |
| MDZ_ERROR_NONE | function succeeded |
Return | Description |
MDZ_ANSI_COMPARE_ERROR | if there is error |
MDZ_COMPARE_EQUAL | if pcData and pcItems are equal |
MDZ_COMPARE_NONEQUAL | if pcData and pcItems are not equal |
mdz_ansi_alg Reference
Counts number of pcItems occurences in pcData . If penError is not NULL , error will be written there
size_t mdz_ansi_alg_count(const char* pcData, size_t nLeftPos, size_t nRightPos, const char* pcItems, size_t nCount, mdz_bool bAllowOverlapped, mdz_bool bFromLeft, enum mdz_error* penError);
Parameter | Description |
pcData | pointer to string |
nLeftPos | 0-based start position to search from left. Use 0 to search from the beginning of pcData |
nRightPos | 0-based end position to search up to. Use Size-1 to search till the end of pcData |
pcItems | items to find. Cannot be NULL , but can contain 0-terminators inside |
nCount | length of pcItems to find, or 0 for pcItems length until 0-terminator |
bAllowOverlapped | mdz_true if overlapped pcItems should be counted, otherwise mdz_false |
bFromLeft | mdz_true if search for pcItems 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_alg_init() or invalid |
| MDZ_ERROR_DATA | pcData is NULL |
| MDZ_ERROR_BIG_RIGHT | nRightPos is SIZE_MAX |
| MDZ_ERROR_BIG_LEFT | nLeftPos > nRightPos |
| MDZ_ERROR_ITEMS | pcItems is NULL |
| MDZ_ERROR_ZERO_COUNT | pcItems is empty and nCount is 0 |
| MDZ_ERROR_BIG_COUNT | 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_alg Reference
Replace every occurence of pcItemsBefore with pcItemsAfter in pcData . There should be enough Capacity for replacing data.
enum mdz_error mdz_ansi_alg_replace(char* pcData, size_t* pnDataSize, size_t nDataCapacity, 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, size_t* pnNewSize);
Parameter | Description |
pcData | pointer to string |
pnDataSize | pointer to current Size . If replacement succeed, new size is returned here |
nDataCapacity | maximal capacity of pcData buffer. nDataCapacity does not include 0-terminator byte, thus pcData buffer should be at least 1 byte bigger than nDataCapacity |
nLeftPos | 0-based start position to search for replace from. Use 0 to search from the beginning of pcData |
nRightPos | 0-based end position to search for replace up to. Use Size-1 or SIZE_MAX to seach till the end of pcData |
pcItemsBefore | items to find. Cannot be NULL , but can contain 0-terminators inside |
nCountBefore | length of pcItemsBefore to find, or 0 for pcItemsBefore length until 0-terminator |
pcItemsAfter | pointer to items to replace with. Can be NULL (in this case nCountAfter is treated as 0) |
nCountAfter | length of pcItemsAfter to replace, or 0 for pcItemsAfter length until 0-terminator |
bFromLeft | mdz_true if search for pcItemsBefore 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) |
pnNewSize | if nCountAfter > nCountBefore and there is not enough Capacity to make all replacements - minimal-necessary size is returned here, if pnNewSize is not NULL |
Return | Description |
MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_alg_init() or invalid |
MDZ_ERROR_DATA | pcData is NULL |
MDZ_ERROR_SIZE | pnDataSize is NULL |
MDZ_ERROR_CAPACITY | nDataCapacity is 0 (no space for insertion) or SIZE_MAX (no space for 0-terminator) |
MDZ_ERROR_BIG_SIZE | Size > Capacity |
MDZ_ERROR_ZERO_SIZE | Size is 0 (string is empty) |
MDZ_ERROR_TERMINATOR | there is no 0-terminator in the end of pcData ([Size ] position) |
MDZ_ERROR_ITEMS | pcItemsBefore is NULL |
MDZ_ERROR_ZERO_COUNT | pcItemsBefore is empty and 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 | pcData overlaps with pcItemsBefore , or pcData overlaps with pcItemsAfter |
MDZ_ERROR_REPLACEMENT_TYPE | enReplacementType is invalid |
MDZ_ERROR_BIG_REPLACE | new Size after replacement > Capacity |
MDZ_ERROR_OVERLAP_REPLACE | pcData after replacement - overlaps with pcItemsBefore , or pcData after replacement - overlaps with pcItemsAfter |
MDZ_ERROR_NONE | function succeeded |
mdz_ansi_alg Reference
Reverses characters/bytes in pcData , like "1234" into "4321".
enum mdz_error mdz_ansi_alg_reverse(char* pcData, size_t nLeftPos, size_t nRightPos);
Parameter | Description |
pcData | pointer to string |
nLeftPos | 0-based start position to search for replace from. Use 0 to search from the beginning of pcData |
nRightPos | 0-based end position to search for replace up to. Use Size-1 or SIZE_MAX to seach till the end of pcData |
Return | Description |
MDZ_ERROR_LICENSE | license is not initialized using mdz_ansi_alg_init() or invalid |
MDZ_ERROR_DATA | pcData is NULL |
MDZ_ERROR_BIG_RIGHT | nRightPos is SIZE_MAX |
MDZ_ERROR_BIG_LEFT | nLeftPos >= nRightPos |
MDZ_ERROR_NONE | function succeeded |
mdz_ansi_alg Reference
|