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>
48 #include <Zycore/Defines.h>
49 #include <Zycore/Status.h>
50 #include <Zycore/Vector.h>
105 #define ZYDIS_STRING_ASSERT_NULLTERMINATION(string) \
106 ZYAN_ASSERT(*(char*)((ZyanU8*)(string)->vector.data + (string)->vector.size - 1) == '\0');
111 #define ZYDIS_STRING_NULLTERMINATE(string) \
112 *(char*)((ZyanU8*)(string)->vector.data + (string)->vector.size - 1) = '\0';
134 ZYAN_ASSERT(destination && source);
135 ZYAN_ASSERT(!destination->vector.allocator);
136 ZYAN_ASSERT(destination->vector.size && source->string.vector.size);
138 if (destination->vector.size + source->string.vector.size - 1 > destination->vector.capacity)
140 return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
143 ZYAN_MEMCPY((
char*)destination->vector.data + destination->vector.size - 1,
144 source->string.vector.data, source->string.vector.size - 1);
146 destination->vector.size += source->string.vector.size - 1;
149 return ZYAN_STATUS_SUCCESS;
165 ZYAN_ASSERT(destination && source);
166 ZYAN_ASSERT(!destination->vector.allocator);
167 ZYAN_ASSERT(destination->vector.size && source->string.vector.size);
169 if (destination->vector.size + source->string.vector.size - 1 > destination->vector.capacity)
171 return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
174 ZYAN_MEMCPY((
char*)destination->vector.data + destination->vector.size - 1,
175 source->string.vector.data, source->string.vector.size - 1);
183 const ZyanUSize index = destination->vector.size - 1;
184 const ZyanUSize count = source->string.vector.size - 1;
185 char* s = (
char*)destination->vector.data + index;
186 for (ZyanUSize i = index; i < index + count; ++i)
189 if ((c >=
'A') && (c <=
'Z'))
199 const ZyanUSize index = destination->vector.size - 1;
200 const ZyanUSize count = source->string.vector.size - 1;
201 char* s = (
char*)destination->vector.data + index;
202 for (ZyanUSize i = index; i < index + count; ++i)
205 if ((c >=
'a') && (c <=
'z'))
217 destination->vector.size += source->string.vector.size - 1;
220 return ZYAN_STATUS_SUCCESS;
234 ZYAN_ASSERT(destination && source);
235 ZYAN_ASSERT(!destination->vector.allocator);
236 ZYAN_ASSERT(destination->vector.size && source->
size);
238 if (destination->vector.size + source->
size > destination->vector.capacity)
240 return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
243 ZYAN_MEMCPY((
char*)destination->vector.data + destination->vector.size - 1, source->
data,
244 (ZyanUSize)source->
size + 1);
246 destination->vector.size += source->
size;
249 return ZYAN_STATUS_SUCCESS;
265 ZYAN_ASSERT(destination && source);
266 ZYAN_ASSERT(!destination->vector.allocator);
267 ZYAN_ASSERT(destination->vector.size && source->
size);
269 if (destination->vector.size + source->
size > destination->vector.capacity)
271 return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
274 ZYAN_MEMCPY((
char*)destination->vector.data + destination->vector.size - 1, source->
data,
275 (ZyanUSize)source->
size + 1);
283 const ZyanUSize index = destination->vector.size - 1;
284 const ZyanUSize count = source->
size;
285 char* s = (
char*)destination->vector.data + index;
286 for (ZyanUSize i = index; i < index + count; ++i)
289 if ((c >=
'A') && (c <=
'Z'))
299 const ZyanUSize index = destination->vector.size - 1;
300 const ZyanUSize count = source->
size;
301 char* s = (
char*)destination->vector.data + index;
302 for (ZyanUSize i = index; i < index + count; ++i)
305 if ((c >=
'a') && (c <=
'z'))
317 destination->vector.size += source->
size;
320 return ZYAN_STATUS_SUCCESS;
344 const ZyanStringView* prefix,
const ZyanStringView* suffix);
364 ZyanU8 padding_length, ZyanBool force_sign,
const ZyanStringView* prefix,
365 const ZyanStringView* suffix)
378 (
const ZyanStringView*)ZYAN_NULL, suffix);
383 ZYAN_ASSERT(value >= 0);
410 ZyanBool force_leading_number, ZyanBool uppercase,
const ZyanStringView* prefix,
411 const ZyanStringView* suffix);
436 ZyanU8 padding_length, ZyanBool force_leading_number, ZyanBool uppercase, ZyanBool force_sign,
437 const ZyanStringView* prefix,
const ZyanStringView* suffix)
450 force_leading_number, uppercase, (
const ZyanStringView*)ZYAN_NULL, suffix);
455 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:84
ZYAN_INLINE ZyanStatus ZydisStringAppendHexS(ZyanString *string, ZyanI64 value, ZyanU8 padding_length, ZyanBool force_leading_number, 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:435
ZydisLetterCase_
Defines the ZydisLetterCase enum.
Definition: String.h:68
@ ZYDIS_LETTER_CASE_UPPER
Converts the given text to uppercase letters.
Definition: String.h:80
@ ZYDIS_LETTER_CASE_REQUIRED_BITS
The minimum number of bits required to represent all values of this enum.
Definition: String.h:89
@ ZYDIS_LETTER_CASE_MAX_VALUE
Maximum value of this enum.
Definition: String.h:85
@ ZYDIS_LETTER_CASE_DEFAULT
Uses the given text "as is".
Definition: String.h:72
@ ZYDIS_LETTER_CASE_LOWER
Converts the given text to lowercase letters.
Definition: String.h:76
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:363
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:162
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:262
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:231
ZyanStatus ZydisStringAppendHexU(ZyanString *string, ZyanU64 value, ZyanU8 padding_length, ZyanBool force_leading_number, ZyanBool uppercase, const ZyanStringView *prefix, const ZyanStringView *suffix)
Formats the given unsigned ordinal value to its hexadecimal text-representation and appends it to the...
#define ZYDIS_STRING_NULLTERMINATE(string)
Writes a terminating '\0' character at the end of the string data.
Definition: String.h:111
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:132
#define ZYDIS_STRING_ASSERT_NULLTERMINATION(string)
Checks for a terminating '\0' character at the end of the string data.
Definition: String.h:105
Defines the ZydisShortString struct.
Definition: ShortString.h:60
ZyanU8 size
The length (number of characters) of the string (without 0-termination).
Definition: ShortString.h:68
const char * data
The buffer that contains the actual (null-terminated) string.
Definition: ShortString.h:64