Zycore 1.5.2
Zyan Core Library for C
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
31
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
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
111 ZyanU8 padding_length);
112
131 ZyanU8 padding_length, ZyanBool force_sign, const ZyanString* prefix);
132
151 ZyanU8 padding_length, ZyanBool uppercase);
152
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)
Decorator for printf-style functions.
Definition Defines.h:483
#define ZYAN_INLINE
Definition Defines.h:356
#define ZYAN_REQUIRES_LIBC
Marks functions that require libc (cannot be used with ZYAN_NO_LIBC).
Definition Defines.h:468
#define ZYCORE_EXPORT
Symbol is exported in shared library builds.
Definition Defines.h:330
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringAppendFormat(ZyanString *string, const char *format,...)
Appends formatted text to the destination string.
ZYCORE_EXPORT ZyanStatus ZyanStringInsertHexS(ZyanString *string, ZyanUSize index, ZyanI64 value, ZyanU8 padding_length, ZyanBool uppercase, ZyanBool force_sign, const ZyanString *prefix)
Formats the given signed ordinal value to its hexadecimal text-representation and inserts it to the s...
ZYCORE_EXPORT ZyanStatus ZyanStringAppendHexS(ZyanString *string, ZyanI64 value, ZyanU8 padding_length, ZyanBool uppercase, ZyanBool force_sign, const ZyanStringView *prefix)
Formats the given signed ordinal value to its hexadecimal text-representation and appends it to the s...
ZYCORE_EXPORT ZyanStatus ZyanStringAppendDecS(ZyanString *string, ZyanI64 value, ZyanU8 padding_length, ZyanBool force_sign, const ZyanStringView *prefix)
Formats the given signed ordinal value to its decimal text-representation and appends it to the strin...
ZYCORE_EXPORT ZyanStatus ZyanStringAppendDecU(ZyanString *string, ZyanU64 value, ZyanU8 padding_length)
Formats the given unsigned ordinal value to its decimal text-representation and appends it to the str...
ZYCORE_EXPORT ZyanStatus ZyanStringInsertDecU(ZyanString *string, ZyanUSize index, ZyanU64 value, ZyanU8 padding_length)
Formats the given unsigned ordinal value to its decimal text-representation and inserts it to the str...
ZYCORE_EXPORT ZyanStatus ZyanStringInsertDecS(ZyanString *string, ZyanUSize index, ZyanI64 value, ZyanU8 padding_length, ZyanBool force_sign, const ZyanString *prefix)
Formats the given signed ordinal value to its decimal text-representation and inserts it to the strin...
ZYCORE_EXPORT ZyanStatus ZyanStringAppendHexU(ZyanString *string, ZyanU64 value, ZyanU8 padding_length, ZyanBool uppercase)
Formats the given unsigned ordinal value to its hexadecimal text-representation and appends it to the...
ZYCORE_EXPORT ZyanStatus ZyanStringInsertFormat(ZyanString *string, ZyanUSize index, const char *format,...)
Inserts formatted text in the destination string at the given index.
ZYCORE_EXPORT ZyanStatus ZyanStringInsertHexU(ZyanString *string, ZyanUSize index, ZyanU64 value, ZyanU8 padding_length, ZyanBool uppercase)
Formats the given unsigned ordinal value to its hexadecimal text-representation and inserts it to the...
ZYAN_INLINE ZyanU64 ZyanAbsI64(ZyanI64 x)
Get the absolute value of a 64 bit int.
Definition Format.h:59
Status code definitions and check macros.
ZyanU32 ZyanStatus
Defines the ZyanStatus data type.
Definition Status.h:48
Implements a string type.
struct ZyanStringView_ ZyanStringView
Defines the ZyanStringView struct.
struct ZyanString_ ZyanString
Defines the ZyanString struct.
Includes and defines some default data types.
ZyanU8 ZyanBool
Defines the ZyanBool data-type.
Definition Types.h:296
int64_t ZyanI64
Definition Types.h:223
size_t ZyanUSize
Definition Types.h:224
uint64_t ZyanU64
Definition Types.h:219
uint8_t ZyanU8
Definition Types.h:216