Refactor string functions, add unicode support
Refactored existing functions. Added Unicode support and UTF-8, UTF-16, and UTF-32 encoding/decoding.
This commit is contained in:
37
src/String/Inline/Signed.h
Normal file
37
src/String/Inline/Signed.h
Normal file
@@ -0,0 +1,37 @@
|
||||
char tmp[sizeof(value) * CHAR_BIT + 2];
|
||||
char *current, *end;
|
||||
int sign;
|
||||
|
||||
end = tmp + sizeof(tmp);
|
||||
current = end;
|
||||
sign = 0;
|
||||
|
||||
/* Check for sign */
|
||||
if (value < 0)
|
||||
{
|
||||
sign = 1;
|
||||
value = -value;
|
||||
}
|
||||
|
||||
/* Fill buffer from the end */
|
||||
*(--current) = 0;
|
||||
while (value)
|
||||
{
|
||||
*(--current) = digits[value % base];
|
||||
value /= base;
|
||||
}
|
||||
|
||||
/* Append sign */
|
||||
if (sign)
|
||||
*(--current) = '-';
|
||||
|
||||
/* Check that string have space for the result */
|
||||
if (size < (size_t)(end - current))
|
||||
return BH_ERROR;
|
||||
|
||||
/* Copy data */
|
||||
memcpy(string, current, end - current);
|
||||
if (actual)
|
||||
*actual = end - current;
|
||||
|
||||
return BH_OK;
|
||||
Reference in New Issue
Block a user