Zycore 1.4.0.0
Loading...
Searching...
No Matches
Format.h
Go to the documentation of this file.
1/***************************************************************************************************
2
3 Zyan Core Library (Zycore-C)
4
5 Original Author : Florian Bernd
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
32#ifndef ZYCORE_FORMAT_H
33#define ZYCORE_FORMAT_H
34
35#include <Zycore/Status.h>
36#include <Zycore/String.h>
37#include <Zycore/Types.h>
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/* ============================================================================================== */
44/* Exported functions */
45/* ============================================================================================== */
46
47/* ---------------------------------------------------------------------------------------------- */
48/* Helpers */
49/* ---------------------------------------------------------------------------------------------- */
50
59ZYAN_INLINE ZyanU64 ZyanAbsI64(ZyanI64 x)
60{
61 // INT_MIN special case. Can't use the value directly because GCC thinks
62 // it's too big for an INT64 literal, however is perfectly happy to accept
63 // this expression. This is also hit INT64_MIN is defined in `stdint.h`.
64 if (x == (-0x7fffffffffffffff - 1))
65 {
66 return 0x8000000000000000u;
67 }
68
69 return (ZyanU64)(x < 0 ? -x : x);
70}
71
72/* ---------------------------------------------------------------------------------------------- */
73/* Insertion */
74/* ---------------------------------------------------------------------------------------------- */
75
91 const char* format, ...);
92
93/* ---------------------------------------------------------------------------------------------- */
94
110ZYCORE_EXPORT ZyanStatus ZyanStringInsertDecU(ZyanString* string, ZyanUSize index, ZyanU64 value,
111 ZyanU8 padding_length);
112
130ZYCORE_EXPORT ZyanStatus ZyanStringInsertDecS(ZyanString* string, ZyanUSize index, ZyanI64 value,
131 ZyanU8 padding_length, ZyanBool force_sign, const ZyanString* prefix);
132
150ZYCORE_EXPORT ZyanStatus ZyanStringInsertHexU(ZyanString* string, ZyanUSize index, ZyanU64 value,
151 ZyanU8 padding_length, ZyanBool uppercase);
152
172ZYCORE_EXPORT ZyanStatus ZyanStringInsertHexS(ZyanString* string, ZyanUSize index, ZyanI64 value,
173 ZyanU8 padding_length, ZyanBool uppercase, ZyanBool force_sign, const ZyanString* prefix);
174
175/* ---------------------------------------------------------------------------------------------- */
176/* Appending */
177/* ---------------------------------------------------------------------------------------------- */
178
179#ifndef ZYAN_NO_LIBC
180
195 ZyanString* string, const char* format, ...);
196
197#endif // ZYAN_NO_LIBC
198
199/* ---------------------------------------------------------------------------------------------- */
200
216 ZyanU8 padding_length);
217
235 ZyanU8 padding_length, ZyanBool force_sign, const ZyanStringView* prefix);
236
254 ZyanU8 padding_length, ZyanBool uppercase);
255
275 ZyanU8 padding_length, ZyanBool uppercase, ZyanBool force_sign, const ZyanStringView* prefix);
276
277/* ---------------------------------------------------------------------------------------------- */
278
279/* ============================================================================================== */
280
281#ifdef __cplusplus
282}
283#endif
284
285#endif // ZYCORE_FORMAT_H
#define ZYAN_PRINTF_ATTR(format_index, first_to_check)
Definition Defines.h:373
#define ZYAN_REQUIRES_LIBC
Definition Defines.h:358
#define ZYCORE_EXPORT
Definition Defines.h:227
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringAppendFormat(ZyanString *string, const char *format,...)
ZYCORE_EXPORT ZyanStatus ZyanStringInsertHexS(ZyanString *string, ZyanUSize index, ZyanI64 value, ZyanU8 padding_length, ZyanBool uppercase, ZyanBool force_sign, const ZyanString *prefix)
ZYCORE_EXPORT ZyanStatus ZyanStringAppendHexS(ZyanString *string, ZyanI64 value, ZyanU8 padding_length, ZyanBool uppercase, ZyanBool force_sign, const ZyanStringView *prefix)
ZYCORE_EXPORT ZyanStatus ZyanStringAppendDecS(ZyanString *string, ZyanI64 value, ZyanU8 padding_length, ZyanBool force_sign, const ZyanStringView *prefix)
ZYCORE_EXPORT ZyanStatus ZyanStringAppendDecU(ZyanString *string, ZyanU64 value, ZyanU8 padding_length)
ZYCORE_EXPORT ZyanStatus ZyanStringInsertDecU(ZyanString *string, ZyanUSize index, ZyanU64 value, ZyanU8 padding_length)
ZYCORE_EXPORT ZyanStatus ZyanStringInsertDecS(ZyanString *string, ZyanUSize index, ZyanI64 value, ZyanU8 padding_length, ZyanBool force_sign, const ZyanString *prefix)
ZYCORE_EXPORT ZyanStatus ZyanStringAppendHexU(ZyanString *string, ZyanU64 value, ZyanU8 padding_length, ZyanBool uppercase)
ZYCORE_EXPORT ZyanStatus ZyanStringInsertFormat(ZyanString *string, ZyanUSize index, const char *format,...)
ZYCORE_EXPORT ZyanStatus ZyanStringInsertHexU(ZyanString *string, ZyanUSize index, ZyanU64 value, ZyanU8 padding_length, ZyanBool uppercase)
ZYAN_INLINE ZyanU64 ZyanAbsI64(ZyanI64 x)
Definition Format.h:59
ZyanU32 ZyanStatus
Definition Status.h:48
ZyanU8 ZyanBool
Definition Types.h:192
Definition String.h:132
Definition String.h:98