Go to the documentation of this file.
103 if (*(
char*)a < * (
char*)b)
105 if (*(
char*)a > *(
char*)b)
145 count = (
XsSize)strlen(src) + 1;
152 memcpy(thisPtr->m_data, src, count);
153 thisPtr->m_data[count] = 0;
163 memset(thisPtr->m_data,
' ', count);
164 thisPtr->m_data[count] = 0;
177 #ifndef XSENS_NO_WCHAR
186 int unicodeLength = lstrlenW(src);
187 int required = WideCharToMultiByte(CP_UTF8, 0, src, unicodeLength, NULL, 0, NULL, NULL);
188 if (required != -1 && required > 0)
191 if (reqv > thisPtr->m_reserved)
193 WideCharToMultiByte(CP_UTF8, 0, src, unicodeLength, thisPtr->m_data, required + 1, NULL, NULL);
194 thisPtr->m_data[required] =
'\0';
195 *((
XsSize*) &thisPtr->m_size) = reqv;
199 size_t required = wcstombs(0, src, 0);
200 if (required != (
size_t) -1 && required > 0)
202 if ((
XsSize)required + 1 > thisPtr->m_reserved)
204 wcstombs(thisPtr->m_data, src, required + 1);
205 *((
XsSize*) &thisPtr->m_size) = required + 1;
218 return (
XsSize)(ptrdiff_t) MultiByteToWideChar(CP_UTF8, 0, thisPtr->m_data, (
int)(ptrdiff_t) thisPtr->m_size, dest, (
int)(ptrdiff_t) size);
220 return mbstowcs(dest, thisPtr->m_data, size) + (dest ? 0 : 1);
229 wchar_t buf[2] = { c, 0 };
237 #endif // XSENS_NO_WCHAR
245 XsSize sz = thisPtr->m_size;
249 for (; sz < count; ++sz)
250 thisPtr->m_data[sz] =
' ';
251 thisPtr->m_data[count] = 0;
259 if (other && other->m_size > 1)
264 if (thisPtr == other)
267 static const char nullChar = 0;
278 if (index + count >= thisPtr->m_size)
281 XsArray_erase(thisPtr, index, (thisPtr->m_size - 1) - index);
294 XsSize sz = thisPtr->m_size;
298 thisPtr->m_data[sz - 1] = c;
303 if ((*p & 0xC0) != 0xC0)
328 uint8_t
const* p = (uint8_t
const*) thisPtr->m_data;
330 if (!thisPtr || !thisPtr->m_data)
341 #ifndef XSENS_NO_WCHAR
345 for (i = 0; i < bytes; ++i)
346 t = (t << 6) | (p[i] & 0x3F);
358 uint8_t
const* p = (uint8_t
const*) thisPtr->m_data;
360 if (!thisPtr || !thisPtr->m_data)
363 while (*p != 0 && index)
374 if ((*p & 0xC0) != 0xC0)
404 if (thisPtr->m_size < other->m_size)
408 if (other->m_size <= 1)
411 left = thisPtr->m_data + thisPtr->m_size - other->m_size;
412 right = other->m_data;
415 for (; *left == *right && *right; ++left, ++right);
417 for (; tolower((
unsigned char)*left) == tolower((
unsigned char)*right) && *right; ++left, ++right);
432 const char* left = thisPtr->m_data;
433 const char* right = other->m_data;
436 if (thisPtr->m_size < other->m_size)
440 if (other->m_size <= 1)
444 for (; *left == *right && *right; ++left, ++right);
446 for (; tolower((
unsigned char)*left) == tolower((
unsigned char)*right) && *right; ++left, ++right);
468 if (other->m_size <= 1)
472 while (thisPtr->m_size - *offset >= other->m_size)
474 const char* left = thisPtr->m_data + *offset;
475 const char* right = other->m_data;
477 for (; *left == *right && *right; ++left, ++right);
479 for (; tolower((
unsigned char)*left) == tolower((
unsigned char)*right) && *right; ++left, ++right);
497 if (!thisPtr->m_size || (thisPtr->m_flags &
XSDF_Empty))
499 return !(thisPtr->m_size - 1);
507 if (thisPtr->m_size > 2)
508 qsort(thisPtr->m_data, thisPtr->m_size - 1,
sizeof(
char),
compareChar);
518 char*
data, tmp, *right;
519 if (thisPtr->m_size > 2)
521 half = (int)((thisPtr->m_size - 1) >> 1);
522 data = (
char*) thisPtr->m_data;
523 right =
data + thisPtr->m_size - 2;
524 for (i = 0; i < half; ++i)
539 XsSize offset, i, end, endN;
542 if (!needle || needle->m_size <= 1)
544 if (thisPtr->m_size <= 1 || thisPtr->m_size < needle->m_size)
547 end = thisPtr->m_size - needle->m_size;
548 endN = needle->m_size - 1;
550 for (offset = 0; offset <= end; ++offset)
552 for (i = 0; i < endN; ++i)
553 if (thisPtr->m_data[offset + i] != needle->m_data[i])
556 return (ptrdiff_t) offset;
570 if (!thisPtr || !source)
572 if (
start >= source->m_size)
577 if (
start + count >= source->m_size)
578 count = (source->m_size - 1) -
start;
596 end = thisPtr->m_size - src->m_size;
597 endN = src->m_size - 1;
600 for (offset = 0; offset <= end;)
602 for (i = 0; i < endN; ++i)
603 if (thisPtr->m_data[offset + i] != src->m_data[i])
620 if (start < thisPtr->m_size)
642 if (isspace(source->m_data[
start]))
649 if (isspace(source->m_data[end - 1]))
This object describes how to treat the data in an array.
void XsArray_construct(void *thisPtr, XsArrayDescriptor const *const descriptor, XsSize count, void const *src)
Initializes the XsArray with space for count items and copies them from src.
uint8_t const * advanceUtf8(const uint8_t *p)
void XsArray_rawCopy(void *to, void const *from, XsSize count, XsSize iSize)
Copies items optimized in a direct way.
int32_t shiftUtf8(int32_t t, uint8_t const *p, int bytes)
void XsString_destruct(XsString *thisPtr)
Clears and frees memory allocated by the XsArray.
void XsString_trimmed(XsString *thisPtr, XsString const *source)
Fills thisPtr with a copy of source with all its leading and trailing whitespace removed.
int XsString_startsWith(XsString const *thisPtr, XsString const *other, int caseSensitive)
Returns whether this string starts with other.
XsSize XsString_copyToWCharArray(const XsString *thisPtr, wchar_t *dest, XsSize size)
This function copies the contents of the object to a unicode wchar_t array.
void XsString_sort(XsString *thisPtr)
Sorts the string.
int XsString_empty(XsString const *thisPtr)
Returns true when the supplied string is empty.
void copyChar(char *to, char const *from)
The function to use for copying the data of from to to.
void XsArray_destruct(void *thisPtr)
Clears and frees memory allocated by the XsArray.
XsSize XsString_utf8Len(XsString const *thisPtr)
Returns the number of characters in a UTF-8 encoded string.
void swapChar(char *a, char *b)
The function to use for swapping the data of two array items.
void XsArray_append(void *thisPtr, void const *other)
Appends the other list to thisArray list.
void XsString_append(XsString *thisPtr, XsString const *other)
This function concatenates the other to this.
void XsString_replaceAll(XsString *thisPtr, XsString const *src, XsString const *dst)
Replace all occurrences of src with dst, modifying thisPtr.
#define XSSTRING_INITIALIZER
void XsArray_erase(void *thisPtr, XsSize index, XsSize count)
Removes a count items from the list starting at index.
ptrdiff_t XsString_findSubStr(XsString const *thisPtr, XsString const *needle)
Find the first occurrence of needle in the string.
void XsString_assignWCharArray(XsString *thisPtr, const wchar_t *src)
This function determines the size of src and copies the contents to the object after converting it fr...
int XsString_contains(XsString const *thisPtr, XsString const *other, int caseSensitive, XsSize *offset)
Returns whether this string contains other.
void XsString_construct(XsString *thisPtr)
Initializes the XsString object as an empty string.
void XsString_reverse(XsString *thisPtr)
Reverses the contents of the string.
void XsString_push_backWChar(XsString *thisPtr, wchar_t c)
Append unicode character c to the string.
#define XsString_swap(a, b)
size_t XsSize
XsSize must be unsigned number!
void XsArray_assign(void *thisPtr, XsSize count, void const *src)
Reinitializes the XsArray with space for count items and copies them from src.
void XsArray_resize(void *thisPtr, XsSize count)
Resizes the existing list to count items.
void XsArray_insert(void *thisPtr, XsSize index, XsSize count, void const *src)
Insert count items from src at index in the array.
@ XSDF_Empty
The object contains undefined data / should be considered empty. Usually only relevant when XSDF_Fixe...
void XsArray_reserve(void *thisPtr, XsSize count)
Reserves space for count items.
int XsString_endsWith(XsString const *thisPtr, XsString const *other, int caseSensitive)
Returns whether this string ends with other.
void XsString_resize(XsString *thisPtr, XsSize count)
This function resizes the contained string to the desired size, while retaining its contents.
void XsString_push_back(XsString *thisPtr, char c)
Append character c to the string.
void XsString_assignCharArray(XsString *thisPtr, const char *src)
This function determines the size of src and copies the contents to the object.
const XsArrayDescriptor g_xsStringDescriptor
Descriptor for XsInt64Array.
void XsString_mid(XsString *thisPtr, XsString const *source, XsSize start, XsSize count)
Copy a substring of the source string.
void XsString_assign(XsString *thisPtr, XsSize count, const char *src)
Reinitializes the XsArray with space for count items and copies them from src.
void XsString_erase(XsString *thisPtr, XsSize index, XsSize count)
Removes a count items from the list starting at index.
wchar_t XsString_utf8At(XsString const *thisPtr, XsSize index)
The decoded UTF-8 character at index index in the UTF-8 encoded string.
A 0-terminated managed string of characters.
int compareChar(void const *a, void const *b)
The function to use for comparing two items.