regify utility  2.0.0-0
string.h
1 /*
2  * Copyright regify
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
29 #ifndef REGIFY_UTIL_STRING_H
30 #define REGIFY_UTIL_STRING_H
31 /* Only need to export C interface if used by C++ source code */
32 #ifdef __cplusplus
33 extern "C" {
34 #endif /* __cplusplus */
45 typedef void* ruString;
52 RUAPI ruString ruStringNew(const char* instr);
53 
62 RUAPI ruString ruStringNewn(const char* instr, rusize size);
63 
71 RUAPI ruString ruStringNewf(const char* format, ...);
72 
78 RUAPI int32_t ruStringReset(ruString rs);
79 
85 RUAPI ruString ruStringFree(ruString rs, bool keepBuffer);
86 
93 RUAPI int32_t ruStringAppend(ruString rs, const char* str);
94 
101 RUAPI int32_t ruStringAppendUriEncoded(ruString rs, const char* instr);
102 
111 RUAPI int32_t ruStringAppendn(ruString rs, const char* instr, rusize len);
112 
120 RUAPI int32_t ruStringAppendf(ruString rs, const char* format, ...);
121 
127 RUAPI char* ruStringGetCString(ruString rs);
128 
135 RUAPI rusize ruStringLen(ruString rs, int32_t *code);
136 
144 RUAPI bool ruStringEndsWith(ruString rs, const char *suffix, int32_t *code);
152 #define ruUtf8Nfc 1
153 
157 #define ruUtf8Nfd 2
158 // these seem to be generally missing ATM
159 //#define ruUtf8Nfkc 3
160 //#define ruUtf8Nfkd 4
161 
165 #define ruUtf8NoCase 0
166 
170 #define ruUtf8Lower 1
171 
175 #define ruUtf8Upper 2
176 
187 RUAPI char* ruUtf8CaseNormalize(const char *instr, int32_t normMode, int32_t caseMode);
188 
197 
206 
217 RUAPI void ruStrByteReplace(char* string, char search, char replace);
218 
228  trans_chars replace);
229 
237 RUAPI int32_t ruStrCmp(trans_chars str1, trans_chars str2);
238 
246 RUAPI bool ruStrEquals(trans_chars str1, trans_chars str2);
247 
256 RUAPI bool ruStrNEquals(trans_chars str1, rusize s1len, trans_chars str2);
257 
265 RUAPI int32_t ruStrCaseCmp(trans_chars str1, trans_chars str2);
266 
274 RUAPI bool ruStrCaseEquals(trans_chars str1, trans_chars str2);
275 
283 RUAPI bool ruStrStartsWith(trans_chars str, trans_chars prefix, int32_t *code);
284 
292 RUAPI bool ruStrCaseStartsWith(trans_chars str, trans_chars prefix, int32_t *code);
293 
301 RUAPI bool ruStrEndsWith(trans_chars str, trans_chars suffix, int32_t *code);
302 
310 RUAPI bool ruStrCaseEndsWith(trans_chars str, trans_chars suffix, int32_t *code);
311 
321 
329 RUAPI trans_chars ruStrStrLen(trans_chars haystack, trans_chars needle, rusize len);
330 
337 RUAPI trans_chars ruStrStr(trans_chars haystack, trans_chars needle);
338 
347 
355 
366 RUAPI ruList ruStrNSplit(trans_chars instr, rusize inlen, trans_chars delim, int32_t maxCnt);
367 
377 RUAPI ruList ruStrSplit(trans_chars instr, trans_chars delim, int32_t maxCnt);
378 
385 RUAPI char ruAsciiCharToLower(char in);
386 
393 
401 
408 RUAPI char ruAsciiCharToUpper(char in);
409 
416 
424 
431 
438 
445 RUAPI alloc_chars ruStrFromNUtf16(trans_uni unistr, int32_t bytelen);
446 
453 
460 RUAPI alloc_uni ruStrNToUtf16(trans_chars str, int32_t bytelen);
461 
468 
474 RUAPI char* ruStrDup(const char* str);
475 
482 
489 RUAPI char* ruStrNDup(const char* str, rusize len);
490 
497 RUAPI char* ruDupvPrintf(const char* format, va_list arglist);
498 
505 RUAPI char* ruDupPrintf(const char* format, ...);
506 
512 RUAPI bool ruIsInt64(trans_chars str);
513 
524 RUAPI bool ruIsBool(trans_chars str, bool* val);
525 
539 RUAPI int32_t ruStrParseBool(trans_chars str, perm_chars* endptr, bool* out);
540 
554 RUAPI int32_t ruStrParseInt64(trans_chars str, perm_chars* endptr, uint32_t base, int64_t* num);
555 
561 RUAPI int64_t ruStrToInt64(trans_chars str);
562 
576 RUAPI int32_t ruStrParseLong(trans_chars str, perm_chars* endptr, uint32_t base, long* num);
577 
583 RUAPI long ruStrToLong(trans_chars str);
584 
598 RUAPI int32_t ruStrParseInt(trans_chars str, perm_chars* endptr, uint32_t base, int32_t* num);
599 
605 RUAPI int32_t ruStrToInt(trans_chars str);
606 
613 RUAPI bool ruStrHasChar(trans_chars haystack, char needle);
614 
625  alloc_chars* newstr);
626 
634 ruTrimBoth = (uint32_t)0,
635 
640 
644 ruTrimEnd = 2
645 
646 };
647 
674  enum ruTrimSide ends, alloc_chars* newstr);
675 
683 RUAPI trans_chars ruStrTrimBounds(trans_chars inStart, rusize inLen, rusize* outLen);
684 
699 RUAPI bool ruStrFindKeyVal(trans_chars inStart, rusize inLen, trans_chars delim,
700  trans_chars* keyStart, rusize* keyLen,
701  trans_chars* valStart, rusize* valLen);
702 
708 RUAPI bool ruStrEmpty(trans_chars str);
709 
732 typedef void* ruBuffer;
733 
743 #define ruBufferNew(initialSize) (ruBuffer) ruStringNewn(NULL, initialSize)
744 
752 #define ruBufferAppend(rb, buf, len) ruStringAppendn(rb, buf, len)
753 
761 RUAPI int32_t ruBufferAppendUriEncoded(ruString rs, const char* buf, rusize len);
762 
768 #define ruBufferGetData(rb) ruStringGetCString(rb)
769 
776 #define ruBufferLen(rb, code) ruStringLen(rb, code)
777 
783 #define ruBufferFree(rb, keep) ruStringFree(rb, keep);
784 
789 #ifdef __cplusplus
790 }
791 #endif /* __cplusplus */
792 #endif //REGIFY_UTIL_STRING_H
void * ruBuffer
An opaque data type representing a regify-util string object that is not NULL terminated.
Definition: string.h:732
RUAPI int32_t ruBufferAppendUriEncoded(ruString rs, const char *buf, rusize len)
Append given string URI encoded to String Object.
void * ruList
Opaque pointer to list object. See List Collection.
Definition: list.h:103
uint16_t * alloc_uni
An allocated UTF16 wchar_t character type.
Definition: regify-util.h:233
const uint16_t * trans_uni
A transient UTF16 wchar_t character type.
Definition: regify-util.h:220
const char * trans_chars
A transient NULL terminated string pointer.
Definition: regify-util.h:186
const char * perm_chars
A permanent NULL terminated string pointer.
Definition: regify-util.h:176
char * alloc_chars
An allocated NULL terminated string pointer.
Definition: regify-util.h:199
size_t rusize
Abstracted version of size_t.
Definition: regify-util.h:338
RUAPI int32_t ruStringAppend(ruString rs, const char *str)
Append given string to String Object.
RUAPI int32_t ruStringReset(ruString rs)
Empties the string for reuse without freeing the buffer.
RUAPI int32_t ruStringAppendUriEncoded(ruString rs, const char *instr)
Append given string URI encoded to String Object.
RUAPI bool ruStringEndsWith(ruString rs, const char *suffix, int32_t *code)
Whether String Object ends with given suffix.
RUAPI char * ruStringGetCString(ruString rs)
Returns the underlying char* of the given String Object.
void * ruString
An opaque data type representing a regify-util string object.
Definition: string.h:45
RUAPI rusize ruStringLen(ruString rs, int32_t *code)
Returns the current length of the String Object.
RUAPI ruString ruStringNewn(const char *instr, rusize size)
Creates a new String object of initial size from a string.
RUAPI ruString ruStringFree(ruString rs, bool keepBuffer)
Frees the given String Object object.
RUAPI int32_t ruStringAppendf(ruString rs, const char *format,...)
Appends formatted string to String Object.
RUAPI ruString ruStringNewf(const char *format,...)
Creates a new String object from a formatted string.
RUAPI ruString ruStringNew(const char *instr)
Creates a new String object from a string.
RUAPI int32_t ruStringAppendn(ruString rs, const char *instr, rusize len)
Append given string to String Object.
RUAPI trans_chars ruStrTrimBounds(trans_chars inStart, rusize inLen, rusize *outLen)
Returns the white space trimmed bounds of given string without modifying it.
RUAPI alloc_uni ruStrNToUtf16(trans_chars str, int32_t bytelen)
Converts given UTF8 string to UTF16 as it is used on Windows.
RUAPI bool ruStrCaseEquals(trans_chars str1, trans_chars str2)
Returns true when libc strcasecmp would return 0 but in a manner that gracefully handles NULL imputs.
RUAPI alloc_chars ruStrReplace(trans_chars instr, trans_chars search, trans_chars replace)
Replaces any occurrence of search in instr with replace.
RUAPI char * ruDupvPrintf(const char *format, va_list arglist)
Returns an allocated string from given vprintf call.
RUAPI alloc_chars ruStrFromUtf16(trans_uni unistr)
Converts given UTF16 wide character sequence to UTF8.
ruTrimSide
Definition: string.h:630
RUAPI char ruAsciiCharToUpper(char in)
Returns uppercase representation of given ASCII character.
RUAPI int32_t ruStrCaseCmp(trans_chars str1, trans_chars str2)
Returns what libc strcasecmp would return but in a manner that gracefully handles NULL imputs.
RUAPI perm_chars ruStrTrim(perm_chars instr, trans_chars unwanted, enum ruTrimSide ends, alloc_chars *newstr)
Checks given string for leading / trailing unwanted characters and returns trimmed copy if needed.
RUAPI long ruStrToLong(trans_chars str)
Like ruStrParseLong but ignores overflow and trailing garbage.
RUAPI trans_chars ruStrStrLen(trans_chars haystack, trans_chars needle, rusize len)
Searches the first instance of needle in haystack up to len bytes.
RUAPI char * ruStrDup(const char *str)
Returns a copy of given string.
RUAPI ruList ruStrSplit(trans_chars instr, trans_chars delim, int32_t maxCnt)
split given instr with delim into a ruList.
RUAPI alloc_chars ruAsciiNToLower(trans_chars instr, rusize len)
Returns a lowercase copy of len bytes of given ASCII string.
RUAPI perm_chars ruStrStrip(perm_chars instr, trans_chars unwanted, alloc_chars *newstr)
Removes unwanted characters from instr.
RUAPI bool ruStrEquals(trans_chars str1, trans_chars str2)
Returns true when libc strcmp would return 0 but in a manner that gracefully handles NULL imputs.
RUAPI bool ruStrStartsWith(trans_chars str, trans_chars prefix, int32_t *code)
Whether given string starts with given prefix.
RUAPI bool ruIsBool(trans_chars str, bool *val)
Returns true if given string contains a valid boolean.
RUAPI trans_chars ruStrCaseStrLen(trans_chars haystack, trans_chars needle, rusize len)
Searches the first instance of lowercase needle in lowercase haystack up to len bytes....
RUAPI alloc_chars ruUtf8ToUpper(trans_chars instr)
Returns a uppercase copy of given UTF8 string.
RUAPI int64_t ruStrToInt64(trans_chars str)
Like ruStrParseInt64 but ignores overflow and trailing garbage.
RUAPI char * ruUtf8CaseNormalize(const char *instr, int32_t normMode, int32_t caseMode)
Returns the given string normalized and/or case switched as requested.
RUAPI trans_chars ruLastSubStr(trans_chars haystack, trans_chars needle)
Searches the last instance of needle in haystack.
RUAPI bool ruStrEndsWith(trans_chars str, trans_chars suffix, int32_t *code)
Whether given string ends with given suffix.
RUAPI trans_chars ruLastSubStrLen(trans_chars haystack, trans_chars needle, rusize len)
Searches the last instance of needle in haystack up to len bytes.
RUAPI bool ruStrEmpty(trans_chars str)
Checks whether given string has any content other than whitespace.
RUAPI int32_t ruStrParseInt(trans_chars str, perm_chars *endptr, uint32_t base, int32_t *num)
RUAPI alloc_chars ruUtf8ToLower(trans_chars instr)
Returns a lowercase copy of given UTF8 string.
RUAPI alloc_chars ruAsciiToUpper(trans_chars instr)
Returns a uppercase copy of given ASCII string.
RUAPI int32_t ruStrParseLong(trans_chars str, perm_chars *endptr, uint32_t base, long *num)
RUAPI trans_chars ruStrStr(trans_chars haystack, trans_chars needle)
Searches the first instance of needle in haystack.
RUAPI ruList ruStrNSplit(trans_chars instr, rusize inlen, trans_chars delim, int32_t maxCnt)
Split given instr up to inlen bytes with delim into a ruList.
RUAPI bool ruStrHasChar(trans_chars haystack, char needle)
RUAPI bool ruStrFindKeyVal(trans_chars inStart, rusize inLen, trans_chars delim, trans_chars *keyStart, rusize *keyLen, trans_chars *valStart, rusize *valLen)
Parses whitespace trimmed key / value regions based on delim out of given input string.
RUAPI int32_t ruStrParseInt64(trans_chars str, perm_chars *endptr, uint32_t base, int64_t *num)
RUAPI int32_t ruStrParseBool(trans_chars str, perm_chars *endptr, bool *out)
Parses boolean value out of given string.
RUAPI alloc_chars ruAsciiToLower(trans_chars instr)
Returns a lowercase copy of given ASCII string.
RUAPI bool ruStrCaseStartsWith(trans_chars str, trans_chars prefix, int32_t *code)
Whether given string starts with given prefix ignoring case.
RUAPI alloc_chars ruAsciiNToUpper(trans_chars instr, rusize len)
Returns a uppercase copy of len bytes of given ASCII string.
RUAPI char * ruStrNDup(const char *str, rusize len)
Returns a copy of len bytes of given string.
RUAPI void ruStrByteReplace(char *string, char search, char replace)
Replaces any occurrence of search in string with replace.
RUAPI bool ruStrCaseEndsWith(trans_chars str, trans_chars suffix, int32_t *code)
Whether given string ends with given suffix ignoring case.
RUAPI char * ruDupPrintf(const char *format,...)
Returns an allocated string from given printf call.
RUAPI alloc_chars ruStrToNfd(trans_chars instr)
Returns the given string in decomposed form.
RUAPI int32_t ruStrToInt(trans_chars str)
Like ruStrParseInt but ignores overflow and trailing garbage.
RUAPI alloc_chars ruStrFromNUtf16(trans_uni unistr, int32_t bytelen)
Converts given UTF16 wide character sequence to UTF8.
RUAPI rusize ruStrLen(trans_chars str)
behaves like strlen but returns 0 if NULL is passed in
RUAPI char ruAsciiCharToLower(char in)
Returns lowercase representation of given ASCII character.
RUAPI alloc_chars ruStrFromNfd(trans_chars instr)
Returns the given decomposed string in precomposed form.
RUAPI bool ruStrNEquals(trans_chars str1, rusize s1len, trans_chars str2)
Returns true when str2 is equal to the first len number of bytes in str1 or both str1 and str2 are NU...
RUAPI bool ruIsInt64(trans_chars str)
Returns true if given string contains a valid 64 bit integer.
RUAPI int32_t ruStrCmp(trans_chars str1, trans_chars str2)
Returns what libc strcmp would return but in a manner that gracefully handles NULL imputs.
RUAPI alloc_uni ruStrToUtf16(trans_chars str)
Converts given UTF8 string to UTF16 as it is used on Windows.
@ ruTrimStart
Definition: string.h:639
@ ruTrimEnd
Definition: string.h:644
@ ruTrimBoth
Definition: string.h:634