40 #ifndef ZYDIS_INTERNAL_STRING_H
41 #define ZYDIS_INTERNAL_STRING_H
43 #include <Zycore/LibC.h>
44 #include <Zycore/String.h>
45 #include <Zycore/Types.h>
46 #include <Zycore/Format.h>
103 #define ZYDIS_STRING_ASSERT_NULLTERMINATION(string) \
104 ZYAN_ASSERT(*(char*)((ZyanU8*)(string)->vector.data + (string)->vector.size - 1) == '\0');
109 #define ZYDIS_STRING_NULLTERMINATE(string) \
110 *(char*)((ZyanU8*)(string)->vector.data + (string)->vector.size - 1) = '\0';
132 ZYAN_ASSERT(destination && source);
133 ZYAN_ASSERT(!destination->vector.allocator);
134 ZYAN_ASSERT(destination->vector.size && source->string.vector.size);
136 if (destination->vector.size + source->string.vector.size - 1 > destination->vector.capacity)
138 return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
141 ZYAN_MEMCPY((
char*)destination->vector.data + destination->vector.size - 1,
142 source->string.vector.data, source->string.vector.size - 1);
144 destination->vector.size += source->string.vector.size - 1;
147 return ZYAN_STATUS_SUCCESS;
163 ZYAN_ASSERT(destination && source);
164 ZYAN_ASSERT(!destination->vector.allocator);
165 ZYAN_ASSERT(destination->vector.size && source->string.vector.size);
167 if (destination->vector.size + source->string.vector.size - 1 > destination->vector.capacity)
169 return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
172 ZYAN_MEMCPY((
char*)destination->vector.data + destination->vector.size - 1,
173 source->string.vector.data, source->string.vector.size - 1);
181 const ZyanUSize index = destination->vector.size - 1;
182 const ZyanUSize count = source->string.vector.size - 1;
183 char* s = (
char*)destination->vector.data + index;
184 for (ZyanUSize i = index; i < index + count; ++i)
187 if ((c >=
'A') && (c <=
'Z'))
197 const ZyanUSize index = destination->vector.size - 1;
198 const ZyanUSize count = source->string.vector.size - 1;
199 char* s = (
char*)destination->vector.data + index;
200 for (ZyanUSize i = index; i < index + count; ++i)
203 if ((c >=
'a') && (c <=
'z'))
215 destination->vector.size += source->string.vector.size - 1;
218 return ZYAN_STATUS_SUCCESS;
232 ZYAN_ASSERT(destination && source);
233 ZYAN_ASSERT(!destination->vector.allocator);
234 ZYAN_ASSERT(destination->vector.size && source->
size);
236 if (destination->vector.size + source->
size > destination->vector.capacity)
238 return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
241 ZYAN_MEMCPY((
char*)destination->vector.data + destination->vector.size - 1, source->
data,
242 (ZyanUSize)source->
size + 1);
244 destination->vector.size += source->
size;
247 return ZYAN_STATUS_SUCCESS;
263 ZYAN_ASSERT(destination && source);
264 ZYAN_ASSERT(!destination->vector.allocator);
265 ZYAN_ASSERT(destination->vector.size && source->
size);
267 if (destination->vector.size + source->
size > destination->vector.capacity)
269 return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
272 ZYAN_MEMCPY((
char*)destination->vector.data + destination->vector.size - 1, source->
data,
273 (ZyanUSize)source->
size + 1);
281 const ZyanUSize index = destination->vector.size - 1;
282 const ZyanUSize count = source->
size;
283 char* s = (
char*)destination->vector.data + index;
284 for (ZyanUSize i = index; i < index + count; ++i)
287 if ((c >=
'A') && (c <=
'Z'))
297 const ZyanUSize index = destination->vector.size - 1;
298 const ZyanUSize count = source->
size;
299 char* s = (
char*)destination->vector.data + index;
300 for (ZyanUSize i = index; i < index + count; ++i)
303 if ((c >=
'a') && (c <=
'z'))
315 destination->vector.size += source->
size;
318 return ZYAN_STATUS_SUCCESS;
342 const ZyanStringView* prefix,
const ZyanStringView* suffix);
362 ZyanU8 padding_length, ZyanBool force_sign,
const ZyanStringView* prefix,
363 const ZyanStringView* suffix)
376 (
const ZyanStringView*)ZYAN_NULL, suffix);
381 ZYAN_ASSERT(value >= 0);
406 ZyanBool uppercase,
const ZyanStringView* prefix,
const ZyanStringView* suffix);
431 ZyanU8 padding_length, ZyanBool uppercase, ZyanBool force_sign,
const ZyanStringView* prefix,
432 const ZyanStringView* suffix)
445 (
const ZyanStringView*)ZYAN_NULL, suffix);
450 ZYAN_ASSERT(value >= 0);
Defines the immutable and storage-efficient ZydisShortString struct, which is used to store strings i...
#define ZYDIS_MAKE_SHORTSTRING(string)
Declares a ZydisShortString from a static C-style string.
Definition: ShortString.h:81
Status code definitions and check macros.
ZyanStatus ZydisStringAppendHexU(ZyanString *string, ZyanU64 value, ZyanU8 padding_length, ZyanBool uppercase, const ZyanStringView *prefix, const ZyanStringView *suffix)
Formats the given unsigned ordinal value to its hexadecimal text-representation and appends it to the...
ZydisLetterCase_
Defines the ZydisLetterCase enum.
Definition: String.h:66
@ ZYDIS_LETTER_CASE_UPPER
Converts the given text to uppercase letters.
Definition: String.h:78
@ ZYDIS_LETTER_CASE_REQUIRED_BITS
The minimum number of bits required to represent all values of this enum.
Definition: String.h:87
@ ZYDIS_LETTER_CASE_MAX_VALUE
Maximum value of this enum.
Definition: String.h:83
@ ZYDIS_LETTER_CASE_DEFAULT
Uses the given text "as is".
Definition: String.h:70
@ ZYDIS_LETTER_CASE_LOWER
Converts the given text to lowercase letters.
Definition: String.h:74
ZYAN_INLINE ZyanStatus ZydisStringAppendDecS(ZyanString *string, ZyanI64 value, ZyanU8 padding_length, ZyanBool force_sign, const ZyanStringView *prefix, const ZyanStringView *suffix)
Formats the given signed ordinal value to its decimal text-representation and appends it to the strin...
Definition: String.h:361
ZYAN_INLINE ZyanStatus ZydisStringAppendCase(ZyanString *destination, const ZyanStringView *source, ZydisLetterCase letter_case)
Appends the content of the source string to the end of the destination string, converting the charact...
Definition: String.h:160
ZYAN_INLINE ZyanStatus ZydisStringAppendShortCase(ZyanString *destination, const ZydisShortString *source, ZydisLetterCase letter_case)
Appends the content of the source short-string to the end of the destination string,...
Definition: String.h:260
enum ZydisLetterCase_ ZydisLetterCase
Defines the ZydisLetterCase enum.
ZyanStatus ZydisStringAppendDecU(ZyanString *string, ZyanU64 value, ZyanU8 padding_length, const ZyanStringView *prefix, const ZyanStringView *suffix)
Formats the given unsigned ordinal value to its decimal text-representation and appends it to the str...
ZYAN_INLINE ZyanStatus ZydisStringAppendShort(ZyanString *destination, const ZydisShortString *source)
Appends the content of the source short-string to the end of the destination string.
Definition: String.h:229
ZYAN_INLINE ZyanStatus ZydisStringAppendHexS(ZyanString *string, ZyanI64 value, ZyanU8 padding_length, ZyanBool uppercase, ZyanBool force_sign, const ZyanStringView *prefix, const ZyanStringView *suffix)
Formats the given signed ordinal value to its hexadecimal text-representation and appends it to the s...
Definition: String.h:430
#define ZYDIS_STRING_NULLTERMINATE(string)
Writes a terminating '\0' character at the end of the string data.
Definition: String.h:109
ZYAN_INLINE ZyanStatus ZydisStringAppend(ZyanString *destination, const ZyanStringView *source)
Appends the content of the source string to the end of the destination string.
Definition: String.h:130
#define ZYDIS_STRING_ASSERT_NULLTERMINATION(string)
Checks for a terminating '\0' character at the end of the string data.
Definition: String.h:103
Defines the ZydisShortString struct.
Definition: ShortString.h:59
ZyanU8 size
The length (number of characters) of the string (without 0-termination).
Definition: ShortString.h:67
const char * data
The buffer that contains the actual (null-terminated) string.
Definition: ShortString.h:63