Coverage Report

Created: 2026-01-22 07:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/zydis/include/Zydis/Internal/String.h
Line
Count
Source
1
/***************************************************************************************************
2
3
  Zyan Disassembler Library (Zydis)
4
5
  Original Author : Florian Bernd, Joel Hoener
6
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in all
15
 * copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
 * SOFTWARE.
24
25
***************************************************************************************************/
26
27
/**
28
 * @file
29
 * Provides some internal, more performant, but unsafe helper functions for the `ZyanString`
30
 * data-type.
31
 *
32
 * Most of these functions are very similar to the ones in `Zycore/String.h`, but inlined and
33
 * without optional overhead like parameter-validation checks, etc ...
34
 *
35
 * The `ZyanString` data-type is able to dynamically allocate memory on the heap, but as `Zydis` is
36
 * designed to be a non-'malloc'ing library, all functions in this file assume that the instances
37
 * they are operating on are created with a user-defined static-buffer.
38
 */
39
40
#ifndef ZYDIS_INTERNAL_STRING_H
41
#define ZYDIS_INTERNAL_STRING_H
42
43
#include <Zycore/LibC.h>
44
#include <Zycore/String.h>
45
#include <Zycore/Types.h>
46
#include <Zycore/Format.h>
47
#include <Zydis/ShortString.h>
48
#include <Zycore/Defines.h>
49
#include <Zycore/Status.h>
50
#include <Zycore/Vector.h>
51
52
#ifdef __cplusplus
53
extern "C" {
54
#endif
55
56
/* ============================================================================================== */
57
/* Enums and types                                                                                */
58
/* ============================================================================================== */
59
60
/* ---------------------------------------------------------------------------------------------- */
61
/* Letter Case                                                                                    */
62
/* ---------------------------------------------------------------------------------------------- */
63
64
/**
65
 * Defines the `ZydisLetterCase` enum.
66
 */
67
typedef enum ZydisLetterCase_
68
{
69
    /**
70
     * Uses the given text "as is".
71
     */
72
    ZYDIS_LETTER_CASE_DEFAULT,
73
    /**
74
     * Converts the given text to lowercase letters.
75
     */
76
    ZYDIS_LETTER_CASE_LOWER,
77
    /**
78
     * Converts the given text to uppercase letters.
79
     */
80
    ZYDIS_LETTER_CASE_UPPER,
81
82
    /**
83
     * Maximum value of this enum.
84
     */
85
    ZYDIS_LETTER_CASE_MAX_VALUE = ZYDIS_LETTER_CASE_UPPER,
86
    /**
87
     * The minimum number of bits required to represent all values of this enum.
88
     */
89
    ZYDIS_LETTER_CASE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_LETTER_CASE_MAX_VALUE)
90
} ZydisLetterCase;
91
92
/* ---------------------------------------------------------------------------------------------- */
93
94
/* ============================================================================================== */
95
/* Macros                                                                                         */
96
/* ============================================================================================== */
97
98
/* ---------------------------------------------------------------------------------------------- */
99
/* Internal macros                                                                                */
100
/* ---------------------------------------------------------------------------------------------- */
101
102
/**
103
 * Checks for a terminating '\0' character at the end of the string data.
104
 */
105
#define ZYDIS_STRING_ASSERT_NULLTERMINATION(string) \
106
36.4k
      ZYAN_ASSERT(*(char*)((ZyanU8*)(string)->vector.data + (string)->vector.size - 1) == '\0');
107
108
/**
109
 * Writes a terminating '\0' character at the end of the string data.
110
 */
111
#define ZYDIS_STRING_NULLTERMINATE(string) \
112
9.48k
      *(char*)((ZyanU8*)(string)->vector.data + (string)->vector.size - 1) = '\0';
113
114
/* ---------------------------------------------------------------------------------------------- */
115
116
/* ============================================================================================== */
117
/* Internal Functions                                                                             */
118
/* ============================================================================================== */
119
120
/* ---------------------------------------------------------------------------------------------- */
121
/* Appending                                                                                      */
122
/* ---------------------------------------------------------------------------------------------- */
123
124
/**
125
 * Appends the content of the source string to the end of the destination string.
126
 *
127
 * @param   destination The destination string.
128
 * @param   source      The source string.
129
 *
130
 * @return  A zyan status code.
131
 */
132
ZYAN_INLINE ZyanStatus ZydisStringAppend(ZyanString* destination, const ZyanStringView* source)
133
5.73k
{
134
5.73k
    ZYAN_ASSERT(destination && source);
135
5.73k
    ZYAN_ASSERT(!destination->vector.allocator);
136
5.73k
    ZYAN_ASSERT(destination->vector.size && source->string.vector.size);
137
138
5.73k
    if (destination->vector.size + source->string.vector.size - 1 > destination->vector.capacity)
139
389
    {
140
389
        return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
141
389
    }
142
143
5.34k
    ZYAN_MEMCPY((char*)destination->vector.data + destination->vector.size - 1,
144
5.34k
        source->string.vector.data, source->string.vector.size - 1);
145
146
5.34k
    destination->vector.size += source->string.vector.size - 1;
147
5.34k
    ZYDIS_STRING_NULLTERMINATE(destination);
148
149
5.34k
    return ZYAN_STATUS_SUCCESS;
150
5.73k
}
Unexecuted instantiation: Formatter.c:ZydisStringAppend
Unexecuted instantiation: FormatterBuffer.c:ZydisStringAppend
FormatterATT.c:ZydisStringAppend
Line
Count
Source
133
281
{
134
281
    ZYAN_ASSERT(destination && source);
135
281
    ZYAN_ASSERT(!destination->vector.allocator);
136
281
    ZYAN_ASSERT(destination->vector.size && source->string.vector.size);
137
138
281
    if (destination->vector.size + source->string.vector.size - 1 > destination->vector.capacity)
139
34
    {
140
34
        return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
141
34
    }
142
143
247
    ZYAN_MEMCPY((char*)destination->vector.data + destination->vector.size - 1,
144
247
        source->string.vector.data, source->string.vector.size - 1);
145
146
247
    destination->vector.size += source->string.vector.size - 1;
147
247
    ZYDIS_STRING_NULLTERMINATE(destination);
148
149
247
    return ZYAN_STATUS_SUCCESS;
150
281
}
FormatterBase.c:ZydisStringAppend
Line
Count
Source
133
431
{
134
431
    ZYAN_ASSERT(destination && source);
135
431
    ZYAN_ASSERT(!destination->vector.allocator);
136
431
    ZYAN_ASSERT(destination->vector.size && source->string.vector.size);
137
138
431
    if (destination->vector.size + source->string.vector.size - 1 > destination->vector.capacity)
139
45
    {
140
45
        return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
141
45
    }
142
143
386
    ZYAN_MEMCPY((char*)destination->vector.data + destination->vector.size - 1,
144
386
        source->string.vector.data, source->string.vector.size - 1);
145
146
386
    destination->vector.size += source->string.vector.size - 1;
147
386
    ZYDIS_STRING_NULLTERMINATE(destination);
148
149
386
    return ZYAN_STATUS_SUCCESS;
150
431
}
FormatterIntel.c:ZydisStringAppend
Line
Count
Source
133
255
{
134
255
    ZYAN_ASSERT(destination && source);
135
255
    ZYAN_ASSERT(!destination->vector.allocator);
136
255
    ZYAN_ASSERT(destination->vector.size && source->string.vector.size);
137
138
255
    if (destination->vector.size + source->string.vector.size - 1 > destination->vector.capacity)
139
57
    {
140
57
        return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
141
57
    }
142
143
198
    ZYAN_MEMCPY((char*)destination->vector.data + destination->vector.size - 1,
144
198
        source->string.vector.data, source->string.vector.size - 1);
145
146
198
    destination->vector.size += source->string.vector.size - 1;
147
198
    ZYDIS_STRING_NULLTERMINATE(destination);
148
149
198
    return ZYAN_STATUS_SUCCESS;
150
255
}
String.c:ZydisStringAppend
Line
Count
Source
133
4.76k
{
134
4.76k
    ZYAN_ASSERT(destination && source);
135
4.76k
    ZYAN_ASSERT(!destination->vector.allocator);
136
4.76k
    ZYAN_ASSERT(destination->vector.size && source->string.vector.size);
137
138
4.76k
    if (destination->vector.size + source->string.vector.size - 1 > destination->vector.capacity)
139
253
    {
140
253
        return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
141
253
    }
142
143
4.51k
    ZYAN_MEMCPY((char*)destination->vector.data + destination->vector.size - 1,
144
4.51k
        source->string.vector.data, source->string.vector.size - 1);
145
146
4.51k
    destination->vector.size += source->string.vector.size - 1;
147
4.51k
    ZYDIS_STRING_NULLTERMINATE(destination);
148
149
4.51k
    return ZYAN_STATUS_SUCCESS;
150
4.76k
}
151
152
/**
153
 * Appends the content of the source string to the end of the destination
154
 * string, converting the characters to the specified letter-case.
155
 *
156
 * @param   destination The destination string.
157
 * @param   source      The source string.
158
 * @param   letter_case The desired letter-case.
159
 *
160
 * @return  A zyan status code.
161
 */
162
ZYAN_INLINE ZyanStatus ZydisStringAppendCase(ZyanString* destination, const ZyanStringView* source,
163
    ZydisLetterCase letter_case)
164
0
{
165
0
    ZYAN_ASSERT(destination && source);
166
0
    ZYAN_ASSERT(!destination->vector.allocator);
167
0
    ZYAN_ASSERT(destination->vector.size && source->string.vector.size);
168
0
169
0
    if (destination->vector.size + source->string.vector.size - 1 > destination->vector.capacity)
170
0
    {
171
0
        return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
172
0
    }
173
0
174
0
    ZYAN_MEMCPY((char*)destination->vector.data + destination->vector.size - 1,
175
0
        source->string.vector.data, source->string.vector.size - 1);
176
0
177
0
    switch (letter_case)
178
0
    {
179
0
    case ZYDIS_LETTER_CASE_DEFAULT:
180
0
        break;
181
0
    case ZYDIS_LETTER_CASE_LOWER:
182
0
    {
183
0
        const ZyanUSize index = destination->vector.size - 1;
184
0
        const ZyanUSize count = source->string.vector.size - 1;
185
0
        char* s = (char*)destination->vector.data + index;
186
0
        for (ZyanUSize i = index; i < index + count; ++i)
187
0
        {
188
0
            const char c = *s;
189
0
            if ((c >= 'A') && (c <= 'Z'))
190
0
            {
191
0
                *s = c | 32;
192
0
            }
193
0
            ++s;
194
0
        }
195
0
        break;
196
0
    }
197
0
    case ZYDIS_LETTER_CASE_UPPER:
198
0
    {
199
0
        const ZyanUSize index = destination->vector.size - 1;
200
0
        const ZyanUSize count = source->string.vector.size - 1;
201
0
        char* s = (char*)destination->vector.data + index;
202
0
        for (ZyanUSize i = index; i < index + count; ++i)
203
0
        {
204
0
            const char c = *s;
205
0
            if ((c >= 'a') && (c <= 'z'))
206
0
            {
207
0
                *s = c & ~32;
208
0
            }
209
0
            ++s;
210
0
        }
211
0
        break;
212
0
    }
213
0
    default:
214
0
        ZYAN_UNREACHABLE;
215
0
    }
216
0
217
0
    destination->vector.size += source->string.vector.size - 1;
218
0
    ZYDIS_STRING_NULLTERMINATE(destination);
219
0
220
0
    return ZYAN_STATUS_SUCCESS;
221
0
}
Unexecuted instantiation: Formatter.c:ZydisStringAppendCase
Unexecuted instantiation: FormatterBuffer.c:ZydisStringAppendCase
Unexecuted instantiation: FormatterATT.c:ZydisStringAppendCase
Unexecuted instantiation: FormatterBase.c:ZydisStringAppendCase
Unexecuted instantiation: FormatterIntel.c:ZydisStringAppendCase
Unexecuted instantiation: String.c:ZydisStringAppendCase
222
223
/**
224
 * Appends the content of the source short-string to the end of the destination string.
225
 *
226
 * @param   destination The destination string.
227
 * @param   source      The source string.
228
 *
229
 * @return  A zyan status code.
230
 */
231
ZYAN_INLINE ZyanStatus ZydisStringAppendShort(ZyanString* destination,
232
    const ZydisShortString* source)
233
18.8k
{
234
18.8k
    ZYAN_ASSERT(destination && source);
235
18.8k
    ZYAN_ASSERT(!destination->vector.allocator);
236
18.8k
    ZYAN_ASSERT(destination->vector.size && source->size);
237
238
18.8k
    if (destination->vector.size + source->size > destination->vector.capacity)
239
420
    {
240
420
        return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
241
420
    }
242
243
18.3k
    ZYAN_MEMCPY((char*)destination->vector.data + destination->vector.size - 1, source->data,
244
18.3k
        (ZyanUSize)source->size + 1);
245
246
18.3k
    destination->vector.size += source->size;
247
18.3k
    ZYDIS_STRING_ASSERT_NULLTERMINATION(destination);
248
249
18.3k
    return ZYAN_STATUS_SUCCESS;
250
18.3k
}
Unexecuted instantiation: Formatter.c:ZydisStringAppendShort
Unexecuted instantiation: FormatterBuffer.c:ZydisStringAppendShort
FormatterATT.c:ZydisStringAppendShort
Line
Count
Source
233
8.97k
{
234
8.97k
    ZYAN_ASSERT(destination && source);
235
8.97k
    ZYAN_ASSERT(!destination->vector.allocator);
236
8.97k
    ZYAN_ASSERT(destination->vector.size && source->size);
237
238
8.97k
    if (destination->vector.size + source->size > destination->vector.capacity)
239
185
    {
240
185
        return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
241
185
    }
242
243
8.78k
    ZYAN_MEMCPY((char*)destination->vector.data + destination->vector.size - 1, source->data,
244
8.78k
        (ZyanUSize)source->size + 1);
245
246
8.78k
    destination->vector.size += source->size;
247
8.78k
    ZYDIS_STRING_ASSERT_NULLTERMINATION(destination);
248
249
8.78k
    return ZYAN_STATUS_SUCCESS;
250
8.78k
}
FormatterBase.c:ZydisStringAppendShort
Line
Count
Source
233
3.08k
{
234
3.08k
    ZYAN_ASSERT(destination && source);
235
3.08k
    ZYAN_ASSERT(!destination->vector.allocator);
236
3.08k
    ZYAN_ASSERT(destination->vector.size && source->size);
237
238
3.08k
    if (destination->vector.size + source->size > destination->vector.capacity)
239
80
    {
240
80
        return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
241
80
    }
242
243
3.00k
    ZYAN_MEMCPY((char*)destination->vector.data + destination->vector.size - 1, source->data,
244
3.00k
        (ZyanUSize)source->size + 1);
245
246
3.00k
    destination->vector.size += source->size;
247
3.00k
    ZYDIS_STRING_ASSERT_NULLTERMINATION(destination);
248
249
3.00k
    return ZYAN_STATUS_SUCCESS;
250
3.00k
}
FormatterIntel.c:ZydisStringAppendShort
Line
Count
Source
233
6.75k
{
234
6.75k
    ZYAN_ASSERT(destination && source);
235
6.75k
    ZYAN_ASSERT(!destination->vector.allocator);
236
6.75k
    ZYAN_ASSERT(destination->vector.size && source->size);
237
238
6.75k
    if (destination->vector.size + source->size > destination->vector.capacity)
239
155
    {
240
155
        return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
241
155
    }
242
243
6.59k
    ZYAN_MEMCPY((char*)destination->vector.data + destination->vector.size - 1, source->data,
244
6.59k
        (ZyanUSize)source->size + 1);
245
246
6.59k
    destination->vector.size += source->size;
247
6.59k
    ZYDIS_STRING_ASSERT_NULLTERMINATION(destination);
248
249
6.59k
    return ZYAN_STATUS_SUCCESS;
250
6.59k
}
Unexecuted instantiation: String.c:ZydisStringAppendShort
251
252
/**
253
 * Appends the content of the source short-string to the end of the destination string,
254
 * converting the characters to the specified letter-case.
255
 *
256
 * @param   destination The destination string.
257
 * @param   source      The source string.
258
 * @param   letter_case The desired letter-case.
259
 *
260
 * @return  A zyan status code.
261
 */
262
ZYAN_INLINE ZyanStatus ZydisStringAppendShortCase(ZyanString* destination,
263
    const ZydisShortString* source, ZydisLetterCase letter_case)
264
18.8k
{
265
18.8k
    ZYAN_ASSERT(destination && source);
266
18.8k
    ZYAN_ASSERT(!destination->vector.allocator);
267
18.8k
    ZYAN_ASSERT(destination->vector.size && source->size);
268
269
18.8k
    if (destination->vector.size + source->size > destination->vector.capacity)
270
789
    {
271
789
        return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
272
789
    }
273
274
18.0k
    ZYAN_MEMCPY((char*)destination->vector.data + destination->vector.size - 1, source->data,
275
18.0k
        (ZyanUSize)source->size + 1);
276
277
18.0k
    switch (letter_case)
278
18.0k
    {
279
5.31k
    case ZYDIS_LETTER_CASE_DEFAULT:
280
5.31k
        break;
281
0
    case ZYDIS_LETTER_CASE_LOWER:
282
0
    {
283
0
        const ZyanUSize index = destination->vector.size - 1;
284
0
        const ZyanUSize count = source->size;
285
0
        char* s = (char*)destination->vector.data + index;
286
0
        for (ZyanUSize i = index; i < index + count; ++i)
287
0
        {
288
0
            const char c = *s;
289
0
            if ((c >= 'A') && (c <= 'Z'))
290
0
            {
291
0
                *s = c | 32;
292
0
            }
293
0
            ++s;
294
0
        }
295
0
        break;
296
0
    }
297
12.6k
    case ZYDIS_LETTER_CASE_UPPER:
298
12.6k
    {
299
12.6k
        const ZyanUSize index = destination->vector.size - 1;
300
12.6k
        const ZyanUSize count = source->size;
301
12.6k
        char* s = (char*)destination->vector.data + index;
302
53.9k
        for (ZyanUSize i = index; i < index + count; ++i)
303
41.2k
        {
304
41.2k
            const char c = *s;
305
41.2k
            if ((c >= 'a') && (c <= 'z'))
306
36.6k
            {
307
36.6k
                *s = c & ~32;
308
36.6k
            }
309
41.2k
            ++s;
310
41.2k
        }
311
12.6k
        break;
312
0
    }
313
0
    default:
314
0
        ZYAN_UNREACHABLE;
315
18.0k
    }
316
317
18.0k
    destination->vector.size += source->size;
318
18.0k
    ZYDIS_STRING_ASSERT_NULLTERMINATION(destination);
319
320
18.0k
    return ZYAN_STATUS_SUCCESS;
321
18.0k
}
Unexecuted instantiation: Formatter.c:ZydisStringAppendShortCase
Unexecuted instantiation: FormatterBuffer.c:ZydisStringAppendShortCase
FormatterATT.c:ZydisStringAppendShortCase
Line
Count
Source
264
9.14k
{
265
9.14k
    ZYAN_ASSERT(destination && source);
266
9.14k
    ZYAN_ASSERT(!destination->vector.allocator);
267
9.14k
    ZYAN_ASSERT(destination->vector.size && source->size);
268
269
9.14k
    if (destination->vector.size + source->size > destination->vector.capacity)
270
388
    {
271
388
        return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
272
388
    }
273
274
8.75k
    ZYAN_MEMCPY((char*)destination->vector.data + destination->vector.size - 1, source->data,
275
8.75k
        (ZyanUSize)source->size + 1);
276
277
8.75k
    switch (letter_case)
278
8.75k
    {
279
2.49k
    case ZYDIS_LETTER_CASE_DEFAULT:
280
2.49k
        break;
281
0
    case ZYDIS_LETTER_CASE_LOWER:
282
0
    {
283
0
        const ZyanUSize index = destination->vector.size - 1;
284
0
        const ZyanUSize count = source->size;
285
0
        char* s = (char*)destination->vector.data + index;
286
0
        for (ZyanUSize i = index; i < index + count; ++i)
287
0
        {
288
0
            const char c = *s;
289
0
            if ((c >= 'A') && (c <= 'Z'))
290
0
            {
291
0
                *s = c | 32;
292
0
            }
293
0
            ++s;
294
0
        }
295
0
        break;
296
0
    }
297
6.26k
    case ZYDIS_LETTER_CASE_UPPER:
298
6.26k
    {
299
6.26k
        const ZyanUSize index = destination->vector.size - 1;
300
6.26k
        const ZyanUSize count = source->size;
301
6.26k
        char* s = (char*)destination->vector.data + index;
302
25.9k
        for (ZyanUSize i = index; i < index + count; ++i)
303
19.6k
        {
304
19.6k
            const char c = *s;
305
19.6k
            if ((c >= 'a') && (c <= 'z'))
306
17.8k
            {
307
17.8k
                *s = c & ~32;
308
17.8k
            }
309
19.6k
            ++s;
310
19.6k
        }
311
6.26k
        break;
312
0
    }
313
0
    default:
314
0
        ZYAN_UNREACHABLE;
315
8.75k
    }
316
317
8.75k
    destination->vector.size += source->size;
318
8.75k
    ZYDIS_STRING_ASSERT_NULLTERMINATION(destination);
319
320
8.75k
    return ZYAN_STATUS_SUCCESS;
321
8.75k
}
FormatterBase.c:ZydisStringAppendShortCase
Line
Count
Source
264
905
{
265
905
    ZYAN_ASSERT(destination && source);
266
905
    ZYAN_ASSERT(!destination->vector.allocator);
267
905
    ZYAN_ASSERT(destination->vector.size && source->size);
268
269
905
    if (destination->vector.size + source->size > destination->vector.capacity)
270
91
    {
271
91
        return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
272
91
    }
273
274
814
    ZYAN_MEMCPY((char*)destination->vector.data + destination->vector.size - 1, source->data,
275
814
        (ZyanUSize)source->size + 1);
276
277
814
    switch (letter_case)
278
814
    {
279
271
    case ZYDIS_LETTER_CASE_DEFAULT:
280
271
        break;
281
0
    case ZYDIS_LETTER_CASE_LOWER:
282
0
    {
283
0
        const ZyanUSize index = destination->vector.size - 1;
284
0
        const ZyanUSize count = source->size;
285
0
        char* s = (char*)destination->vector.data + index;
286
0
        for (ZyanUSize i = index; i < index + count; ++i)
287
0
        {
288
0
            const char c = *s;
289
0
            if ((c >= 'A') && (c <= 'Z'))
290
0
            {
291
0
                *s = c | 32;
292
0
            }
293
0
            ++s;
294
0
        }
295
0
        break;
296
0
    }
297
543
    case ZYDIS_LETTER_CASE_UPPER:
298
543
    {
299
543
        const ZyanUSize index = destination->vector.size - 1;
300
543
        const ZyanUSize count = source->size;
301
543
        char* s = (char*)destination->vector.data + index;
302
3.91k
        for (ZyanUSize i = index; i < index + count; ++i)
303
3.37k
        {
304
3.37k
            const char c = *s;
305
3.37k
            if ((c >= 'a') && (c <= 'z'))
306
2.23k
            {
307
2.23k
                *s = c & ~32;
308
2.23k
            }
309
3.37k
            ++s;
310
3.37k
        }
311
543
        break;
312
0
    }
313
0
    default:
314
0
        ZYAN_UNREACHABLE;
315
814
    }
316
317
814
    destination->vector.size += source->size;
318
814
    ZYDIS_STRING_ASSERT_NULLTERMINATION(destination);
319
320
814
    return ZYAN_STATUS_SUCCESS;
321
814
}
FormatterIntel.c:ZydisStringAppendShortCase
Line
Count
Source
264
8.75k
{
265
8.75k
    ZYAN_ASSERT(destination && source);
266
8.75k
    ZYAN_ASSERT(!destination->vector.allocator);
267
8.75k
    ZYAN_ASSERT(destination->vector.size && source->size);
268
269
8.75k
    if (destination->vector.size + source->size > destination->vector.capacity)
270
310
    {
271
310
        return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
272
310
    }
273
274
8.44k
    ZYAN_MEMCPY((char*)destination->vector.data + destination->vector.size - 1, source->data,
275
8.44k
        (ZyanUSize)source->size + 1);
276
277
8.44k
    switch (letter_case)
278
8.44k
    {
279
2.55k
    case ZYDIS_LETTER_CASE_DEFAULT:
280
2.55k
        break;
281
0
    case ZYDIS_LETTER_CASE_LOWER:
282
0
    {
283
0
        const ZyanUSize index = destination->vector.size - 1;
284
0
        const ZyanUSize count = source->size;
285
0
        char* s = (char*)destination->vector.data + index;
286
0
        for (ZyanUSize i = index; i < index + count; ++i)
287
0
        {
288
0
            const char c = *s;
289
0
            if ((c >= 'A') && (c <= 'Z'))
290
0
            {
291
0
                *s = c | 32;
292
0
            }
293
0
            ++s;
294
0
        }
295
0
        break;
296
0
    }
297
5.89k
    case ZYDIS_LETTER_CASE_UPPER:
298
5.89k
    {
299
5.89k
        const ZyanUSize index = destination->vector.size - 1;
300
5.89k
        const ZyanUSize count = source->size;
301
5.89k
        char* s = (char*)destination->vector.data + index;
302
24.1k
        for (ZyanUSize i = index; i < index + count; ++i)
303
18.2k
        {
304
18.2k
            const char c = *s;
305
18.2k
            if ((c >= 'a') && (c <= 'z'))
306
16.6k
            {
307
16.6k
                *s = c & ~32;
308
16.6k
            }
309
18.2k
            ++s;
310
18.2k
        }
311
5.89k
        break;
312
0
    }
313
0
    default:
314
0
        ZYAN_UNREACHABLE;
315
8.44k
    }
316
317
8.44k
    destination->vector.size += source->size;
318
8.44k
    ZYDIS_STRING_ASSERT_NULLTERMINATION(destination);
319
320
8.44k
    return ZYAN_STATUS_SUCCESS;
321
8.44k
}
Unexecuted instantiation: String.c:ZydisStringAppendShortCase
322
323
/* ---------------------------------------------------------------------------------------------- */
324
/* Formatting                                                                                     */
325
/* ---------------------------------------------------------------------------------------------- */
326
327
/**
328
 * Formats the given unsigned ordinal `value` to its decimal text-representation and
329
 * appends it to the `string`.
330
 *
331
 * @param   string          A pointer to the `ZyanString` instance.
332
 * @param   value           The value to append.
333
 * @param   padding_length  Padds the converted value with leading zeros, if the number of chars is
334
 *                          less than the `padding_length`.
335
 * @param   prefix          The string to use as prefix or `ZYAN_NULL`, if not needed.
336
 * @param   suffix          The string to use as suffix or `ZYAN_NULL`, if not needed.
337
 *
338
 * @return  A zyan status code.
339
 *
340
 * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified
341
 * `ZyanString` instance.
342
 */
343
ZyanStatus ZydisStringAppendDecU(ZyanString* string, ZyanU64 value, ZyanU8 padding_length,
344
    const ZyanStringView* prefix, const ZyanStringView* suffix);
345
346
/**
347
 * Formats the given signed ordinal `value` to its decimal text-representation and
348
 * appends it to the `string`.
349
 *
350
 * @param   string          A pointer to the `ZyanString` instance.
351
 * @param   value           The value to append.
352
 * @param   padding_length  Padds the converted value with leading zeros, if the number of chars is
353
 *                          less than the `padding_length`.
354
 * @param   force_sign      Enable this option to print the `+` sign for positive numbers.
355
 * @param   prefix          The string to use as prefix or `ZYAN_NULL`, if not needed.
356
 * @param   suffix          The string to use as suffix or `ZYAN_NULL`, if not needed.
357
 *
358
 * @return  A zyan status code.
359
 *
360
 * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified
361
 * `ZyanString` instance.
362
 */
363
ZYAN_INLINE ZyanStatus ZydisStringAppendDecS(ZyanString* string, ZyanI64 value,
364
    ZyanU8 padding_length, ZyanBool force_sign, const ZyanStringView* prefix,
365
    const ZyanStringView* suffix)
366
1.21k
{
367
1.21k
    static const ZydisShortString str_add = ZYDIS_MAKE_SHORTSTRING("+");
368
1.21k
    static const ZydisShortString str_sub = ZYDIS_MAKE_SHORTSTRING("-");
369
370
1.21k
    if (value < 0)
371
838
    {
372
838
        ZYAN_CHECK(ZydisStringAppendShort(string, &str_sub));
373
811
        if (prefix)
374
559
        {
375
559
            ZYAN_CHECK(ZydisStringAppend(string, prefix));
376
559
        }
377
729
        return ZydisStringAppendDecU(string, ZyanAbsI64(value), padding_length,
378
729
            (const ZyanStringView*)ZYAN_NULL, suffix);
379
811
    }
380
381
373
    if (force_sign)
382
254
    {
383
254
        ZYAN_ASSERT(value >= 0);
384
254
        ZYAN_CHECK(ZydisStringAppendShort(string, &str_add));
385
254
    }
386
360
    return ZydisStringAppendDecU(string, value, padding_length, prefix, suffix);
387
373
}
Unexecuted instantiation: Formatter.c:ZydisStringAppendDecS
Unexecuted instantiation: FormatterBuffer.c:ZydisStringAppendDecS
FormatterATT.c:ZydisStringAppendDecS
Line
Count
Source
366
320
{
367
320
    static const ZydisShortString str_add = ZYDIS_MAKE_SHORTSTRING("+");
368
320
    static const ZydisShortString str_sub = ZYDIS_MAKE_SHORTSTRING("-");
369
370
320
    if (value < 0)
371
201
    {
372
201
        ZYAN_CHECK(ZydisStringAppendShort(string, &str_sub));
373
188
        if (prefix)
374
133
        {
375
133
            ZYAN_CHECK(ZydisStringAppend(string, prefix));
376
133
        }
377
170
        return ZydisStringAppendDecU(string, ZyanAbsI64(value), padding_length,
378
170
            (const ZyanStringView*)ZYAN_NULL, suffix);
379
188
    }
380
381
119
    if (force_sign)
382
0
    {
383
0
        ZYAN_ASSERT(value >= 0);
384
0
        ZYAN_CHECK(ZydisStringAppendShort(string, &str_add));
385
0
    }
386
119
    return ZydisStringAppendDecU(string, value, padding_length, prefix, suffix);
387
119
}
FormatterBase.c:ZydisStringAppendDecS
Line
Count
Source
366
478
{
367
478
    static const ZydisShortString str_add = ZYDIS_MAKE_SHORTSTRING("+");
368
478
    static const ZydisShortString str_sub = ZYDIS_MAKE_SHORTSTRING("-");
369
370
478
    if (value < 0)
371
349
    {
372
349
        ZYAN_CHECK(ZydisStringAppendShort(string, &str_sub));
373
340
        if (prefix)
374
246
        {
375
246
            ZYAN_CHECK(ZydisStringAppend(string, prefix));
376
246
        }
377
313
        return ZydisStringAppendDecU(string, ZyanAbsI64(value), padding_length,
378
313
            (const ZyanStringView*)ZYAN_NULL, suffix);
379
340
    }
380
381
129
    if (force_sign)
382
129
    {
383
129
        ZYAN_ASSERT(value >= 0);
384
129
        ZYAN_CHECK(ZydisStringAppendShort(string, &str_add));
385
129
    }
386
119
    return ZydisStringAppendDecU(string, value, padding_length, prefix, suffix);
387
129
}
FormatterIntel.c:ZydisStringAppendDecS
Line
Count
Source
366
413
{
367
413
    static const ZydisShortString str_add = ZYDIS_MAKE_SHORTSTRING("+");
368
413
    static const ZydisShortString str_sub = ZYDIS_MAKE_SHORTSTRING("-");
369
370
413
    if (value < 0)
371
288
    {
372
288
        ZYAN_CHECK(ZydisStringAppendShort(string, &str_sub));
373
283
        if (prefix)
374
180
        {
375
180
            ZYAN_CHECK(ZydisStringAppend(string, prefix));
376
180
        }
377
246
        return ZydisStringAppendDecU(string, ZyanAbsI64(value), padding_length,
378
246
            (const ZyanStringView*)ZYAN_NULL, suffix);
379
283
    }
380
381
125
    if (force_sign)
382
125
    {
383
125
        ZYAN_ASSERT(value >= 0);
384
125
        ZYAN_CHECK(ZydisStringAppendShort(string, &str_add));
385
125
    }
386
122
    return ZydisStringAppendDecU(string, value, padding_length, prefix, suffix);
387
125
}
Unexecuted instantiation: String.c:ZydisStringAppendDecS
388
389
/**
390
 * Formats the given unsigned ordinal `value` to its hexadecimal text-representation and
391
 * appends it to the `string`.
392
 *
393
 * @param   string                  A pointer to the `ZyanString` instance.
394
 * @param   value                   The value to append.
395
 * @param   padding_length          Pads the converted value with leading zeros if the number of
396
 *                                  chars is less than the `padding_length`.
397
 * @param   force_leading_number    Enable this option to prepend a leading `0` if the first
398
 *                                  character is non-numeric.
399
 * @param   uppercase               Enable this option to use uppercase letters ('A'-'F') instead
400
 *                                  of lowercase ones ('a'-'f').
401
 * @param   prefix                  The string to use as prefix or `ZYAN_NULL`, if not needed.
402
 * @param   suffix                  The string to use as suffix or `ZYAN_NULL`, if not needed.
403
 *
404
 * @return  A zyan status code.
405
 *
406
 * This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified
407
 * `ZyanString` instance.
408
 */
409
ZyanStatus ZydisStringAppendHexU(ZyanString* string, ZyanU64 value, ZyanU8 padding_length,
410
    ZyanBool force_leading_number, ZyanBool uppercase, const ZyanStringView* prefix,
411
    const ZyanStringView* suffix);
412
413
/**
414
 * Formats the given signed ordinal `value` to its hexadecimal text-representation and
415
 * appends it to the `string`.
416
 *
417
 * @param   string                  A pointer to the `ZyanString` instance.
418
 * @param   value                   The value to append.
419
 * @param   padding_length          Padds the converted value with leading zeros, if the number of
420
 *                                  chars is less than the `padding_length` (the sign char does not
421
 *                                  count).
422
 * @param   force_leading_number    Enable this option to prepend a leading `0`, if the first
423
 *                                  character is non-numeric.
424
 * @param   uppercase               Enable this option to use uppercase letters ('A'-'F') instead
425
 *                                  of lowercase ones ('a'-'f').
426
 * @param   force_sign              Enable this option to print the `+` sign for positive numbers.
427
 * @param   prefix                  The string to use as prefix or `ZYAN_NULL`, if not needed.
428
 * @param   suffix                  The string to use as suffix or `ZYAN_NULL`, if not needed.
429
 *
430
 * @return  A zyan status code.
431
 *
432
 * This function will fail if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified
433
 * `ZyanString` instance.
434
 */
435
ZYAN_INLINE ZyanStatus ZydisStringAppendHexS(ZyanString* string, ZyanI64 value,
436
    ZyanU8 padding_length, ZyanBool force_leading_number, ZyanBool uppercase, ZyanBool force_sign,
437
    const ZyanStringView* prefix, const ZyanStringView* suffix)
438
892
{
439
892
    static const ZydisShortString str_add = ZYDIS_MAKE_SHORTSTRING("+");
440
892
    static const ZydisShortString str_sub = ZYDIS_MAKE_SHORTSTRING("-");
441
442
892
    if (value < 0)
443
590
    {
444
590
        ZYAN_CHECK(ZydisStringAppendShort(string, &str_sub));
445
565
        if (prefix)
446
408
        {
447
408
            ZYAN_CHECK(ZydisStringAppend(string, prefix));
448
408
        }
449
511
        return ZydisStringAppendHexU(string, ZyanAbsI64(value), padding_length,
450
511
            force_leading_number, uppercase, (const ZyanStringView*)ZYAN_NULL, suffix);
451
565
    }
452
453
302
    if (force_sign)
454
210
    {
455
210
        ZYAN_ASSERT(value >= 0);
456
210
        ZYAN_CHECK(ZydisStringAppendShort(string, &str_add));
457
210
    }
458
288
    return ZydisStringAppendHexU(string, value, padding_length, force_leading_number, uppercase,
459
288
        prefix, suffix);
460
302
}
Unexecuted instantiation: Formatter.c:ZydisStringAppendHexS
Unexecuted instantiation: FormatterBuffer.c:ZydisStringAppendHexS
FormatterATT.c:ZydisStringAppendHexS
Line
Count
Source
438
291
{
439
291
    static const ZydisShortString str_add = ZYDIS_MAKE_SHORTSTRING("+");
440
291
    static const ZydisShortString str_sub = ZYDIS_MAKE_SHORTSTRING("-");
441
442
291
    if (value < 0)
443
199
    {
444
199
        ZYAN_CHECK(ZydisStringAppendShort(string, &str_sub));
445
190
        if (prefix)
446
148
        {
447
148
            ZYAN_CHECK(ZydisStringAppend(string, prefix));
448
148
        }
449
174
        return ZydisStringAppendHexU(string, ZyanAbsI64(value), padding_length,
450
174
            force_leading_number, uppercase, (const ZyanStringView*)ZYAN_NULL, suffix);
451
190
    }
452
453
92
    if (force_sign)
454
0
    {
455
0
        ZYAN_ASSERT(value >= 0);
456
0
        ZYAN_CHECK(ZydisStringAppendShort(string, &str_add));
457
0
    }
458
92
    return ZydisStringAppendHexU(string, value, padding_length, force_leading_number, uppercase,
459
92
        prefix, suffix);
460
92
}
FormatterBase.c:ZydisStringAppendHexS
Line
Count
Source
438
407
{
439
407
    static const ZydisShortString str_add = ZYDIS_MAKE_SHORTSTRING("+");
440
407
    static const ZydisShortString str_sub = ZYDIS_MAKE_SHORTSTRING("-");
441
442
407
    if (value < 0)
443
290
    {
444
290
        ZYAN_CHECK(ZydisStringAppendShort(string, &str_sub));
445
276
        if (prefix)
446
185
        {
447
185
            ZYAN_CHECK(ZydisStringAppend(string, prefix));
448
185
        }
449
258
        return ZydisStringAppendHexU(string, ZyanAbsI64(value), padding_length,
450
258
            force_leading_number, uppercase, (const ZyanStringView*)ZYAN_NULL, suffix);
451
276
    }
452
453
117
    if (force_sign)
454
117
    {
455
117
        ZYAN_ASSERT(value >= 0);
456
117
        ZYAN_CHECK(ZydisStringAppendShort(string, &str_add));
457
117
    }
458
104
    return ZydisStringAppendHexU(string, value, padding_length, force_leading_number, uppercase,
459
104
        prefix, suffix);
460
117
}
FormatterIntel.c:ZydisStringAppendHexS
Line
Count
Source
438
194
{
439
194
    static const ZydisShortString str_add = ZYDIS_MAKE_SHORTSTRING("+");
440
194
    static const ZydisShortString str_sub = ZYDIS_MAKE_SHORTSTRING("-");
441
442
194
    if (value < 0)
443
101
    {
444
101
        ZYAN_CHECK(ZydisStringAppendShort(string, &str_sub));
445
99
        if (prefix)
446
75
        {
447
75
            ZYAN_CHECK(ZydisStringAppend(string, prefix));
448
75
        }
449
79
        return ZydisStringAppendHexU(string, ZyanAbsI64(value), padding_length,
450
79
            force_leading_number, uppercase, (const ZyanStringView*)ZYAN_NULL, suffix);
451
99
    }
452
453
93
    if (force_sign)
454
93
    {
455
93
        ZYAN_ASSERT(value >= 0);
456
93
        ZYAN_CHECK(ZydisStringAppendShort(string, &str_add));
457
93
    }
458
92
    return ZydisStringAppendHexU(string, value, padding_length, force_leading_number, uppercase,
459
92
        prefix, suffix);
460
93
}
Unexecuted instantiation: String.c:ZydisStringAppendHexS
461
462
/* ---------------------------------------------------------------------------------------------- */
463
464
/* ============================================================================================== */
465
466
#ifdef __cplusplus
467
}
468
#endif
469
470
#endif // ZYDIS_INTERNAL_STRING_H