String libraryString.h
The String library provides safe string functions which have almost the same functionality as string functions from the standard C library, but without their shortcomings. They work around buffer overflow problem, which is common problem for string library in libc. These safe functions signal by a return code to caller, that source string is too long to store it into selected buffer, and roll back all data which have been already partially copied from source string into the target buffer.
Contents
- String compare function prototypes
- String length
- Copying
- Copying of string to string
- Copying of characters sequence to string
- Concatenating
- Concatenating of string to string
- Concatenating of characters sequence to string
- String comparison
- Comparison of strings
- Comparison of characters sequences
- Symbol search
- Searching for single symbol
- Forward direction search
- Backward direction search
- Searching for symbols set
- Forward direction search
- Backward direction search
- Substring search
- Searching string for pattern
- Forward direction search
- Backward direction search
- Searching characters sequence for pattern
- Forward direction search
- Backward direction search
- String search
- Linear search
- Forward direction search
- Backward direction search
- Binary search
- Ascending sort order
- Searching for first equal string
- Searching for last equal string
- Searching for greater string
- Searching for greater or equal string
- Searching for less string
- Searching for less or equal string
- Descending sort order
- Searching for first equal string
- Searching for last equal string
- Searching for less string
- Searching for less or equal string
- Searching for greater string
- Searching for greater or equal string
- Counting
- Symbol counting
- Single symbol counting
- Symbols set counting
- String counting
- Linear counting
- Binary counting
- Ascending sort order
- Descending sort order
- Replacing
- Symbol replacing
- String replacing
- Order reversing
- Unique values
- Duplicate values
- Insertion sort
- String array sorting
- Ascending sort order
- Descending sort order
- Key array sorting
- Ascending sort order
- Descending sort order
- Quick sort
- String array sorting
- Ascending sort order
- Descending sort order
- Key array sorting
- Ascending sort order
- Descending sort order
- Merge sort
- String array sorting
- Ascending sort order
- Descending sort order
- Key array sorting
- Ascending sort order
- Descending sort order
- Merging of sorted strings
- String array merging
- Ascending sort order
- Descending sort order
- Key array merging
- Ascending sort order
- Descending sort order
- Checks
- Check for duplicate values
- Check for sort order
- Check for ascending sort order
- Check for descending sort order
- String hashing
- 32-bit hash functions
- 64-bit hash functions
Function list
C function name | Functions | C++ function name | Functions |
---|---|---|---|
Cat | 3 functions | Cat | 3 functions |
CatN | 3 functions | CatN | 3 functions |
CheckDup | 3 functions | CheckDup | 3 functions |
CheckSortAsc | 3 functions | CheckSortAsc | 3 functions |
CheckSortDsc | 3 functions | CheckSortDsc | 3 functions |
Compare | 3 functions | Compare | 3 functions |
CompareN | 3 functions | CompareN | 3 functions |
Copy | 3 functions | Copy | 3 functions |
CopyN | 3 functions | CopyN | 3 functions |
CountString | 3 functions | CountString | 3 functions |
CountStringAsc | 3 functions | CountStringAsc | 3 functions |
CountStringDsc | 3 functions | CountStringDsc | 3 functions |
CountSymbol | 3 functions | CountSymbol | 3 functions |
CountSymbols | 3 functions | CountSymbols | 3 functions |
Duplicates | 3 functions | Duplicates | 3 functions |
FindBwd | 3 functions | FindBwd | 3 functions |
FindFirstEqualAsc | 3 functions | FindFirstEqualAsc | 3 functions |
FindFirstEqualDsc | 3 functions | FindFirstEqualDsc | 3 functions |
FindFwd | 3 functions | FindFwd | 3 functions |
FindGreatAsc | 3 functions | FindGreatAsc | 3 functions |
FindGreatDsc | 3 functions | FindGreatDsc | 3 functions |
FindGreatOrEqualAsc | 3 functions | FindGreatOrEqualAsc | 3 functions |
FindGreatOrEqualDsc | 3 functions | FindGreatOrEqualDsc | 3 functions |
FindLastEqualAsc | 3 functions | FindLastEqualAsc | 3 functions |
FindLastEqualDsc | 3 functions | FindLastEqualDsc | 3 functions |
FindLessAsc | 3 functions | FindLessAsc | 3 functions |
FindLessDsc | 3 functions | FindLessDsc | 3 functions |
FindLessOrEqualAsc | 3 functions | FindLessOrEqualAsc | 3 functions |
FindLessOrEqualDsc | 3 functions | FindLessOrEqualDsc | 3 functions |
FindSubStringBwd | 3 functions | FindSubStringBwd | 3 functions |
FindSubStringFwd | 3 functions | FindSubStringFwd | 3 functions |
FindSubStringNBwd | 3 functions | FindSubStringNBwd | 3 functions |
FindSubStringNFwd | 3 functions | FindSubStringNFwd | 3 functions |
FindSymbolBwd | 3 functions | FindSymbolBwd | 3 functions |
FindSymbolFwd | 3 functions | FindSymbolFwd | 3 functions |
FindSymbolsBwd | 3 functions | FindSymbolsBwd | 3 functions |
FindSymbolsFwd | 3 functions | FindSymbolsFwd | 3 functions |
Hash32 | 3 functions | Hash32 | 3 functions |
Hash64 | 3 functions | Hash64 | 3 functions |
InsertSortAsc | 3 functions | InsertSortAsc | 3 functions |
InsertSortDsc | 3 functions | InsertSortDsc | 3 functions |
InsertSortKeyAsc | 3 functions | InsertSortKeyAsc | 3 functions |
InsertSortKeyDsc | 3 functions | InsertSortKeyDsc | 3 functions |
Len | 3 functions | Len | 3 functions |
MergeAsc | 3 functions | MergeAsc | 3 functions |
MergeDsc | 3 functions | MergeDsc | 3 functions |
MergeKeyAsc | 3 functions | MergeKeyAsc | 3 functions |
MergeKeyDsc | 3 functions | MergeKeyDsc | 3 functions |
MergeSortAsc | 3 functions | MergeSortAsc | 3 functions |
MergeSortDsc | 3 functions | MergeSortDsc | 3 functions |
MergeSortKeyAsc | 3 functions | MergeSortKeyAsc | 3 functions |
MergeSortKeyDsc | 3 functions | MergeSortKeyDsc | 3 functions |
QuickSortAsc | 3 functions | QuickSortAsc | 3 functions |
QuickSortDsc | 3 functions | QuickSortDsc | 3 functions |
QuickSortKeyAsc | 3 functions | QuickSortKeyAsc | 3 functions |
QuickSortKeyDsc | 3 functions | QuickSortKeyDsc | 3 functions |
ReplaceString | 3 functions | ReplaceString | 3 functions |
ReplaceSymbol | 3 functions | ReplaceSymbol | 3 functions |
Reverse | 3 functions | Reverse | 3 functions |
Unique | 3 functions | Unique | 3 functions |
C function name | Functions | C++ function name | Functions |
String compare function prototypes
String compare functions are used by searching and sorting algorithms. They take two constant strings and return relation between them as signed integer number: 0 if first string is equal to second string; 1 if first string is greater than second string, and -1 if first string is less than second string.
Standard compare functions, which are implemented in the library, do lexicographical comparison (compare bytes, machine words, etc.). For some sorting algorithm you may need to change this behavior to user defined sorting order, which take into consideration alphabetical sort order, case of letters, or assume preceding zeroes before numbers. To do so you may wish to implement your own functions, to use with the library. This can be done by a pointer to a functions, which is passed as a parameter to sorting and searching algorithms of string library.
Each user defined compare function should conform to the prototypes specified below.
C/C++sint64_t CmpChar8 (const char8_t string1[], const char8_t string2[]); sint64_t CmpChar16 (const char16_t string1[], const char16_t string2[]); sint64_t CmpChar32 (const char32_t string1[], const char32_t string2[]);
Parameters:
- string1 - a constant pointer to first string
- string2 - a constant pointer to second string
Return value:
- -1 if first string is less than second string
- 0 if first string is equal to second string
- +1 if first string is greater than second string
String length
Csize_t String_Len_char8 (const char8_t string[]); size_t String_Len_char16 (const char16_t string[]); size_t String_Len_char32 (const char32_t string[]);
C++size_t String::Len (const char8_t string[]); size_t String::Len (const char16_t string[]); size_t String::Len (const char32_t string[]);
Description: Calculate length of specified string, excluding terminating null symbol (0)
Parameters:
- string - pointer to a string
Return value: Number of characters (not bytes) in the string.
Copying
String copy functions provide safe methods to copy string content to another string. If size of source string is greater than the buffer length, then functions clear target string (make empty string) and return -1, which means that the buffer has no enough space to hold result string. Source string may be a regular string or a characters sequence.
Copying of string to string
Csize_t String_Copy_char8 (char8_t target[], size_t maxlen, const char8_t source[]); size_t String_Copy_char16 (char16_t target[], size_t maxlen, const char16_t source[]); size_t String_Copy_char32 (char32_t target[], size_t maxlen, const char32_t source[]);
C++size_t String::Copy (char8_t target[], size_t maxlen, const char8_t source[]); size_t String::Copy (char16_t target[], size_t maxlen, const char16_t source[]); size_t String::Copy (char32_t target[], size_t maxlen, const char32_t source[]);
Description: Copy source string, including terminating null symbol (0), to target string. If source string size is greater than maxlen, then functions clear content of destination string (return empty string).
Parameters:
- target - pointer to target string
- maxlen - maximum length (number of characters) of target string, without last null symbol (0)
- source - pointer to source string
Return value:
- Number of characters (not bytes) were copied from source string to target string, excluding null symbol (0).
- -1 if source string size is greater than maxlen.
Warning:Content of source string will be unexpectedly modified if strings are overlapped in memory, and both will have unpredictable data.
Copying of characters sequence to string
Csize_t String_CopyN_char8 (char8_t target[], size_t maxlen, const char8_t source[], size_t size); size_t String_CopyN_char16 (char16_t target[], size_t maxlen, const char16_t source[], size_t size); size_t String_CopyN_char32 (char32_t target[], size_t maxlen, const char32_t source[], size_t size);
C++size_t String::CopyN (char8_t target[], size_t maxlen, const char8_t source[], size_t size); size_t String::CopyN (char16_t target[], size_t maxlen, const char16_t source[], size_t size); size_t String::CopyN (char32_t target[], size_t maxlen, const char32_t source[], size_t size);
Description: Copy specified count or less count of characters from source sequence to target string, and put terminating null symbol (0). If source characters sequence size is greater than maxlen, then functions clear content of destination string (return empty string). The functions may return less count of characters than were specified by size parameter, if null symbol (0) was found in source sequence.
Parameters:
- target - pointer to target string
- maxlen - maximum length (number of characters) of target string, without last null symbol (0)
- source - pointer to source characters sequence
- size - maximum number of character to be copied from source characters sequence
Return value:
- Number of characters (not bytes) were copied from source characters sequence to target string, excluding null symbol (0).
- -1 if source characters sequence size is greater than maxlen.
Warning:Content of source sequence will be unexpectedly modified if it overlaps in memory with destination string, and both will have unpredictable data.
Note:Maxlen is maximum string length (count of characters, excluding null symbol), but not an array size. Do not misunderstand the meaning of maxlen parameter.
Concatenating
These functions add source string to the end of target string and check size of result string to fit into the target string buffer. If size of result string is greater than the buffer length, then target string stay unchanged and functions return -1, which means that the buffer has no enough space to hold result string. Source string may be a regular string or a characters sequence.
Concatenating of string to string
Csize_t String_Cat_char8 (char8_t target[], size_t maxlen, const char8_t source[]); size_t String_Cat_char16 (char16_t target[], size_t maxlen, const char16_t source[]); size_t String_Cat_char32 (char32_t target[], size_t maxlen, const char32_t source[]);
C++size_t String::Cat (char8_t target[], size_t maxlen, const char8_t source[]); size_t String::Cat (char16_t target[], size_t maxlen, const char16_t source[]); size_t String::Cat (char32_t target[], size_t maxlen, const char32_t source[]);
Description: Add source string, including terminating null symbol (0), to target string. If source string length is greater than maxlen, then content of destination string is unchanged.
Parameters:
- target - pointer to target string
- maxlen - maximum length (number of characters) of target string, without last null symbol (0)
- source - pointer to source string
Return value:
- Number of characters (not bytes) were added from source string to target string, excluding null symbol (0).
- -1 if source string length is greater than maxlen.
Warning:Content of source string will be unexpectedly modified if strings are overlapped in memory, and both will have unpredictable data.
Concatenating of characters sequence to string
Csize_t String_CatN_char8 (char8_t target[], size_t maxlen, const char8_t source[], size_t size); size_t String_CatN_char16 (char16_t target[], size_t maxlen, const char16_t source[], size_t size); size_t String_CatN_char32 (char32_t target[], size_t maxlen, const char32_t source[], size_t size);
C++size_t String::CatN (char8_t target[], size_t maxlen, const char8_t source[], size_t size); size_t String::CatN (char16_t target[], size_t maxlen, const char16_t source[], size_t size); size_t String::CatN (char32_t target[], size_t maxlen, const char32_t source[], size_t size);
Description: Add specified count or less count of characters from source sequence to target string, and put terminating null symbol (0). If source characters sequence size is greater than maxlen, then content of destination string is unchanged. The functions may return less count of characters than were specified by size parameter, if null symbol (0) was found in source sequence.
Parameters:
- target - pointer to target string
- maxlen - maximum length (number of characters) of target string, without last null symbol (0)
- source - pointer to source characters sequence
- size - maximum number of character to be concatenated from source characters sequence
Return value:
- Number of characters (not bytes) were added from source characters sequence to target string, excluding null symbol (0).
- -1 if source characters sequence size is greater than maxlen.
Warning:Content of source sequence will be unexpectedly modified if it overlaps in memory with destination string, and both will have unpredictable data.
String comparison
These functions compare strings and return compare status as signed integer value: 0 if strings are equal, 1 if first string is lexicographical greater than second string, and -1 if first string is lexicographical less than second string. Strings are compared ignoring locale settings or alphabetic sort order. Compare procedure uses binary representation of string to find their relations.
Comparison of strings
Csint64_t String_Compare_char8 (const char8_t string1[], const char8_t string2[]); sint64_t String_Compare_char16 (const char16_t string1[], const char16_t string2[]); sint64_t String_Compare_char32 (const char32_t string1[], const char32_t string2[]);
C++sint64_t String::Compare (const char8_t string1[], const char8_t string2[]); sint64_t String::Compare (const char16_t string1[], const char16_t string2[]); sint64_t String::Compare (const char32_t string1[], const char32_t string2[]);
Description: Compare two strings and return relations between them (greater than, less than or equal).
Parameters:
- string1 - pointer to first string
- string2 - pointer to second string
Return value:
- -1 if first string is less than second string
- 0 if strings are equal
- +1 if first string is greater than second string
Comparison of characters sequences
Csint64_t String_CompareN_char8 (const char8_t string1[], const char8_t string2[], size_t size); sint64_t String_CompareN_char16 (const char16_t string1[], const char16_t string2[], size_t size); sint64_t String_CompareN_char32 (const char32_t string1[], const char32_t string2[], size_t size);
C++sint64_t String::CompareN (const char8_t string1[], const char8_t string2[], size_t size); sint64_t String::CompareN (const char16_t string1[], const char16_t string2[], size_t size); sint64_t String::CompareN (const char32_t string1[], const char32_t string2[], size_t size);
Description: Compare two characters sequences and return relations between them (greater than, less than or equal).
Parameters:
- string1 - pointer to first characters sequence
- string2 - pointer to second characters sequence
- size - size of characters sequences (number of characters)
Return value:
- -1 if first characters sequence is less than second characters sequence
- 0 if characters sequences are equal
- +1 if first characters sequence is greater than second characters sequence
Symbol search
These functions implement search algorithms which find first/last occurrence of looking symbol or symbols set. If target symbol is found, they return its index, or -1 if pattern was not found.
Searching for single symbol
Single symbol search functions check the string for required symbol and return its first or last occurrence into the string. If the symbol is not found, then -1 is returned. If you are looking for null symbol (0), then you should use string length functions instead. Because symbol searching algorithms do not check string for this symbol.
Forward direction search
Csize_t String_FindSymbolFwd_char8 (const char8_t string[], char8_t symbol); size_t String_FindSymbolFwd_char16 (const char16_t string[], char16_t symbol); size_t String_FindSymbolFwd_char32 (const char32_t string[], char32_t symbol);
C++size_t String::FindSymbolFwd (const char8_t string[], char8_t symbol); size_t String::FindSymbolFwd (const char16_t string[], char16_t symbol); size_t String::FindSymbolFwd (const char32_t string[], char32_t symbol);
Description: Search the string for specified symbol and return index of its first occurrence.
Parameters:
- string - string for searching
- symbol - looking symbol
Return value:
- An index of first occurrence of specified symbol.
- -1 if symbol was not found, or the looking symbol is null symbol (0).
Note:This function ignores null symbol (0) as search pattern. To find its position use string length function instead.
Backward direction search
Csize_t String_FindSymbolBwd_char8 (const char8_t string[], char8_t symbol); size_t String_FindSymbolBwd_char16 (const char16_t string[], char16_t symbol); size_t String_FindSymbolBwd_char32 (const char32_t string[], char32_t symbol);
C++size_t String::FindSymbolBwd (const char8_t string[], char8_t symbol); size_t String::FindSymbolBwd (const char16_t string[], char16_t symbol); size_t String::FindSymbolBwd (const char32_t string[], char32_t symbol);
Description: Search the string for specified symbol and return index of its last occurrence.
Parameters:
- string - string for searching
- symbol - looking symbol
Return value:
- An index of last occurrence of specified symbol.
- -1 if symbol was not found, or the looking symbol is null symbol (0).
Note:This function ignores null symbol (0) as search pattern. To find its position use string length function instead.
Searching for symbols set
Symbols set search functions check the string for required set of symbol and return first or last occurrence of any symbol into the string. If no symbol is not found, then -1 is returned. Search functions ignore null symbol (0) into the symbols set. That is why they return -1 if no symbol from the set (except the null symbol) is found.
Forward direction search
Csize_t String_FindSymbolsFwd_char8 (const char8_t string[], const char8_t symbols[]); size_t String_FindSymbolsFwd_char16 (const char16_t string[], const char16_t symbols[]); size_t String_FindSymbolsFwd_char32 (const char32_t string[], const char32_t symbols[]);
C++size_t String::FindSymbolsFwd (const char8_t string[], const char8_t symbols[]); size_t String::FindSymbolsFwd (const char16_t string[], const char16_t symbols[]); size_t String::FindSymbolsFwd (const char32_t string[], const char32_t symbols[]);
Description: Search string for specified symbols set and return index of first occurrence of any symbol from that set if found.
Parameters:
- string - string for searching
- symbols - looking symbols set
Return value:
- An index of first occurrence of any symbol from the symbols set.
- -1 if none symbol was found.
Note:Symbols set should have terminating null symbol (0). That is. It will look like regular string.
Backward direction search
Csize_t String_FindSymbolsBwd_char8 (const char8_t string[], const char8_t symbols[]); size_t String_FindSymbolsBwd_char16 (const char16_t string[], const char16_t symbols[]); size_t String_FindSymbolsBwd_char32 (const char32_t string[], const char32_t symbols[]);
C++size_t String::FindSymbolsBwd (const char8_t string[], const char8_t symbols[]); size_t String::FindSymbolsBwd (const char16_t string[], const char16_t symbols[]); size_t String::FindSymbolsBwd (const char32_t string[], const char32_t symbols[]);
Description: Search string for specified symbols set and return index of last occurrence of any symbol from that set if found.
Parameters:
- string - string for searching
- symbols - looking symbols set
Return value:
- An index of last occurrence of any symbol from the symbols set.
- -1 if none symbol was found.
Note:Symbols set should have terminating null symbol (0). That is. It will look like regular string.
Substring search
Substring search locate position of a regular string, called pattern, into a source string or characters sequence. If pattern is found then it returns index of first/last symbol where pattern matched string, or -1 if substring was not found.
Searching string for pattern
Following functions search regular string for first/last occurrence of substring (pattern) and return first or last position of that pattern into the string. If pattern was not found, then -1 is returned.
Forward direction search
Csize_t String_FindSubStringFwd_char8 (const char8_t string[], const char8_t pattern[]); size_t String_FindSubStringFwd_char16 (const char16_t string[], const char16_t pattern[]); size_t String_FindSubStringFwd_char32 (const char32_t string[], const char32_t pattern[]);
C++size_t String::FindSubStringFwd (const char8_t string[], const char8_t pattern[]); size_t String::FindSubStringFwd (const char16_t string[], const char16_t pattern[]); size_t String::FindSubStringFwd (const char32_t string[], const char32_t pattern[]);
Description: Find first occurrence of pattern into string. Terminating null symbols (0) are not compared.
Parameters:
- string - pointer to string for pattern searching
- pattern - looking pattern
Return value:
- An index of the beginning of pattern (its first occurrence).
- -1 if pattern was not found.
Note:This function uses Boyer-Moore-Horspool subsequence searching algorithm now. So it works very fast for regular texts.
Backward direction search
Csize_t String_FindSubStringBwd_char8 (const char8_t string[], const char8_t pattern[]); size_t String_FindSubStringBwd_char16 (const char16_t string[], const char16_t pattern[]); size_t String_FindSubStringBwd_char32 (const char32_t string[], const char32_t pattern[]);
C++size_t String::FindSubStringBwd (const char8_t string[], const char8_t pattern[]); size_t String::FindSubStringBwd (const char16_t string[], const char16_t pattern[]); size_t String::FindSubStringBwd (const char32_t string[], const char32_t pattern[]);
Description: Find last occurrence of pattern into string. Terminating null symbols (0) are not compared.
Parameters:
- string - pointer to string for pattern searching
- pattern - looking pattern
Return value:
- An index of the beginning of pattern (its last occurrence).
- -1 if pattern was not found.
Note:This function uses Boyer-Moore-Horspool subsequence searching algorithm now. So it works very fast for regular texts.
Searching characters sequence for pattern
Following functions search characters sequence for first/last occurrence of substring (pattern) and return first or last position of that pattern into the characters sequence. If pattern was not found, then -1 is returned.
Forward direction search
Csize_t String_FindSubStringNFwd_char8 (const char8_t string[], size_t size, const char8_t pattern[]); size_t String_FindSubStringNFwd_char16 (const char16_t string[], size_t size, const char16_t pattern[]); size_t String_FindSubStringNFwd_char32 (const char32_t string[], size_t size, const char32_t pattern[]);
C++size_t String::FindSubStringNFwd (const char8_t string[], size_t size, const char8_t pattern[]); size_t String::FindSubStringNFwd (const char16_t string[], size_t size, const char16_t pattern[]); size_t String::FindSubStringNFwd (const char32_t string[], size_t size, const char32_t pattern[]);
Description: Find first occurrence of pattern into characters sequence. Terminating null symbols (0) are not compared.
Parameters:
- string - pointer to characters sequence for pattern searching
- size - size of characters sequence (symbols)
- pattern - looking pattern
Return value:
- An index of the beginning of pattern (its first occurrence).
- -1 if pattern was not found.
Note:This function uses Boyer-Moore-Horspool subsequence searching algorithm now. So it works very fast for regular texts.
Backward direction search
Csize_t String_FindSubStringNBwd_char8 (const char8_t string[], size_t size, const char8_t pattern[]); size_t String_FindSubStringNBwd_char16 (const char16_t string[], size_t size, const char16_t pattern[]); size_t String_FindSubStringNBwd_char32 (const char32_t string[], size_t size, const char32_t pattern[]);
C++size_t String::FindSubStringNBwd (const char8_t string[], size_t size, const char8_t pattern[]); size_t String::FindSubStringNBwd (const char16_t string[], size_t size, const char16_t pattern[]); size_t String::FindSubStringNBwd (const char32_t string[], size_t size, const char32_t pattern[]);
Description: Find last occurrence of pattern into characters sequence. Terminating null symbols (0) are not compared.
Parameters:
- string - pointer to characters sequence for pattern searching
- size - size of characters sequence (symbols)
- pattern - looking pattern
Return value:
- An index of the beginning of pattern (its last occurrence).
- -1 if pattern was not found.
Note:This function uses Boyer-Moore-Horspool subsequence searching algorithm now. So it works very fast for regular texts.
String search
The following functions check an array of strings for a string, which is equal to pattern, and return index of element where it was met first time. Search functions use pointer to compare function, which is used for string matching. To use your own function for compare operations, just pass a pointer to that function to searching procedures.
Linear search
Linear search algorithms check array of strings for first string which is equal to pattern. These functions do not assume that string arrays are sorted, and use linear checkup. For sorted arrays use binary searching algorithms, which are the best for such arrays.
Forward direction search
Csize_t String_FindFwd_char8 (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String_FindFwd_char16 (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String_FindFwd_char32 (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
C++size_t String::FindFwd (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String::FindFwd (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String::FindFwd (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
Description: Search array of strings in forward direction for first occurrence of a string which is equal to pattern.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- string - pointer to string for searching
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value:
- An index of first occurrence of looking string into array.
- -1 if string was not found.
Backward direction search
Csize_t String_FindBwd_char8 (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String_FindBwd_char16 (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String_FindBwd_char32 (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
C++size_t String::FindBwd (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String::FindBwd (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String::FindBwd (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
Description: Search array of strings in backward direction for last occurrence of a string which is equal to pattern.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- string - pointer to string for searching
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value:
- An index of last occurrence of looking string into array.
- -1 if string was not found.
Binary search
Binary searching algorithms check sorted array of strings for first string which is equal to pattern, and return its index into array. These functions assume that array is sorted by the same compare function, which is used for searching, and array have correct sort order. If array has incorrect sort order or wrong compare function is used, then pattern may not be found.
Ascending sort order
Searching for first equal stringtop
Csize_t String_FindFirstEqualAsc_char8 (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String_FindFirstEqualAsc_char16 (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String_FindFirstEqualAsc_char32 (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
C++size_t String::FindFirstEqualAsc (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String::FindFirstEqualAsc (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String::FindFirstEqualAsc (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
Description: Search the array of strings, which is sorted in ascending order for specified string and return index of its first occurrence.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- string - pointer to string for searching
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value:
- An index of first occurrence of specified string.
- -1 if string was not found.
Note:These functions work only with sorted array of strings. To use them with unordered arrays they should be sorted first.
Searching for last equal stringtop
Csize_t String_FindLastEqualAsc_char8 (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String_FindLastEqualAsc_char16 (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String_FindLastEqualAsc_char32 (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
C++size_t String::FindLastEqualAsc (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String::FindLastEqualAsc (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String::FindLastEqualAsc (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
Description: Search the array of strings, which is sorted in ascending order for specified string and return index of its last occurrence.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- string - pointer to string for searching
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value:
- An index of last occurrence of specified string.
- -1 if string was not found.
Note:These functions work only with sorted array of strings. To use them with unordered arrays they should be sorted first.
Searching for greater stringtop
Csize_t String_FindGreatAsc_char8 (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String_FindGreatAsc_char16 (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String_FindGreatAsc_char32 (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
C++size_t String::FindGreatAsc (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String::FindGreatAsc (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String::FindGreatAsc (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
Description: Search the array of strings, which is sorted in ascending order for the first string, which is greater than the specified string.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- string - pointer to string for searching
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value:
- An index of first string, which is greater than the specified string.
- -1 if string was not found.
Note:These functions work only with sorted array of strings. To use them with unordered arrays they should be sorted first.
Searching for greater or equal stringtop
Csize_t String_FindGreatOrEqualAsc_char8 (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String_FindGreatOrEqualAsc_char16 (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String_FindGreatOrEqualAsc_char32 (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
C++size_t String::FindGreatOrEqualAsc (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String::FindGreatOrEqualAsc (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String::FindGreatOrEqualAsc (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
Description: Search the array of strings, which is sorted in ascending order for the first string, which is greater than or equal to the specified string.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- string - pointer to string for searching
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value:
- An index of first string, which is greater than or equal to the specified string.
- -1 if string was not found.
Note:These functions work only with sorted array of strings. To use them with unordered arrays they should be sorted first.
Searching for less stringtop
Csize_t String_FindLessAsc_char8 (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String_FindLessAsc_char16 (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String_FindLessAsc_char32 (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
C++size_t String::FindLessAsc (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String::FindLessAsc (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String::FindLessAsc (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
Description: Search the array of strings, which is sorted in ascending order for the last string, which is less than the specified string.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- string - pointer to string for searching
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value:
- An index of last string, which is less than the specified string.
- -1 if string was not found.
Note:These functions work only with sorted array of strings. To use them with unordered arrays they should be sorted first.
Searching for less or equal stringtop
Csize_t String_FindLessOrEqualAsc_char8 (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String_FindLessOrEqualAsc_char16 (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String_FindLessOrEqualAsc_char32 (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
C++size_t String::FindLessOrEqualAsc (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String::FindLessOrEqualAsc (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String::FindLessOrEqualAsc (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
Description: Search the array of strings, which is sorted in ascending order for the last string, which is less than or equal to the specified string.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- string - pointer to string for searching
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value:
- An index of last string, which is less than or equal to the specified string.
- -1 if string was not found.
Note:These functions work only with sorted array of strings. To use them with unordered arrays they should be sorted first.
Descending sort order
Searching for first equal stringtop
Csize_t String_FindFirstEqualDsc_char8 (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String_FindFirstEqualDsc_char16 (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String_FindFirstEqualDsc_char32 (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
C++size_t String::FindFirstEqualDsc (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String::FindFirstEqualDsc (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String::FindFirstEqualDsc (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
Description: Search the array of strings, which is sorted in descending order for specified string and return index of its first occurrence.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- string - pointer to string for searching
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value:
- An index of first occurrence of specified string.
- -1 if string was not found.
Note:These functions work only with sorted array of strings. To use them with unordered arrays they should be sorted first.
Searching for last equal stringtop
Csize_t String_FindLastEqualDsc_char8 (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String_FindLastEqualDsc_char16 (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String_FindLastEqualDsc_char32 (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
C++size_t String::FindLastEqualDsc (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String::FindLastEqualDsc (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String::FindLastEqualDsc (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
Description: Search the array of strings, which is sorted in descending order for specified string and return index of its last occurrence.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- string - pointer to string for searching
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value:
- An index of last occurrence of specified string.
- -1 if string was not found.
Note:These functions work only with sorted array of strings. To use them with unordered arrays they should be sorted first.
Searching for less stringtop
Csize_t String_FindLessDsc_char8 (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String_FindLessDsc_char16 (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String_FindLessDsc_char32 (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
C++size_t String::FindLessDsc (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String::FindLessDsc (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String::FindLessDsc (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
Description: Search the array of strings, which is sorted in descending order for the first string, which is less than the specified string.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- string - pointer to string for searching
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value:
- An index of first string, which is less than the specified string.
- -1 if string was not found.
Note:These functions work only with sorted array of strings. To use them with unordered arrays they should be sorted first.
Searching for less or equal stringtop
Csize_t String_FindLessOrEqualDsc_char8 (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String_FindLessOrEqualDsc_char16 (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String_FindLessOrEqualDsc_char32 (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
C++size_t String::FindLessOrEqualDsc (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String::FindLessOrEqualDsc (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String::FindLessOrEqualDsc (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
Description: Search the array of strings, which is sorted in descending order for the first string, which is less than or equal to the specified string.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- string - pointer to string for searching
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value:
- An index of first string, which is less than or equal to the specified string.
- -1 if string was not found.
Note:These functions work only with sorted array of strings. To use them with unordered arrays they should be sorted first.
Searching for greater stringtop
Csize_t String_FindGreatDsc_char8 (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String_FindGreatDsc_char16 (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String_FindGreatDsc_char32 (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
C++size_t String::FindGreatDsc (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String::FindGreatDsc (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String::FindGreatDsc (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
Description: Search the array of strings, which is sorted in descending order for the last string, which is greater than the specified string.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- string - pointer to string for searching
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value:
- An index of last string, which is greater than the specified string.
- -1 if string was not found.
Note:These functions work only with sorted array of strings. To use them with unordered arrays they should be sorted first.
Searching for greater or equal stringtop
Csize_t String_FindGreatOrEqualDsc_char8 (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String_FindGreatOrEqualDsc_char16 (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String_FindGreatOrEqualDsc_char32 (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
C++size_t String::FindGreatOrEqualDsc (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String::FindGreatOrEqualDsc (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String::FindGreatOrEqualDsc (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
Description: Search the array of strings, which is sorted in descending order for the last string, which is greater than or equal to the specified string.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- string - pointer to string for searching
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value:
- An index of last string, which is greater than or equal to the specified string.
- -1 if string was not found.
Note:These functions work only with sorted array of strings. To use them with unordered arrays they should be sorted first.
Counting
Next functions looks the strings for specified pattern and return how many times the pattern was met.
Symbol counting
Symbol counting functions check the string for target symbol or symbol set, and return a number of pattern matches.
Single symbol counting
Csize_t String_CountSymbol_char8 (const char8_t string[], char8_t symbol); size_t String_CountSymbol_char16 (const char16_t string[], char16_t symbol); size_t String_CountSymbol_char32 (const char32_t string[], char32_t symbol);
C++size_t String::CountSymbol (const char8_t string[], char8_t symbol); size_t String::CountSymbol (const char16_t string[], char16_t symbol); size_t String::CountSymbol (const char32_t string[], char32_t symbol);
Description: Search the string for specified symbol and return the count of matches were met.
Parameters:
- string - string for searching
- symbol - looking symbol
Return value:
- The number of pattern matches.
- -1 if the pattern is null symbol (0).
Symbols set counting
Csize_t String_CountSymbols_char8 (const char8_t string[], const char8_t symbols[]); size_t String_CountSymbols_char16 (const char16_t string[], const char16_t symbols[]); size_t String_CountSymbols_char32 (const char32_t string[], const char32_t symbols[]);
C++size_t String::CountSymbols (const char8_t string[], const char8_t symbols[]); size_t String::CountSymbols (const char16_t string[], const char16_t symbols[]); size_t String::CountSymbols (const char32_t string[], const char32_t symbols[]);
Description: Search the string for specified symbols set and return the count of matches were met.
Parameters:
- string - string for searching
- symbols - looking symbols set
Return value:
- The number of pattern matches.
- -1 if the symbols set is empty.
Note:Symbols set should have terminating null symbol (0). That is. It will look like regular string.
String counting
String counting algorithm checks the string array for required string and returns the count of pattern matches were met. Linear counting functions do linear scanning of string array, whereas binary counting functions work with sorted string arrays. Binary counting algorithms require log(N) operations to get a number of pattern matches.
Linear counting
Csize_t String_CountString_char8 (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String_CountString_char16 (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String_CountString_char32 (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
C++size_t String::CountString (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String::CountString (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String::CountString (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
Description: Search array of strings for specified string and return the count of pattern matches were met.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- string - pointer to string for searching
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value: The number of pattern matches.
Binary counting
Binary counting is very efficient way to count pattern matches in sorted array of strings. It takes log(N) compare operations to find a number of pattern matches and works only with sorted is ascending or descending order arrays. Use appropriate function for each sort order.
Ascending sort ordertop
Csize_t String_CountStringAsc_char8 (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String_CountStringAsc_char16 (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String_CountStringAsc_char32 (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
C++size_t String::CountStringAsc (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String::CountStringAsc (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String::CountStringAsc (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
Description: Search array of strings, which is sorted in ascending order, for specified string and return the count of pattern matches were met.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- string - pointer to string for searching
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value: The number of pattern matches.
Note:These functions work only with sorted array of strings. To use them with unordered arrays they should be sorted first.
Descending sort ordertop
Csize_t String_CountStringDsc_char8 (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String_CountStringDsc_char16 (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String_CountStringDsc_char32 (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
C++size_t String::CountStringDsc (const char8_t* array[], size_t size, const char8_t string[], CmpChar8 func); size_t String::CountStringDsc (const char16_t* array[], size_t size, const char16_t string[], CmpChar16 func); size_t String::CountStringDsc (const char32_t* array[], size_t size, const char32_t string[], CmpChar32 func);
Description: Search array of strings, which is sorted in desending order, for specified string and return the count of pattern matches were met.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- string - pointer to string for searching
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value: The number of pattern matches.
Note:These functions work only with sorted array of strings. To use them with unordered arrays they should be sorted first.
Replacing
These functions scan a string and replace each occurrence of pattern to specified value.
Symbol replacing
Cvoid String_ReplaceSymbol_char8 (char8_t string[], char8_t symbol, char8_t value); void String_ReplaceSymbol_char16 (char16_t string[], char16_t symbol, char16_t value); void String_ReplaceSymbol_char32 (char32_t string[], char32_t symbol, char32_t value);
C++void String::ReplaceSymbol (char8_t string[], char8_t symbol, char8_t value); void String::ReplaceSymbol (char16_t string[], char16_t symbol, char16_t value); void String::ReplaceSymbol (char32_t string[], char32_t symbol, char32_t value);
Description: Replace each symbol, which is equal to pattern with the new value. Functions ignore null symbol (0) as pattern value, and do not replace string terminating symbol in any case.
Parameters:
- string - string for searching
- symbol - looking symbol
- value - value to replace symbol
Return value: None.
String replacing
Cvoid String_ReplaceString_char8 (const char8_t* array[], size_t size, const char8_t string[], const char8_t value[], CmpChar8 func); void String_ReplaceString_char16 (const char16_t* array[], size_t size, const char16_t string[], const char16_t value[], CmpChar16 func); void String_ReplaceString_char32 (const char32_t* array[], size_t size, const char32_t string[], const char32_t value[], CmpChar32 func);
C++void String::ReplaceString (const char8_t* array[], size_t size, const char8_t string[], const char8_t value[], CmpChar8 func); void String::ReplaceString (const char16_t* array[], size_t size, const char16_t string[], const char16_t value[], CmpChar16 func); void String::ReplaceString (const char32_t* array[], size_t size, const char32_t string[], const char32_t value[], CmpChar32 func);
Description: Search array of strings and replace each occurrence of the target string with the new string.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- string - pointer to string for searching
- value - pointer to the new string which should replace target string
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value: None.
Order reversing
Cvoid String_Reverse_char8 (const char8_t* array[], size_t size); void String_Reverse_char16 (const char16_t* array[], size_t size); void String_Reverse_char32 (const char32_t* array[], size_t size);
C++void String::Reverse (const char8_t* array[], size_t size); void String::Reverse (const char16_t* array[], size_t size); void String::Reverse (const char32_t* array[], size_t size);
Description: Change strings order to reverse order and store them in the same array of strings.
Parameters:
- array - pointer to array of strings
- size - size of array (count of elements)
Return value: None.
Unique values
Csize_t String_Unique_char8 (const char8_t* unique[], const char8_t* array[], size_t size, CmpChar8 func); size_t String_Unique_char16 (const char16_t* unique[], const char16_t* array[], size_t size, CmpChar16 func); size_t String_Unique_char32 (const char32_t* unique[], const char32_t* array[], size_t size, CmpChar32 func);
C++size_t String::Unique (const char8_t* unique[], const char8_t* array[], size_t size, CmpChar8 func); size_t String::Unique (const char16_t* unique[], const char16_t* array[], size_t size, CmpChar16 func); size_t String::Unique (const char32_t* unique[], const char32_t* array[], size_t size, CmpChar32 func);
Description: Remove duplicate elements from sorted array of strings, leaving only unique values.
Parameters:
- unique - pointer to array of strings, where unique values will be stored. Should have the same size as source array.
- array - pointer to sorted array of strings
- size - size of array (count of elements)
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value: Count of unique elements.
Note:These functions work only with sorted arrays of strings, regardless of sort order. To use them with regular string arrays they should be sorted first.
Duplicate values
Csize_t String_Duplicates_char8 (const char8_t* unique[], size_t count[], const char8_t* array[], size_t size, CmpChar8 func); size_t String_Duplicates_char16 (const char16_t* unique[], size_t count[], const char16_t* array[], size_t size, CmpChar16 func); size_t String_Duplicates_char32 (const char32_t* unique[], size_t count[], const char32_t* array[], size_t size, CmpChar32 func);
C++size_t String::Duplicates (const char8_t* unique[], size_t count[], const char8_t* array[], size_t size, CmpChar8 func); size_t String::Duplicates (const char16_t* unique[], size_t count[], const char16_t* array[], size_t size, CmpChar16 func); size_t String::Duplicates (const char32_t* unique[], size_t count[], const char32_t* array[], size_t size, CmpChar32 func);
Description: Collect unique values from source array of strings and count how many times each unique value is met into array.
Parameters:
- unique - pointer to array of strings, where unique values will be stored. Should have the same size as source array.
- count - pointer to array, where stored count of duplicates for each unique value. Should have the same size as source array.
- array - pointer to sorted array of strings
- size - size of array (count of elements)
- func - pointer to a strings compare function, which is used for string matching. Compare function should follow this prototype.
Return value: Count of unique elements.
Note:These functions work only with sorted arrays of strings, regardless of sort order. To use them with regular string arrays they should be sorted first.
Insertion sort
Insertion sort is a simple sorting algorithm that builds the final sorted array one item at a time. It is much less efficient on large arrays than more advanced algorithms such as quicksort or merge sort, but it is stable. Stable sorting algorithms maintain the relative order of elements with equal keys.
String array sorting
These algorithms sort array of strings (array of pointers to real strings) in different sort orders, using string compare function, which is passed as a pointer to a function to sorting procedure. You may use your own compare function to sort string in required order. Compare function should follow this prototype.
Ascending sort order
Cvoid String_InsertSortAsc_char8 (const char8_t* array[], size_t size, CmpChar8 func); void String_InsertSortAsc_char16 (const char16_t* array[], size_t size, CmpChar16 func); void String_InsertSortAsc_char32 (const char32_t* array[], size_t size, CmpChar32 func);
C++void String::InsertSortAsc (const char8_t* array[], size_t size, CmpChar8 func); void String::InsertSortAsc (const char16_t* array[], size_t size, CmpChar16 func); void String::InsertSortAsc (const char32_t* array[], size_t size, CmpChar32 func);
Description: Sort array of strings in ascending sort order, using specified strings compare function.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- func - pointer to a strings compare function, which is used for strings arrangement. Compare function should follow this prototype.
Return value: None.
Tip:Insert sort preserve the relative order of elements with equal keys. And should be used for small arrays (32 elements or less) where this option is necessary.
Descending sort order
Cvoid String_InsertSortDsc_char8 (const char8_t* array[], size_t size, CmpChar8 func); void String_InsertSortDsc_char16 (const char16_t* array[], size_t size, CmpChar16 func); void String_InsertSortDsc_char32 (const char32_t* array[], size_t size, CmpChar32 func);
C++void String::InsertSortDsc (const char8_t* array[], size_t size, CmpChar8 func); void String::InsertSortDsc (const char16_t* array[], size_t size, CmpChar16 func); void String::InsertSortDsc (const char32_t* array[], size_t size, CmpChar32 func);
Description: Sort array of strings in descending sort order, using specified strings compare function.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- func - pointer to a strings compare function, which is used for strings arrangement. Compare function should follow this prototype.
Return value: None.
Tip:Insert sort preserve the relative order of elements with equal keys. And should be used for small arrays (32 elements or less) where this option is necessary.
Key array sorting
Key sorting algorithms do sorting of array of strings (array of pointers to real strings) in ascending or descending order and also do the same rearrangement for pointers to real data that are assigned to those keys. As a result, your complex data will be sorted by provided field, which values are stored in keys array. You may provide your own compare function that follows this prototype for custom sort order.
Ascending sort order
Cvoid String_InsertSortKeyAsc_char8 (const char8_t* key[], const void* ptr[], size_t size, CmpChar8 func); void String_InsertSortKeyAsc_char16 (const char16_t* key[], const void* ptr[], size_t size, CmpChar16 func); void String_InsertSortKeyAsc_char32 (const char32_t* key[], const void* ptr[], size_t size, CmpChar32 func);
C++void String::InsertSortKeyAsc (const char8_t* key[], const void* ptr[], size_t size, CmpChar8 func); void String::InsertSortKeyAsc (const char16_t* key[], const void* ptr[], size_t size, CmpChar16 func); void String::InsertSortKeyAsc (const char32_t* key[], const void* ptr[], size_t size, CmpChar32 func);
Description: Sort array of string keys (pointers to real strings) in ascending sort order, using specified strings compare function, and also rearrange array of pointers to data which are assigned to those keys.
Parameters:
- key - pointer to array of string keys
- ptr - pointer to array of pointers to data that are assigned to string keys
- size - count of strings into the keys array
- func - pointer to a strings compare function, which is used for strings arrangement. Compare function should follow this prototype.
Return value: None.
Tip:Insert sort preserve the relative order of elements with equal keys. And should be used for small arrays (32 elements or less) where this option is necessary.
Descending sort order
Cvoid String_InsertSortKeyDsc_char8 (const char8_t* key[], const void* ptr[], size_t size, CmpChar8 func); void String_InsertSortKeyDsc_char16 (const char16_t* key[], const void* ptr[], size_t size, CmpChar16 func); void String_InsertSortKeyDsc_char32 (const char32_t* key[], const void* ptr[], size_t size, CmpChar32 func);
C++void String::InsertSortKeyDsc (const char8_t* key[], const void* ptr[], size_t size, CmpChar8 func); void String::InsertSortKeyDsc (const char16_t* key[], const void* ptr[], size_t size, CmpChar16 func); void String::InsertSortKeyDsc (const char32_t* key[], const void* ptr[], size_t size, CmpChar32 func);
Description: Sort array of string keys (pointers to real strings) in descending sort order, using specified strings compare function, and also rearrange array of pointers to data which are assigned to those keys.
Parameters:
- key - pointer to array of string keys
- ptr - pointer to array of pointers to data that are assigned to string keys
- size - count of strings into the keys array
- func - pointer to a strings compare function, which is used for strings arrangement. Compare function should follow this prototype.
Return value: None.
Tip:Insert sort preserve the relative order of elements with equal keys. And should be used for small arrays (32 elements or less) where this option is necessary.
Quick sort
Quick sort is a sorting algorithm developed by Tony Hoare that, on average, makes N*log(N) comparisons to sort N items. In the worst case, it makes O(N2) comparisons, though this behavior is rare. Quick sort sequential and localized memory references work well with a cache. This algorithm is implemented as an in-place partitioning algorithm, and doesn't require any additional place for sorting.
String array sorting
These algorithms sort array of strings (array of pointers to real strings) in different sort orders, using string compare function, which is passed as a pointer to a function to sorting procedure. You may use your own compare function to sort string in required order. Compare function should follow this prototype.
Ascending sort order
Cvoid String_QuickSortAsc_char8 (const char8_t* array[], size_t size, CmpChar8 func); void String_QuickSortAsc_char16 (const char16_t* array[], size_t size, CmpChar16 func); void String_QuickSortAsc_char32 (const char32_t* array[], size_t size, CmpChar32 func);
C++void String::QuickSortAsc (const char8_t* array[], size_t size, CmpChar8 func); void String::QuickSortAsc (const char16_t* array[], size_t size, CmpChar16 func); void String::QuickSortAsc (const char32_t* array[], size_t size, CmpChar32 func);
Description: Sort array of strings in ascending sort order, using specified strings compare function.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- func - pointer to a strings compare function, which is used for strings arrangement. Compare function should follow this prototype.
Return value: None.
Descending sort order
Cvoid String_QuickSortDsc_char8 (const char8_t* array[], size_t size, CmpChar8 func); void String_QuickSortDsc_char16 (const char16_t* array[], size_t size, CmpChar16 func); void String_QuickSortDsc_char32 (const char32_t* array[], size_t size, CmpChar32 func);
C++void String::QuickSortDsc (const char8_t* array[], size_t size, CmpChar8 func); void String::QuickSortDsc (const char16_t* array[], size_t size, CmpChar16 func); void String::QuickSortDsc (const char32_t* array[], size_t size, CmpChar32 func);
Description: Sort array of strings in descending sort order, using specified strings compare function.
Parameters:
- array - pointer to array of strings
- size - count of strings into the array
- func - pointer to a strings compare function, which is used for strings arrangement. Compare function should follow this prototype.
Return value: None.
Key array sorting
Key sorting algorithms do sorting of array of strings (array of pointers to real strings) in ascending or descending order and also do the same rearrangement for pointers to real data that are assigned to those keys. As a result, your complex data will be sorted by provided field, which values are stored in keys array. You may provide your own compare function that follows this prototype for custom sort order.
Ascending sort order
Cvoid String_QuickSortKeyAsc_char8 (const char8_t* key[], const void* ptr[], size_t size, CmpChar8 func); void String_QuickSortKeyAsc_char16 (const char16_t* key[], const void* ptr[], size_t size, CmpChar16 func); void String_QuickSortKeyAsc_char32 (const char32_t* key[], const void* ptr[], size_t size, CmpChar32 func);
C++void String::QuickSortKeyAsc (const char8_t* key[], const void* ptr[], size_t size, CmpChar8 func); void String::QuickSortKeyAsc (const char16_t* key[], const void* ptr[], size_t size, CmpChar16 func); void String::QuickSortKeyAsc (const char32_t* key[], const void* ptr[], size_t size, CmpChar32 func);
Description: Sort array of string keys (pointers to real strings) in ascending sort order, using specified strings compare function, and also rearrange array of pointers to data which are assigned to those keys.
Parameters:
- key - pointer to array of string keys
- ptr - pointer to array of pointers to data that are assigned to string keys
- size - count of strings into the keys array
- func - pointer to a strings compare function, which is used for strings arrangement. Compare function should follow this prototype.
Return value: None.
Descending sort order
Cvoid String_QuickSortKeyDsc_char8 (const char8_t* key[], const void* ptr[], size_t size, CmpChar8 func); void String_QuickSortKeyDsc_char16 (const char16_t* key[], const void* ptr[], size_t size, CmpChar16 func); void String_QuickSortKeyDsc_char32 (const char32_t* key[], const void* ptr[], size_t size, CmpChar32 func);
C++void String::QuickSortKeyDsc (const char8_t* key[], const void* ptr[], size_t size, CmpChar8 func); void String::QuickSortKeyDsc (const char16_t* key[], const void* ptr[], size_t size, CmpChar16 func); void String::QuickSortKeyDsc (const char32_t* key[], const void* ptr[], size_t size, CmpChar32 func);
Description: Sort array of string keys (pointers to real strings) in descending sort order, using specified strings compare function, and also rearrange array of pointers to data which are assigned to those keys.
Parameters:
- key - pointer to array of string keys
- ptr - pointer to array of pointers to data that are assigned to string keys
- size - count of strings into the keys array
- func - pointer to a strings compare function, which is used for strings arrangement. Compare function should follow this prototype.
Return value: None.
Merge sort
Merge sort is an N*log(N) comparison-based sorting algorithm. It produce a stable sort, which means that the implementation preserves the input order of equal elements in the sorted output.
String array sorting
These algorithms sort array of strings (array of pointers to real strings) in different sort orders, using string compare function, which is passed as a pointer to a function to sorting procedure. You may use your own compare function to sort string in required order. Compare function should follow this prototype.
Ascending sort order
Cvoid String_MergeSortAsc_char8 (const char8_t* array[], const char8_t* temp[], size_t size, CmpChar8 func); void String_MergeSortAsc_char16 (const char16_t* array[], const char16_t* temp[], size_t size, CmpChar16 func); void String_MergeSortAsc_char32 (const char32_t* array[], const char32_t* temp[], size_t size, CmpChar32 func);
C++void String::MergeSortAsc (const char8_t* array[], const char8_t* temp[], size_t size, CmpChar8 func); void String::MergeSortAsc (const char16_t* array[], const char16_t* temp[], size_t size, CmpChar16 func); void String::MergeSortAsc (const char32_t* array[], const char32_t* temp[], size_t size, CmpChar32 func);
Description: Sort array of strings in ascending sort order, using specified strings compare function.
Parameters:
- array - pointer to array of strings
- temp - pointer to array of strings, which will be used as temporary buffer during the sorting process
- size - count of strings into the array
- func - pointer to a strings compare function, which is used for strings arrangement. Compare function should follow this prototype.
Return value: None.
Tip:Merge sort preserve the relative order of elements with equal keys. And should be used for big arrays (more than 32 elements) where this option is necessary.
Descending sort order
Cvoid String_MergeSortDsc_char8 (const char8_t* array[], const char8_t* temp[], size_t size, CmpChar8 func); void String_MergeSortDsc_char16 (const char16_t* array[], const char16_t* temp[], size_t size, CmpChar16 func); void String_MergeSortDsc_char32 (const char32_t* array[], const char32_t* temp[], size_t size, CmpChar32 func);
C++void String::MergeSortDsc (const char8_t* array[], const char8_t* temp[], size_t size, CmpChar8 func); void String::MergeSortDsc (const char16_t* array[], const char16_t* temp[], size_t size, CmpChar16 func); void String::MergeSortDsc (const char32_t* array[], const char32_t* temp[], size_t size, CmpChar32 func);
Description: Sort array of strings in descending sort order, using specified strings compare function.
Parameters:
- array - pointer to array of strings
- temp - pointer to array of strings, which will be used as temporary buffer during the sorting process
- size - count of strings into the array
- func - pointer to a strings compare function, which is used for strings arrangement. Compare function should follow this prototype.
Return value: None.
Tip:Merge sort preserve the relative order of elements with equal keys. And should be used for big arrays (more than 32 elements) where this option is necessary.
Key array sorting
Key sorting algorithms do sorting of array of strings (array of pointers to real strings) in ascending or descending order and also do the same rearrangement for pointers to real data that are assigned to those keys. As a result, your complex data will be sorted by provided field, which values are stored in keys array. You may provide your own compare function that follows this prototype for custom sort order.
Ascending sort order
Cvoid String_MergeSortKeyAsc_char8 (const char8_t* key[], const void* ptr[], const char8_t* tkey[], const void* tptr[], size_t size, CmpChar8 func); void String_MergeSortKeyAsc_char16 (const char16_t* key[], const void* ptr[], const char16_t* tkey[], const void* tptr[], size_t size, CmpChar16 func); void String_MergeSortKeyAsc_char32 (const char32_t* key[], const void* ptr[], const char32_t* tkey[], const void* tptr[], size_t size, CmpChar32 func);
C++void String::MergeSortKeyAsc (const char8_t* key[], const void* ptr[], const char8_t* tkey[], const void* tptr[], size_t size, CmpChar8 func); void String::MergeSortKeyAsc (const char16_t* key[], const void* ptr[], const char16_t* tkey[], const void* tptr[], size_t size, CmpChar16 func); void String::MergeSortKeyAsc (const char32_t* key[], const void* ptr[], const char32_t* tkey[], const void* tptr[], size_t size, CmpChar32 func);
Description: Sort array of string keys (pointers to real strings) in ascending sort order, using specified strings compare function, and also rearrange array of pointers to data which are assigned to those keys.
Parameters:
- key - pointer to array of string keys
- ptr - pointer to array of pointers to data that are assigned to string keys
- tkey - pointer to array of strings, which will be used as temporary buffer during the sorting process
- tptr - pointer to array of pointers to data that are assigned to string keys, which will be used as temporary buffer during the sorting process
- size - count of strings into the keys array
- func - pointer to a strings compare function, which is used for strings arrangement. Compare function should follow this prototype.
Return value: None.
Tip:Merge sort preserve the relative order of elements with equal keys. And should be used for big arrays (more than 32 elements) where this option is necessary.
Descending sort order
Cvoid String_MergeSortKeyDsc_char8 (const char8_t* key[], const void* ptr[], const char8_t* tkey[], const void* tptr[], size_t size, CmpChar8 func); void String_MergeSortKeyDsc_char16 (const char16_t* key[], const void* ptr[], const char16_t* tkey[], const void* tptr[], size_t size, CmpChar16 func); void String_MergeSortKeyDsc_char32 (const char32_t* key[], const void* ptr[], const char32_t* tkey[], const void* tptr[], size_t size, CmpChar32 func);
C++void String::MergeSortKeyDsc (const char8_t* key[], const void* ptr[], const char8_t* tkey[], const void* tptr[], size_t size, CmpChar8 func); void String::MergeSortKeyDsc (const char16_t* key[], const void* ptr[], const char16_t* tkey[], const void* tptr[], size_t size, CmpChar16 func); void String::MergeSortKeyDsc (const char32_t* key[], const void* ptr[], const char32_t* tkey[], const void* tptr[], size_t size, CmpChar32 func);
Description: Sort array of string keys (pointers to real strings) in descending sort order, using specified strings compare function, and also rearrange array of pointers to data which are assigned to those keys.
Parameters:
- key - pointer to array of string keys
- ptr - pointer to array of pointers to data that are assigned to string keys
- tkey - pointer to array of strings, which will be used as temporary buffer during the sorting process
- tptr - pointer to array of pointers to data that are assigned to string keys, which will be used as temporary buffer during the sorting process
- size - count of strings into the keys array
- func - pointer to a strings compare function, which is used for strings arrangement. Compare function should follow this prototype.
Return value: None.
Tip:Merge sort preserve the relative order of elements with equal keys. And should be used for big arrays (more than 32 elements) where this option is necessary.
Merging of sorted strings
Some text processing algorithms need to merge sorted strings, are taken from different places, into the new sorted string array. These functions implement 2-way merging of arrays of strings into one big array. Arrays can be sorted in both orders: ascending or descending. For different sort orders, you have to use appropriate functions. Target array, where merged data will be placed, should have at least size1 + size2 elements to hold data from both arrays.
String array merging
Following functions merge sorted string arrays into one big array of strings, which size is equal to sum of sizes of source arrays. To prevent buffer overflow, you have to be sure that target array has size which is not less than size1 + size2 elements.
Ascending sort order
Cvoid String_MergeAsc_char8 (const char8_t* target[], const char8_t* src1[], size_t size1, const char8_t* src2[], size_t size2, CmpChar8 func); void String_MergeAsc_char16 (const char16_t* target[], const char16_t* src1[], size_t size1, const char16_t* src2[], size_t size2, CmpChar16 func); void String_MergeAsc_char32 (const char32_t* target[], const char32_t* src1[], size_t size1, const char32_t* src2[], size_t size2, CmpChar32 func);
C++void String::MergeAsc (const char8_t* target[], const char8_t* src1[], size_t size1, const char8_t* src2[], size_t size2, CmpChar8 func); void String::MergeAsc (const char16_t* target[], const char16_t* src1[], size_t size1, const char16_t* src2[], size_t size2, CmpChar16 func); void String::MergeAsc (const char32_t* target[], const char32_t* src1[], size_t size1, const char32_t* src2[], size_t size2, CmpChar32 func);
Description: Merge two string arrays, sorted in ascending order, into one target array which has at least size1 + size2 elements. Source arrays stay unchanged.
Parameters:
- target - pointer to target array, where data from merged arrays will be placed
- src1 - pointer to first source array
- size1 - size of first array (count of strings)
- src2 - pointer to second source array
- size2 - size of second array (count of strings)
- func - pointer to a strings compare function, which is used for strings arrangement. Compare function should follow this prototype.
Return value: None.
Note:These functions work only with sorted in correct order string arrays. If you try to merge unsorted arrays, then result is undefined.
Descending sort order
Cvoid String_MergeDsc_char8 (const char8_t* target[], const char8_t* src1[], size_t size1, const char8_t* src2[], size_t size2, CmpChar8 func); void String_MergeDsc_char16 (const char16_t* target[], const char16_t* src1[], size_t size1, const char16_t* src2[], size_t size2, CmpChar16 func); void String_MergeDsc_char32 (const char32_t* target[], const char32_t* src1[], size_t size1, const char32_t* src2[], size_t size2, CmpChar32 func);
C++void String::MergeDsc (const char8_t* target[], const char8_t* src1[], size_t size1, const char8_t* src2[], size_t size2, CmpChar8 func); void String::MergeDsc (const char16_t* target[], const char16_t* src1[], size_t size1, const char16_t* src2[], size_t size2, CmpChar16 func); void String::MergeDsc (const char32_t* target[], const char32_t* src1[], size_t size1, const char32_t* src2[], size_t size2, CmpChar32 func);
Description: Merge two string arrays, sorted in descending order, into one target array which has at least size1 + size2 elements. Source arrays stay unchanged.
Parameters:
- target - pointer to target array, where data from merged arrays will be placed
- src1 - pointer to first source array
- size1 - size of first array (count of strings)
- src2 - pointer to second source array
- size2 - size of second array (count of strings)
- func - pointer to a strings compare function, which is used for strings arrangement. Compare function should follow this prototype.
Return value: None.
Note:These functions work only with sorted in correct order string arrays. If you try to merge unsorted arrays, then result is undefined.
Key array merging
Key merging functions merge arrays of strings which hold keys, and also merge arrays of pointers which hold assigned data for selected keys. As the result, you have both keys and pointers to data, joined from different string array into target arrays, one for each data type. Target arrays should have at least size1 + size2 elements to hold data from merged arrays.
Ascending sort order
Cvoid String_MergeKeyAsc_char8 (const char8_t* tkey[], const void* tptr[], const char8_t* skey1[], const void* sptr1[], size_t size1, const char8_t* skey2[], const void* sptr2[], size_t size2, CmpChar8 func); void String_MergeKeyAsc_char16 (const char16_t* tkey[], const void* tptr[], const char16_t* skey1[], const void* sptr1[], size_t size1, const char16_t* skey2[], const void* sptr2[], size_t size2, CmpChar16 func); void String_MergeKeyAsc_char32 (const char32_t* tkey[], const void* tptr[], const char32_t* skey1[], const void* sptr1[], size_t size1, const char32_t* skey2[], const void* sptr2[], size_t size2, CmpChar32 func);
C++void String::MergeKeyAsc (const char8_t* tkey[], const void* tptr[], const char8_t* skey1[], const void* sptr1[], size_t size1, const char8_t* skey2[], const void* sptr2[], size_t size2, CmpChar8 func); void String::MergeKeyAsc (const char16_t* tkey[], const void* tptr[], const char16_t* skey1[], const void* sptr1[], size_t size1, const char16_t* skey2[], const void* sptr2[], size_t size2, CmpChar16 func); void String::MergeKeyAsc (const char32_t* tkey[], const void* tptr[], const char32_t* skey1[], const void* sptr1[], size_t size1, const char32_t* skey2[], const void* sptr2[], size_t size2, CmpChar32 func);
Description: Merge arrays of strings, sorted in ascending order, and arrays of pointers which hold assigned data for selected strings into target arrays which have at least size1 + size2 elements. Source arrays stay unchanged.
Parameters:
- tkey - pointer to target array of strings, where strings from merged arrays will be placed
- tptr - pointer to target array of pointers, where pointers from merged arrays will be placed
- skey1 - pointer to first source array of strings
- sptr1 - pointer to first source array of pointers
- size1 - size of first arrays of strings and pointers (count of elements)
- skey2 - pointer to second source array of strings
- sptr2 - pointer to second source array of pointers
- size2 - size of second arrays of strings and pointers (count of elements)
- func - pointer to a strings compare function, which is used for strings arrangement. Compare function should follow this prototype.
Return value: None.
Note:These functions work only with sorted in correct order string arrays. If you try to merge unsorted arrays, then result is undefined.
Descending sort order
Cvoid String_MergeKeyDsc_char8 (const char8_t* tkey[], const void* tptr[], const char8_t* skey1[], const void* sptr1[], size_t size1, const char8_t* skey2[], const void* sptr2[], size_t size2, CmpChar8 func); void String_MergeKeyDsc_char16 (const char16_t* tkey[], const void* tptr[], const char16_t* skey1[], const void* sptr1[], size_t size1, const char16_t* skey2[], const void* sptr2[], size_t size2, CmpChar16 func); void String_MergeKeyDsc_char32 (const char32_t* tkey[], const void* tptr[], const char32_t* skey1[], const void* sptr1[], size_t size1, const char32_t* skey2[], const void* sptr2[], size_t size2, CmpChar32 func);
C++void String::MergeKeyDsc (const char8_t* tkey[], const void* tptr[], const char8_t* skey1[], const void* sptr1[], size_t size1, const char8_t* skey2[], const void* sptr2[], size_t size2, CmpChar8 func); void String::MergeKeyDsc (const char16_t* tkey[], const void* tptr[], const char16_t* skey1[], const void* sptr1[], size_t size1, const char16_t* skey2[], const void* sptr2[], size_t size2, CmpChar16 func); void String::MergeKeyDsc (const char32_t* tkey[], const void* tptr[], const char32_t* skey1[], const void* sptr1[], size_t size1, const char32_t* skey2[], const void* sptr2[], size_t size2, CmpChar32 func);
Description: Merge arrays of strings, sorted in descending order, and arrays of pointers which hold assigned data for selected strings into target arrays which have at least size1 + size2 elements. Source arrays stay unchanged.
Parameters:
- tkey - pointer to target array of strings, where strings from merged arrays will be placed
- tptr - pointer to target array of pointers, where pointers from merged arrays will be placed
- skey1 - pointer to first source array of strings
- sptr1 - pointer to first source array of pointers
- size1 - size of first arrays of strings and pointers (count of elements)
- skey2 - pointer to second source array of strings
- sptr2 - pointer to second source array of pointers
- size2 - size of second arrays of strings and pointers (count of elements)
- func - pointer to a strings compare function, which is used for strings arrangement. Compare function should follow this prototype.
Return value: None.
Note:These functions work only with sorted in correct order string arrays. If you try to merge unsorted arrays, then result is undefined.
Checks
Check functions revise arrays of strings for special conditions and return index of first element where condition was met.
Check for duplicate values
Csize_t String_CheckDup_char8 (const char8_t* array[], size_t size, CmpChar8 func); size_t String_CheckDup_char16 (const char16_t* array[], size_t size, CmpChar16 func); size_t String_CheckDup_char32 (const char32_t* array[], size_t size, CmpChar32 func);
C++size_t String::CheckDup (const char8_t* array[], size_t size, CmpChar8 func); size_t String::CheckDup (const char16_t* array[], size_t size, CmpChar16 func); size_t String::CheckDup (const char32_t* array[], size_t size, CmpChar32 func);
Description: Check sorted array of strings for duplicate values and return index of first duplicate value if found.
Parameters:
- array - pointer to array of strings
- size - size of array (number of strings)
- func - pointer to a strings compare function. Compare function should follow this prototype.
Return value:
- An index of first occurrence of duplicate string.
- -1 if array has no duplicates.
Note:These functions work only with sorted string arrays, regardless of sort order. To use them with regular arrays of strings they should be sorted first.
Check for sort order
Following functions check arrays for required sort order, and return an index of the first element which did not pass the sort condition.
Check for ascending sort order
Csize_t String_CheckSortAsc_char8 (const char8_t* array[], size_t size, CmpChar8 func); size_t String_CheckSortAsc_char16 (const char16_t* array[], size_t size, CmpChar16 func); size_t String_CheckSortAsc_char32 (const char32_t* array[], size_t size, CmpChar32 func);
C++size_t String::CheckSortAsc (const char8_t* array[], size_t size, CmpChar8 func); size_t String::CheckSortAsc (const char16_t* array[], size_t size, CmpChar16 func); size_t String::CheckSortAsc (const char32_t* array[], size_t size, CmpChar32 func);
Description: Check if array of strings is sorted in ascending sort order, and return index of first element, which position is not conform with the sort order.
Parameters:
- array - pointer to array of strings
- size - size of array (number of strings)
- func - pointer to a strings compare function. Compare function should follow this prototype.
Return value:
- An index of first element, which position does not conform with the array sort order.
- -1 if array is empty, or properly sorted.
Check for descending sort order
Csize_t String_CheckSortDsc_char8 (const char8_t* array[], size_t size, CmpChar8 func); size_t String_CheckSortDsc_char16 (const char16_t* array[], size_t size, CmpChar16 func); size_t String_CheckSortDsc_char32 (const char32_t* array[], size_t size, CmpChar32 func);
C++size_t String::CheckSortDsc (const char8_t* array[], size_t size, CmpChar8 func); size_t String::CheckSortDsc (const char16_t* array[], size_t size, CmpChar16 func); size_t String::CheckSortDsc (const char32_t* array[], size_t size, CmpChar32 func);
Description: Check if array of strings is sorted in descending sort order, and return index of first element, which position is not conform with the sort order.
Parameters:
- array - pointer to array of strings
- size - size of array (number of strings)
- func - pointer to a strings compare function. Compare function should follow this prototype.
Return value:
- An index of first element, which position does not conform with the array sort order.
- -1 if array is empty, or properly sorted.
String hashing
These functions compute hash sum for all characters in the string and return 32-bit and 64-bit hash value. The hash functions (based on golden ratio) are very smooth and can generate very good uniform distribution, even for tiny range of keys. These functions are not designed for data verification (can generate many collisions), but for hash tables, where uniform distribution can significantly improve hash table balancing.
32-bit hash functions
Cuint32_t String_Hash32_char8 (const char8_t string[]); uint32_t String_Hash32_char16 (const char16_t string[]); uint32_t String_Hash32_char32 (const char32_t string[]);
C++uint32_t String::Hash32 (const char8_t string[]); uint32_t String::Hash32 (const char16_t string[]); uint32_t String::Hash32 (const char32_t string[]);
Description: Compute 32-bit hash value for the string, using smooth hash function, based on golden ratio.
Parameters:
- string - pointer to a string
Return value: 32-bit hash value.
64-bit hash functions
Cuint64_t String_Hash64_char8 (const char8_t string[]); uint64_t String_Hash64_char16 (const char16_t string[]); uint64_t String_Hash64_char32 (const char32_t string[]);
C++uint64_t String::Hash64 (const char8_t string[]); uint64_t String::Hash64 (const char16_t string[]); uint64_t String::Hash64 (const char32_t string[]);
Description: Compute 64-bit hash value for the string, using smooth hash function, based on golden ratio.
Parameters:
- string - pointer to a string
Return value: 64-bit hash value.