sbgECom Library
4.0.1987-stable
C library to interface SBG Systems IMU/AHRS/INS
|
Character string. More...
Go to the source code of this file.
Data Structures | |
struct | _SbgString |
struct | _SbgStringIterator |
Macros | |
#define | SBG_STRING_INTERNAL_BUFFER_MIN_SIZE (4) |
#define | SBG_STRING_INTERNAL_BUFFER_DEFAULT_SIZE (16) |
Typedefs | |
typedef struct _SbgString | SbgString |
typedef struct _SbgStringIterator | SbgStringIterator |
Character string.
The MIT license
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define SBG_STRING_INTERNAL_BUFFER_MIN_SIZE (4) |
Minimum size of the internal buffer, in bytes.
This constant must be strictly positive in order to guarantee that no errors can occur during the construction of an empty string.
#define SBG_STRING_INTERNAL_BUFFER_DEFAULT_SIZE (16) |
Default size of the internal buffer, in bytes.
typedef struct _SbgString SbgString |
String.
The buffer contains a C null-terminated string. The null-terminating character is not considered to be part of the string content.
Attempts to modify a read-only string lead to undefined behavior.
Attempts to modify a string while the last modification operation error is set are canceled and return the last error code.
typedef struct _SbgStringIterator SbgStringIterator |
String iterator.
SBG_COMMON_LIB_API void sbgStringConstructEmpty | ( | SbgString * | pString | ) |
String constructor.
The rationale for this constructor is to guarantee that no errors may occur on the construction of empty strings.
[in] | pString | String. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringConstruct | ( | SbgString * | pString, |
const SbgString * | pSourceString | ||
) |
String constructor.
The string content is initialized from the given source string. If that string is NULL, the string is initialized with an empty content.
[in] | pString | String. |
[in] | pSourceString | Source string, may be NULL. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringConstructCString | ( | SbgString * | pString, |
const char * | pCString | ||
) |
String constructor.
The string content is initialized from the given C null-terminated string.
[in] | pString | String. |
[in] | pCString | C null-terminated string. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringConstructVF | ( | SbgString * | pString, |
const char * | pFormat, | ||
va_list | args | ||
) |
String constructor.
The string content is initialized from formatted data from a variable argument list.
[in] | pString | String. |
[in] | pFormat | Format. |
[in] | args | Variable argument list. |
SBG_COMMON_LIB_API SbgErrorCode SBG_COMMON_LIB_API SbgErrorCode sbgStringConstructF | ( | SbgString * | pString, |
const char * | pFormat, | ||
... | |||
) |
String constructor.
The string content is initialized from formatted data.
[in] | pString | String. |
[in] | pFormat | Format. |
SBG_COMMON_LIB_API SbgErrorCode SBG_COMMON_LIB_API SbgErrorCode SBG_COMMON_LIB_API SbgErrorCode sbgStringConstructStatic | ( | SbgString * | pString, |
const char * | pCString, | ||
char * | pBuffer, | ||
size_t | size | ||
) |
String constructor.
The string content is initialized from the given C null-terminated string.
If the C null-terminated string is NULL then the string contains the content of the given buffer before construction. In this case the content of the given buffer must be a C null-terminated string.
The given buffer is owned by the string and must not be modified while the string is in use. After destroying the string, the buffer contains the content of the string immediately before destruction.
[in] | pString | String. |
[in] | pCString | C null-terminated string, may be NULL. |
[in] | pBuffer | Buffer. |
[in] | size | Buffer size, in bytes. |
SBG_COMMON_LIB_API void sbgStringConstructReadOnly | ( | SbgString * | pString, |
const char * | pCString | ||
) |
String constructor.
The string cannot be modified.
The given C null-terminated string provides both the statically allocated buffer for the string, as well as its content. It is owned by the string and must not be modified.
[in] | pString | String. |
[in] | pCString | C null-terminated string. |
SBG_COMMON_LIB_API void sbgStringDestroy | ( | SbgString * | pString | ) |
String destructor.
[in] | pString | String. |
SBG_COMMON_LIB_API int32_t sbgStringCompare | ( | const SbgString * | pString, |
const SbgString * | pOtherString | ||
) |
Compare a string to another string.
[in] | pString | String. |
[in] | pOtherString | Other string. |
SBG_COMMON_LIB_API int32_t sbgStringCompareCString | ( | const SbgString * | pString, |
const char * | pCString | ||
) |
Compare a string to a C null-terminated string.
[in] | pString | String. |
[in] | pCString | C null-terminated string. |
SBG_COMMON_LIB_API int32_t sbgStringCompareIgnoreCase | ( | const SbgString * | pString, |
const SbgString * | pOtherString | ||
) |
Compare a string to another string, ignoring case differences.
[in] | pString | String. |
[in] | pOtherString | Other string. |
SBG_COMMON_LIB_API int32_t sbgStringCompareIgnoreCaseCString | ( | const SbgString * | pString, |
const char * | pCString | ||
) |
Compare a string to a C null-terminated string, ignoring case differences.
[in] | pString | String. |
[in] | pCString | C null-terminated string. |
SBG_COMMON_LIB_API size_t sbgStringHash | ( | const SbgString * | pString | ) |
Compute the hash value of a string.
[in] | pString | String. |
SBG_COMMON_LIB_API size_t sbgStringGetLength | ( | const SbgString * | pString | ) |
Get the length of a string (not including the terminating null character), in bytes.
[in] | pString | String. |
SBG_COMMON_LIB_API const char* sbgStringGetCString | ( | const SbgString * | pString | ) |
Get a C null-terminated string version of a string.
[in] | pString | String. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringCharAt | ( | const SbgString * | pString, |
size_t | index, | ||
char * | pChar | ||
) |
Get a character in a string.
[in] | pString | String. |
[in] | index | Index. |
[out] | pChar | Character. |
SBG_COMMON_LIB_API size_t sbgStringFind | ( | const SbgString * | pString, |
const SbgString * | pStringToFind | ||
) |
Get the index of the first occurrence of a string in a string.
[in] | pString | String. |
[in] | pStringToFind | String to find. |
SBG_COMMON_LIB_API size_t sbgStringFindCString | ( | const SbgString * | pString, |
const char * | pCString | ||
) |
Get the index of the first occurrence of the given C null-terminated string in a string.
[in] | pString | String. |
[in] | pCString | C null-terminated string. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringSubstring | ( | const SbgString * | pString, |
size_t | startIndex, | ||
size_t | endIndex, | ||
SbgString * | pSubstring | ||
) |
Get a substring from a string.
The substring must be constructed before calling this function. If an error occurs, the last error of the substring is set by this function.
[in] | pString | String. |
[in] | startIndex | Start index. |
[in] | endIndex | End index. |
[out] | pSubstring | Substring. |
SBG_COMMON_LIB_API bool sbgStringStartsWith | ( | const SbgString * | pString, |
const char * | pCString | ||
) |
Check if a C null-terminated string is at the beginning of a string.
[in] | pString | String. |
[in] | pCString | C null-terminated string. |
SBG_COMMON_LIB_API bool sbgStringEndsWith | ( | const SbgString * | pString, |
const char * | pCString | ||
) |
Check if a C null-terminated string is at the end of a string.
[in] | pString | String. |
[in] | pCString | C null-terminated string. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringGetLastError | ( | const SbgString * | pString | ) |
Get the last error of a modification operation on a string.
[in] | pString | String. |
SBG_COMMON_LIB_API void sbgStringClearLastError | ( | SbgString * | pString | ) |
Clear the last modification operation error of a string.
[in] | pString | String. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringSetCharAt | ( | SbgString * | pString, |
size_t | index, | ||
char | c | ||
) |
Set a character in a string.
The given index must be strictly lower than the string length. The given character must not be a null character.
[in] | pString | String. |
[in] | index | Index. |
[in] | c | Character. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringAppend | ( | SbgString * | pString, |
const SbgString * | pAppendString | ||
) |
Append a string to another string.
[in] | pString | String. |
[in] | pAppendString | String to append. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringAppendCString | ( | SbgString * | pString, |
const char * | pCString | ||
) |
Append a C null-terminated string to a string.
[in] | pString | String. |
[in] | pCString | C null-terminated string. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringAppendVF | ( | SbgString * | pString, |
const char * | pFormat, | ||
va_list | args | ||
) |
Append formatted data from a variable argument list to a string.
The string format, as well as the variable argument list, are the same as for vprintf.
[in] | pString | String. |
[in] | pFormat | Format. |
[in] | args | Variable argument list. |
SBG_COMMON_LIB_API SbgErrorCode SBG_COMMON_LIB_API SbgErrorCode sbgStringAppendF | ( | SbgString * | pString, |
const char * | pFormat, | ||
... | |||
) |
Append formatted data to a string.
The string format, as well as the variable arguments, are the same as for printf.
[in] | pString | String. |
[in] | pFormat | Format. |
SBG_COMMON_LIB_API SbgErrorCode SBG_COMMON_LIB_API SbgErrorCode SBG_COMMON_LIB_API SbgErrorCode sbgStringAssign | ( | SbgString * | pString, |
const SbgString * | pAssignString | ||
) |
Assign a string to another string.
[in] | pString | String. |
[in] | pAssignString | String to assign. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringAssignCString | ( | SbgString * | pString, |
const char * | pCString | ||
) |
Assign a C null-terminated string to a string.
[in] | pString | String. |
[in] | pCString | C null-terminated string. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringAssignVF | ( | SbgString * | pString, |
const char * | pFormat, | ||
va_list | args | ||
) |
Assign formatted data from a variable argument list to a string.
The string format, as well as the variable argument list, are the same as for vprintf.
[in] | pString | String. |
[in] | pFormat | Format. |
[in] | args | Variable argument list. |
SBG_COMMON_LIB_API SbgErrorCode SBG_COMMON_LIB_API SbgErrorCode sbgStringAssignF | ( | SbgString * | pString, |
const char * | pFormat, | ||
... | |||
) |
Assign formatted data to a string.
The string format, as well as the variable arguments, are the same as for printf.
[in] | pString | String. |
[in] | pFormat | Format. |
SBG_COMMON_LIB_API SbgErrorCode SBG_COMMON_LIB_API SbgErrorCode SBG_COMMON_LIB_API SbgErrorCode sbgStringClear | ( | SbgString * | pString | ) |
Clear a string.
After returning from this call the string is empty.
[in] | pString | String. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringToUpperCase | ( | SbgString * | pString | ) |
Convert all the characters of a string to upper case.
[in] | pString | String. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringToLowerCase | ( | SbgString * | pString | ) |
Convert all the characters of a string to lower case.
[in] | pString | String. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringTrimLeft | ( | SbgString * | pString | ) |
Remove all spacing characters at the beginning of a string.
[in] | pString | String. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringTrimRight | ( | SbgString * | pString | ) |
Remove all spacing characters at the end of a string.
[in] | pString | String. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringTrim | ( | SbgString * | pString | ) |
Remove all spacing characters at the beginning and the end of a string.
[in] | pString | String. |
SBG_COMMON_LIB_API void sbgStringTruncate | ( | SbgString * | pString, |
size_t | length | ||
) |
Truncate a string.
If the given length is greater than or equal to the length of the string, this function doesn't modify the string.
[in] | pString | String. |
[in] | length | Length, in bytes. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringFromInt8 | ( | SbgString * | pString, |
int8_t | value | ||
) |
Convert and assign a 8-bits signed integer value to a string.
[in] | pString | String. |
[in] | value | Value. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringToInt8 | ( | const SbgString * | pString, |
int8_t * | pValue | ||
) |
Convert a string to a 8-bits signed integer value.
[in] | pString | String. |
[out] | pValue | Value. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringFromUint8 | ( | SbgString * | pString, |
uint8_t | value | ||
) |
Convert and assign a 8-bits unsigned integer value to a string.
[in] | pString | String. |
[in] | value | Value |
SBG_COMMON_LIB_API SbgErrorCode sbgStringToUint8 | ( | const SbgString * | pString, |
uint8_t * | pValue | ||
) |
Convert a string to a 8-bits unsigned integer value.
[in] | pString | String. |
[out] | pValue | Value. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringFromInt16 | ( | SbgString * | pString, |
int16_t | value | ||
) |
Convert and assign a 16-bits signed integer value to a string.
[in] | pString | String. |
[in] | value | Value. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringToInt16 | ( | const SbgString * | pString, |
int16_t * | pValue | ||
) |
Convert a string to a 16-bits signed integer value.
[in] | pString | String. |
[out] | pValue | Value. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringFromUint16 | ( | SbgString * | pString, |
uint16_t | value | ||
) |
Convert and assign a 16-bits unsigned integer value to a string.
[in] | pString | String. |
[in] | value | Value |
SBG_COMMON_LIB_API SbgErrorCode sbgStringToUint16 | ( | const SbgString * | pString, |
uint16_t * | pValue | ||
) |
Convert a string to a 16-bits unsigned integer value.
[in] | pString | String. |
[out] | pValue | Value. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringFromInt32 | ( | SbgString * | pString, |
int32_t | value | ||
) |
Convert and assign a 32-bits signed integer value to a string.
[in] | pString | String. |
[in] | value | Value. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringToInt32 | ( | const SbgString * | pString, |
int32_t * | pValue | ||
) |
Convert a string to a 32-bits signed integer value.
[in] | pString | String. |
[out] | pValue | Value. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringFromUint32 | ( | SbgString * | pString, |
uint32_t | value | ||
) |
Convert and assign a 32-bits unsigned integer value to a string.
[in] | pString | String. |
[in] | value | Value |
SBG_COMMON_LIB_API SbgErrorCode sbgStringToUint32 | ( | const SbgString * | pString, |
uint32_t * | pValue | ||
) |
Convert a string to a 32-bits unsigned integer value.
[in] | pString | String. |
[out] | pValue | Value. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringFromInt64 | ( | SbgString * | pString, |
int64_t | value | ||
) |
Convert and assign a 64-bits signed integer value to a string.
[in] | pString | String. |
[in] | value | Value. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringToInt64 | ( | const SbgString * | pString, |
int64_t * | pValue | ||
) |
Convert a string to a 64-bits signed integer value.
[in] | pString | String. |
[out] | pValue | Value. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringFromUint64 | ( | SbgString * | pString, |
uint64_t | value | ||
) |
Convert and assign a 64-bits unsigned integer value to a string.
[in] | pString | String. |
[in] | value | Value |
SBG_COMMON_LIB_API SbgErrorCode sbgStringToUint64 | ( | const SbgString * | pString, |
uint64_t * | pValue | ||
) |
Convert a string to a 64-bits unsigned integer value.
[in] | pString | String. |
[out] | pValue | Value. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringFromFloat | ( | SbgString * | pString, |
float | value | ||
) |
Convert and assign a float value to a string.
[in] | pString | String. |
[in] | value | Value. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringToFloat | ( | const SbgString * | pString, |
float * | pValue | ||
) |
Convert a string to a float value.
[in] | pString | String. |
[out] | pValue | Value. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringFromDouble | ( | SbgString * | pString, |
double | value | ||
) |
Convert and assign a double value to a string.
[in] | pString | String. |
[in] | value | Value. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringToDouble | ( | const SbgString * | pString, |
double * | pValue | ||
) |
Convert a string to a double value.
[in] | pString | String. |
[out] | pValue | Value. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringFromStreamBuffer | ( | SbgString * | pString, |
SbgStreamBuffer * | pStream | ||
) |
Read a string from a stream buffer.
[in] | pString | String. |
[in] | pStream | Stream buffer. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringToStreamBuffer | ( | const SbgString * | pString, |
SbgStreamBuffer * | pStream | ||
) |
Write a string to a stream buffer.
[in] | pString | String. |
[out] | pStream | Stream buffer. |
SBG_COMMON_LIB_API void sbgStringIteratorConstruct | ( | SbgStringIterator * | pIterator, |
const SbgString * | pString | ||
) |
String iterator constructor.
If the given string is modified while the iterator is used, the behavior is undefined.
[in] | pIterator | String iterator. |
[in] | pString | String. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringIteratorWalk | ( | SbgStringIterator * | pIterator, |
const char * | pSeparators, | ||
bool | skipEmptyTokens, | ||
SbgString * | pToken | ||
) |
Walk to the next token of a string.
The token string must be constructed before calling this function. If an error occurs, the last error of the token string is set by this function.
[in] | pIterator | String iterator. |
[in] | pSeparators | C null-terminated string containing separator characters. |
[in] | skipEmptyTokens | If true, empty tokens are skipped. |
[out] | pToken | Token. |
SBG_COMMON_LIB_API SbgErrorCode sbgStringCopy | ( | char * | pDestination, |
const char * | pSource, | ||
size_t | destMaxSize | ||
) |
Safely copy source string to destination according to destination provided buffer size.
This method tends to replace strncpy where you would like to safely copy a string with buffer overflow checking. If the provided output buffer is too small, the method will return a valid NULL terminated C string in destination. This condition will be returned using SBG_BUFFER_OVERFLOW error code.
[out] | pDestination | The destination string that should hold the copied input string. |
[in] | pSource | The source NULL terminated C string to copy to the destination. |
[in] | destMaxSize | The destination buffer size including the null terminating char. |
SBG_COMMON_LIB_API const char* sbgStringFirstValidChar | ( | const char * | pInputStr | ) |
Skip all spacing characters from the beginning of a string.
[in] | pInputStr | Pointer on a read only string to trim. |