![]() |
Oyranos
git-devel
Oyranos is a full featured Color Management System
|
String Handling. More...
![]() |
Functions | |
void | oyjlStr_SetCharAt (oyjl_str str, char c, int pos) |
set the char at position More... | |
char ** | oyjlStringSplit (const char *text, const char delimiter, int *count, void *(*alloc)(size_t)) |
convert a string into list More... | |
char ** | oyjlStringSplit2 (const char *text, const char *delimiter, const char *(splitFunc)(const char *text, const char *delimiter, int *length), int *count, int **index, void *(*alloc)(size_t)) |
convert a string into list More... | |
char * | oyjlStringCopy (const char *string, void *(*alloc)(size_t)) |
duplicate a string with custom allocator More... | |
int | oyjlStringAdd (char **string, void *(*alloc)(size_t size), void(*deAlloc)(void *data), const char *format,...) |
sprintf with de-/allocator More... | |
char * | oyjlStringAppendN (const char *text, const char *append, int append_len, void *(*alloc)(size_t size)) |
append to the string end More... | |
void | oyjlStringAddN (char **text, const char *append, int append_len, void *(*alloc)(size_t), void(*deAlloc)(void *)) |
append to the string end More... | |
int | oyjlStringReplace (char **text, const char *search, const char *replacement, void *(*alloc)(size_t), void(*deAlloc)(void *)) |
substitute pattern in a string More... | |
char ** | oyjlStringListCatList (const char **list, int n_alt, const char **append, int n_app, int *count, void *(*alloc)(size_t)) |
append a string list to an other string list More... | |
void | oyjlStringListRelease (char ***l, int size, void(*deAlloc)(void *)) |
free a string list More... | |
void | oyjlStringListPush (char ***list, int *n, const char *string, void *(*alloc)(size_t), void(*deAlloc)(void *)) |
append a string to a string list More... | |
int | oyjlStringListAdd (char ***list, int *n, void *(*alloc)(size_t), void(*deAlloc)(void *), const char *format,...) |
add a variable string to a string list More... | |
void | oyjlStringListFreeDoubles (char **list, int *list_n, void(*deAlloc)(void *)) |
filter doubles out More... | |
void | oyjlStringListAddList (char ***list, int *n, const char **append, int n_app, void *(*alloc)(size_t), void(*deAlloc)(void *)) |
append a string list to an other and handle memory More... | |
int | oyjlStringToLong (const char *text, long *value, const char **end) |
int | oyjlStringToDouble (const char *text, double *value, const char **end, int flags) |
text to double conversion More... | |
int | oyjlStringsToDoubles (const char *text, const char *delimiter, int *count, void *(*alloc)(size_t), double **value) |
text to double list More... | |
char * | oyjlRegExpFind (char *text, const char *regex, int *length) |
search for pattern More... | |
int | oyjlRegExpReplace (char **text, const char *regex, const char *replacement) |
replace pattern More... | |
char * | oyjlRegExpEscape (const char *text) |
use a pattern literaly More... | |
int | oyjlStringStartsWith (const char *text, const char *pattern) |
simple and fast test More... | |
int | oyjlStringSplitUTF8 (const char *text, char ***mbchars, void *(*alloc)(size_t)) |
split letters of a UTF-8 string More... | |
oyjl_str | oyjlStr_New (size_t length, void *(*alloc)(size_t), void(*deAlloc)(void *)) |
allocate string object More... | |
oyjl_str | oyjlStr_NewFrom (char **text, size_t length, void *(*alloc)(size_t), void(*deAlloc)(void *)) |
allocate string object from chars More... | |
int | oyjlStr_AppendN (oyjl_str string, const char *append, int append_len) |
fast append to the string end More... | |
int | oyjlStr_Push (oyjl_str string, const char *text) |
fast append to the string end More... | |
int | oyjlStr_Add (oyjl_str string, const char *format,...) |
sprintf for oyjl_str More... | |
int | oyjlStr_Replace (oyjl_str text, const char *search, const char *replacement, void(*modifyReplacement)(const char *text, const char *start, const char *end, const char *search, const char **replace, int *replace_len, void *user_data), void *user_data) |
substitute pattern in a string More... | |
char * | oyjlStr_Pull (oyjl_str str) |
move the wrapped char array out of the object More... | |
void | oyjlStr_Clear (oyjl_str string) |
clear text in a string object More... | |
void | oyjlStr_Release (oyjl_str *string_ptr) |
release a string object More... | |
const char * | oyjlStr (oyjl_str string) |
read only the wrapped char array More... | |
const char * | oyjlTermColorToPlain (const char *text, int flags) |
remove term color marks More... | |
String Handling.
A convinient set of string API's is available in the oyjlStringXXX family. Those API's handle plain string arrays. oyjlStringAdd() uses variable args to format and append to a existing string. oyjlStringListXXX API's handle plain arrays of strings.
The oyjl_str based oyStrXXX API's use a more careful memory management and thus perform way faster on larger memory arrays as they need fewer allocations and copies. oyjlStr_New() allocates a new object, or oyjlStr_NewFrom() wrappes a existing string array into a new object. oyjlStr() lets you see the contained char array. oyjlStr_Push() performs fast concatenation. oyjlStr_Replace() uses the object advantages. oyjlStr_Pull() directly takes the char array out of control of the oyjl_str object and oyjlStr_Release() frees the object and all memory.
char * oyjlRegExpEscape | ( | const char * | text | ) |
use a pattern literaly
This function detects OYJL_HAVE_REGEX_H macro internally to fit the oyjlRegExpMatch() implementation.
It is escaping:
.$*+?()[{|
text | string to escape |
char * oyjlRegExpFind | ( | char * | text, |
const char * | regex, | ||
int * | length | ||
) |
search for pattern
This function behaves like strstr(), but extends to regular expressions. Test for OYJL_HAVE_REGEX_H macro to see if regexec() API is used. Otherwise only C strstr() API will be called.
text | string to search in |
regex | regular expression to try with text |
length | length of returned value |
int oyjlRegExpReplace | ( | char ** | text, |
const char * | regex, | ||
const char * | replacement | ||
) |
replace pattern
Test for OYJL_HAVE_REGEX_H macro to see if regexec() API is used.
text | string to search in |
regex | regular expression to try with text |
replacement | substitute all matches of regex in text; it may contain up to two occurences of s regex matching placeholders, e.g. "%s=%s" |
Referenced by oyjlPrintSub(), oyjlPrintSubProfiling(), and oyjlTermColorToPlain().
const char* oyjlStr | ( | oyjl_str | string | ) |
read only the wrapped char array
The returned array might become invalid with each further call to the string object.
Referenced by oyjlStr_Replace().
int oyjlStr_Add | ( | oyjl_str | string, |
const char * | format, | ||
... | |||
) |
sprintf for oyjl_str
The function adds memory management over standard sprintf().
[in] | string | source string |
[in] | format | printf style format string |
[in] | ... | argument list for format |
References OYJL_CREATE_VA_STRING, and oyjlStr_Push().
Referenced by oyjlTreeToCsv().
int oyjlStr_AppendN | ( | oyjl_str | string, |
const char * | append, | ||
int | append_len | ||
) |
fast append to the string end
[in] | string | string object |
[in] | append | to be added text to string |
[in] | append_len | length of append |
Referenced by oyjlStr_Push(), oyjlStr_Replace(), and oyjlTreeToCsv().
void oyjlStr_Clear | ( | oyjl_str | string | ) |
clear text in a string object
Referenced by oyjlStr_Release().
oyjl_str oyjlStr_New | ( | size_t | length, |
void *(*)(size_t) | alloc, | ||
void(*)(void *) | deAlloc | ||
) |
allocate string object
[in] | length | the preallocation length |
[in] | alloc | custom allocator; optional, default is malloc |
[in] | deAlloc | custom deallocator; optional, default is free |
Referenced by oyjlStr_Replace(), oyjlTermColorToHtml(), oyjlTreeToCsv(), oyjlTreeToJson(), and oyjlUi_s::oyjlUiJsonToCode().
oyjl_str oyjlStr_NewFrom | ( | char ** | text, |
size_t | length, | ||
void *(*)(size_t) | alloc, | ||
void(*)(void *) | deAlloc | ||
) |
allocate string object from chars
Use this function to avoid allocation of already in memory char array. Be careful, that the memory alloc and deAlloc args match the text storage.
[in] | text | text to pull into new object |
[in] | length | the preallocation size of text or zero if unknown |
[in] | alloc | custom allocator; optional, default is malloc |
[in] | deAlloc | custom deallocator; optional, default is free |
Referenced by oyjlStringReplace().
char* oyjlStr_Pull | ( | oyjl_str | str | ) |
move the wrapped char array out of the object
This function might be usefull if a plain string copy is too expensive and the object memory allocation can be further handled for the returned char pointer. After the operation the objects internal char array will be reset to zero length.
[in,out] | str | the object, which will be reseted |
Referenced by oyjlStringReplace().
int oyjlStr_Push | ( | oyjl_str | string, |
const char * | text | ||
) |
fast append to the string end
[in] | string | string object |
[in] | text | to be added text to string |
References oyjlStr_AppendN().
Referenced by oyjlStr_Add(), oyjlStr_Replace(), and oyjlTermColorToHtml().
void oyjlStr_Release | ( | oyjl_str * | string_ptr | ) |
release a string object
All references from previous oyjlStr() calls will be void.
References oyjlStr_Clear().
Referenced by oyjlStringReplace().
int oyjlStr_Replace | ( | oyjl_str | text, |
const char * | search, | ||
const char * | replacement, | ||
void(*)(const char *text, const char *start, const char *end, const char *search, const char **replace, int *replace_len, void *user_data) | modifyReplacement, | ||
void * | user_data | ||
) |
substitute pattern in a string
[in,out] | text | source string for in place manipulation |
[in] | search | pattern to be tested in text |
[in] | replacement | string to be put in place of search sub string |
[in] | modifyReplacement | hook to dynamically modify the replacement text; optional
|
[in,out] | user_data | optional user data for modifyReplacement |
References oyjlStr(), oyjlStr_AppendN(), oyjlStr_New(), and oyjlStr_Push().
Referenced by oyjlStringReplace(), and oyjlTermColorToHtml().
void oyjlStr_SetCharAt | ( | oyjl_str | str, |
char | c, | ||
int | pos | ||
) |
set the char at position
[in,out] | str | the object, which will be modified |
int oyjlStringAdd | ( | char ** | string, |
void *(*)(size_t size) | alloc, | ||
void(*)(void *data) | deAlloc, | ||
const char * | format, | ||
... | |||
) |
sprintf with de-/allocator
The function adds memory management over standard sprintf().
[in] | string | source string |
[in] | alloc | custom allocator; optional, default is malloc |
[in] | deAlloc | custom deallocator matching alloc; optional, default is free |
[in] | format | printf style format string |
[in] | ... | argument list for format |
References OYJL_CREATE_VA_STRING.
Referenced by oyjlTreeGetNewValueFromArray(), oyjlTreeToXml(), oyjlTreeToYaml(), oyjlValueSetDouble(), oyjlValueSetInt(), oyjlValueSetString(), and oyjlValueText().
void oyjlStringAddN | ( | char ** | text, |
const char * | append, | ||
int | append_len, | ||
void *(*)(size_t) | alloc, | ||
void(*)(void *) | deAlloc | ||
) |
append to the string end
[in] | text | source string |
[in] | append | to be added text to string |
[in] | append_len | length of append |
[in] | alloc | custom allocator; optional, default is malloc |
[in] | deAlloc | custom deallocator matching alloc; optional, default is free |
References oyjlStringAppendN().
char* oyjlStringAppendN | ( | const char * | text, |
const char * | append, | ||
int | append_len, | ||
void *(*)(size_t size) | alloc | ||
) |
append to the string end
For a plain memory duplication use:
[in] | text | source string; optional |
[in] | append | to be added text to string; optional |
[in] | append_len | length of append |
[in] | alloc | custom allocator; optional, default is malloc |
Referenced by oyjlStringAddN(), and oyjlUi_s::oyjlUi_Copy().
char* oyjlStringCopy | ( | const char * | string, |
void *(*)(size_t) | alloc | ||
) |
duplicate a string with custom allocator
The function adds the allocator over standard strdup().
[in] | string | source string |
[in] | alloc | custom allocator; optional, default is malloc |
Referenced by l2cmsFilterNode_GetText(), oyjlOptionStringToJson(), oyjlStringToDouble(), oyjlTermColorToPlain(), oyjlTreeClearValue(), oyjlTreeToYaml(), oyjlValueSetDouble(), and oyStringCopy().
int oyjlStringListAdd | ( | char *** | list, |
int * | n, | ||
void *(*)(size_t) | alloc, | ||
void(*)(void *) | deAlloc, | ||
const char * | format, | ||
... | |||
) |
add a variable string to a string list
References OYJL_CREATE_VA_STRING, and oyjlStringListPush().
void oyjlStringListAddList | ( | char *** | list, |
int * | n, | ||
const char ** | append, | ||
int | n_app, | ||
void *(*)(size_t) | alloc, | ||
void(*)(void *) | deAlloc | ||
) |
append a string list to an other and handle memory
References oyjlStringListCatList(), and oyjlStringListRelease().
char** oyjlStringListCatList | ( | const char ** | list, |
int | n_alt, | ||
const char ** | append, | ||
int | n_app, | ||
int * | count, | ||
void *(*)(size_t) | alloc | ||
) |
append a string list to an other string list
Referenced by oyjlStringListAddList().
void oyjlStringListFreeDoubles | ( | char ** | list, |
int * | list_n, | ||
void(*)(void *) | deAlloc | ||
) |
filter doubles out
void oyjlStringListPush | ( | char *** | list, |
int * | n, | ||
const char * | string, | ||
void *(*)(size_t) | alloc, | ||
void(*)(void *) | deAlloc | ||
) |
append a string to a string list
Referenced by oyjlStringListAdd().
void oyjlStringListRelease | ( | char *** | l, |
int | size, | ||
void(*)(void *) | deAlloc | ||
) |
free a string list
Referenced by oyjlStringListAddList(), oyjlTreeGetPath(), and oyStringListRelease().
int oyjlStringReplace | ( | char ** | text, |
const char * | search, | ||
const char * | replacement, | ||
void *(*)(size_t) | alloc, | ||
void(*)(void *) | deAlloc | ||
) |
substitute pattern in a string
[in,out] | text | source string for in place manipulation |
[in] | search | pattern to be tested in text |
[in] | replacement | string to be put in place of search sub string |
[in] | alloc | custom allocator; optional, default is malloc |
[in] | deAlloc | custom deallocator matching alloc; optional, default is free |
References oyjlStr_NewFrom(), oyjlStr_Pull(), oyjlStr_Release(), and oyjlStr_Replace().
Referenced by oyjlTreeToYaml().
char ** oyjlStringSplit | ( | const char * | text, |
const char | delimiter, | ||
int * | count, | ||
void *(*)(size_t) | alloc | ||
) |
convert a string into list
[in] | text | source string |
[in] | delimiter | the char which marks the split; e.g. comma ','; optional; default zero: extract white space separated words |
[out] | count | number of detected string segments; optional |
[in] | alloc | custom allocator; optional, default is malloc |
References oyjlStringSplit2().
Referenced by oyjlOptionStringToJson(), oyjlPathMatch(), oyjlTreeClearValue(), oyjlTreeToPaths(), and oyStringSplit().
char** oyjlStringSplit2 | ( | const char * | text, |
const char * | delimiter, | ||
const char * | splitFunc)(const char *text, const char *delimiter, int *length, | ||
int * | count, | ||
int ** | index, | ||
void *(*)(size_t) | alloc | ||
) |
convert a string into list
[in] | text | source string |
[in] | delimiter | the ASCII char which marks the split; e.g. comma ","; optional; default zero: extract white space separated words |
[in] | splitFunc | function for splitting, default is oyjlStringSplit(); optional |
[out] | count | number of detected string segments; optional |
[out] | index | to be allocated array of detected delimiter indexes; The array will contain the list of indexes in text, which lead to the actual split positional index.; optional |
[in] | alloc | custom allocator; optional, default is malloc |
Referenced by oyjlStringSplit(), and oyjlStringsToDoubles().
int oyjlStringSplitUTF8 | ( | const char * | text, |
char *** | mbchars, | ||
void *(*)(size_t) | alloc | ||
) |
split letters of a UTF-8 string
[in] | text | source string in UTF-8 format |
[out] | mbchars | NULL terminated array of count letters in UTF-8 format; optional |
[in] | alloc | custom allocator; optional, default is malloc |
int oyjlStringStartsWith | ( | const char * | text, |
const char * | pattern | ||
) |
simple and fast test
text | string to be searched in |
pattern | string to search in text |
Referenced by oyjlDataFormat().
int oyjlStringsToDoubles | ( | const char * | text, |
const char * | delimiter, | ||
int * | count, | ||
void *(*)(size_t) | alloc, | ||
double ** | value | ||
) |
text to double list
[in] | text | source string |
[in] | delimiter | the ASCII char(s) which mark the split; e.g. comma "," |
[out] | count | number of detected string segments; optional |
[in] | alloc | custom allocator; optional, default is malloc |
[out] | value | array of detected number of count elements |
References oyjlStringSplit2().
int oyjlStringToDouble | ( | const char * | text, |
double * | value, | ||
const char ** | end, | ||
int | flags | ||
) |
text to double conversion
[in] | text | string |
[out] | value | resulting number |
[out] | end | possibly part after number |
[in] | flags | OYJL_KEEP_LOCALE; default is to switch actual LC_NUMERIC to "C" |
References oyjlStringCopy().
Referenced by oyjlTreeGetNewValueFromArray().
int oyjlStringToLong | ( | const char * | text, |
long * | value, | ||
const char ** | end | ||
) |
show better const behaviour and return instant error status over strtol()
[in] | text | string |
[out] | value | resulting number |
[out] | end | possibly part after number |
const char* oyjlTermColorToPlain | ( | const char * | text, |
int flags | |||
) |
remove term color marks
The OYJL_REGEXP flag uses: int count = oyjlRegExpReplace( &t, "\033[[0-9;]*m", "" ); .
[in] | text | input |
[in] | flags | support OYJL_REGEXP slower but work as well outside Oyjl |
References OYJL_REGEXP, oyjlRegExpReplace(), and oyjlStringCopy().