Loading...
Searching...
No Matches
Format.h
Go to the documentation of this file.
/***************************************************************************************************
Zyan Core Library (Zycore-C)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
#ifndef ZYCORE_FORMAT_H
#define ZYCORE_FORMAT_H
#include <Zycore/Status.h>
#include <Zycore/String.h>
#include <Zycore/Types.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Helpers */
/* ---------------------------------------------------------------------------------------------- */
ZYAN_INLINE ZyanU64 ZyanAbsI64(ZyanI64 x)
{
// INT_MIN special case. Can't use the value directly because GCC thinks
// it's too big for an INT64 literal, however is perfectly happy to accept
// this expression. This is also hit INT64_MIN is defined in `stdint.h`.
if (x == (-0x7fffffffffffffff - 1))
{
return 0x8000000000000000u;
}
return (ZyanU64)(x < 0 ? -x : x);
}
/* ---------------------------------------------------------------------------------------------- */
/* Insertion */
/* ---------------------------------------------------------------------------------------------- */
ZYAN_PRINTF_ATTR(3, 4)
ZYCORE_EXPORT ZyanStatus ZyanStringInsertFormat(ZyanString* string, ZyanUSize index,
const char* format, ...);
/* ---------------------------------------------------------------------------------------------- */
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 ZyanStringInsertHexU(ZyanString* string, ZyanUSize index, ZyanU64 value,
ZyanU8 padding_length, ZyanBool uppercase);
ZYCORE_EXPORT ZyanStatus ZyanStringInsertHexS(ZyanString* string, ZyanUSize index, ZyanI64 value,
ZyanU8 padding_length, ZyanBool uppercase, ZyanBool force_sign, const ZyanString* prefix);
/* ---------------------------------------------------------------------------------------------- */
/* Appending */
/* ---------------------------------------------------------------------------------------------- */
#ifndef ZYAN_NO_LIBC
ZYAN_PRINTF_ATTR(2, 3)
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringAppendFormat(
ZyanString* string, const char* format, ...);
#endif // ZYAN_NO_LIBC
/* ---------------------------------------------------------------------------------------------- */
ZYCORE_EXPORT ZyanStatus ZyanStringAppendDecU(ZyanString* string, ZyanU64 value,
ZyanU8 padding_length);
ZYCORE_EXPORT ZyanStatus ZyanStringAppendDecS(ZyanString* string, ZyanI64 value,
ZyanU8 padding_length, ZyanBool force_sign, const ZyanStringView* prefix);
ZYCORE_EXPORT ZyanStatus ZyanStringAppendHexU(ZyanString* string, ZyanU64 value,
ZyanU8 padding_length, ZyanBool uppercase);
ZYCORE_EXPORT ZyanStatus ZyanStringAppendHexS(ZyanString* string, ZyanI64 value,
ZyanU8 padding_length, ZyanBool uppercase, ZyanBool force_sign, const ZyanStringView* prefix);
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif // ZYCORE_FORMAT_H
ZYAN_PRINTF_ATTR
#define ZYAN_PRINTF_ATTR(format_index, first_to_check)
Definition Defines.h:397
ZYAN_REQUIRES_LIBC
#define ZYAN_REQUIRES_LIBC
Definition Defines.h:382
ZYCORE_EXPORT
#define ZYCORE_EXPORT
Definition Defines.h:244
ZyanStringAppendFormat
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringAppendFormat(ZyanString *string, const char *format,...)
ZyanStringInsertHexS
ZYCORE_EXPORT ZyanStatus ZyanStringInsertHexS(ZyanString *string, ZyanUSize index, ZyanI64 value, ZyanU8 padding_length, ZyanBool uppercase, ZyanBool force_sign, const ZyanString *prefix)
ZyanStringAppendHexS
ZYCORE_EXPORT ZyanStatus ZyanStringAppendHexS(ZyanString *string, ZyanI64 value, ZyanU8 padding_length, ZyanBool uppercase, ZyanBool force_sign, const ZyanStringView *prefix)
ZyanStringAppendDecS
ZYCORE_EXPORT ZyanStatus ZyanStringAppendDecS(ZyanString *string, ZyanI64 value, ZyanU8 padding_length, ZyanBool force_sign, const ZyanStringView *prefix)
ZyanStringAppendDecU
ZYCORE_EXPORT ZyanStatus ZyanStringAppendDecU(ZyanString *string, ZyanU64 value, ZyanU8 padding_length)
ZyanStringInsertDecU
ZYCORE_EXPORT ZyanStatus ZyanStringInsertDecU(ZyanString *string, ZyanUSize index, ZyanU64 value, ZyanU8 padding_length)
ZyanStringInsertDecS
ZYCORE_EXPORT ZyanStatus ZyanStringInsertDecS(ZyanString *string, ZyanUSize index, ZyanI64 value, ZyanU8 padding_length, ZyanBool force_sign, const ZyanString *prefix)
ZyanStringAppendHexU
ZYCORE_EXPORT ZyanStatus ZyanStringAppendHexU(ZyanString *string, ZyanU64 value, ZyanU8 padding_length, ZyanBool uppercase)
ZyanStringInsertFormat
ZYCORE_EXPORT ZyanStatus ZyanStringInsertFormat(ZyanString *string, ZyanUSize index, const char *format,...)
ZyanStringInsertHexU
ZYCORE_EXPORT ZyanStatus ZyanStringInsertHexU(ZyanString *string, ZyanUSize index, ZyanU64 value, ZyanU8 padding_length, ZyanBool uppercase)
ZyanAbsI64
ZYAN_INLINE ZyanU64 ZyanAbsI64(ZyanI64 x)
Definition Format.h:59
Status.h
ZyanStatus
ZyanU32 ZyanStatus
Definition Status.h:48
String.h
ZyanStringView
struct ZyanStringView_ ZyanStringView
ZyanString
struct ZyanString_ ZyanString
Types.h
ZyanBool
ZyanU8 ZyanBool
Definition Types.h:296