Loading...
Searching...
No Matches
Format.h File Reference
`#include <Zycore/Status.h>`
`#include <Zycore/String.h>`
`#include <Zycore/Types.h>`
Include dependency graph for Format.h:

Go to the source code of this file.

## Functions

ZYAN_INLINE ZyanU64 | ZyanAbsI64 (ZyanI64 x)
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)
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus | ZyanStringAppendFormat (ZyanString *string, const char *format,...)
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)

## Detailed Description

Provides helper functions for performant number to string conversion.

## Function Documentation

## ZyanAbsI64()

ZYAN_INLINE ZyanU64 ZyanAbsI64 | ( | ZyanI64 | x | ) |

Get the absolute value of a 64 bit int.

Parameters

  x | The value to process.

Returns
  The absolute, unsigned value.

This gracefully deals with the special case of x being INT_MAX.

## ZyanStringAppendDecS()

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 string.

Parameters

  string | A pointer to the ZyanString instance.
  value | The value.
  padding_length | Padds the converted value with leading zeros, if the number of chars is less than the padding_length.
  force_sign | Set ZYAN_TRUE, to force printing of the + sign for positive numbers.
  prefix | The string to use as prefix or ZYAN_NULL, if not needed.

Returns
  A zyan status code.

This function will fail, if the ZYAN_STRING_IS_IMMUTABLE flag is set for the specified ZyanString instance.

## ZyanStringAppendDecU()

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 string.

Parameters

  string | A pointer to the ZyanString instance.
  value | The value.
  padding_length | Padds the converted value with leading zeros, if the number of chars is less than the padding_length.

Returns
  A zyan status code.

This function will fail, if the ZYAN_STRING_IS_IMMUTABLE flag is set for the specified ZyanString instance.

## ZyanStringAppendFormat()

ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanStringAppendFormat | ( | ZyanString * | string,
|  | const char * | format,
|  |  | ... )

Appends formatted text to the destination string.

Parameters

  string | The destination string.
  format | The format string.
  ... | The format arguments.

Returns
  A zyan status code.

This function will fail, if the ZYAN_STRING_IS_IMMUTABLE flag is set for the specified ZyanString instance.

## ZyanStringAppendHexS()

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 string.

Parameters

  string | A pointer to the ZyanString instance.
  value | The value.
  padding_length | Padds the converted value with leading zeros, if the number of chars is less than the padding_length.
  uppercase | Set ZYAN_TRUE to use uppercase letters ('A'-'F') instead of lowercase ones ('a'-'f').
  force_sign | Set ZYAN_TRUE, to force printing of the + sign for positive numbers.
  prefix | The string to use as prefix or ZYAN_NULL, if not needed.

Returns
  A zyan status code.

This function will fail, if the ZYAN_STRING_IS_IMMUTABLE flag is set for the specified ZyanString instance.

## ZyanStringAppendHexU()

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 string.

Parameters

  string | A pointer to the ZyanString instance.
  value | The value.
  padding_length | Padds the converted value with leading zeros, if the number of chars is less than the padding_length.
  uppercase | Set ZYAN_TRUE to use uppercase letters ('A'-'F') instead of lowercase ones ('a'-'f').

Returns
  A zyan status code.

This function will fail, if the ZYAN_STRING_IS_IMMUTABLE flag is set for the specified ZyanString instance.

## ZyanStringInsertDecS()

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 string.

Parameters

  string | A pointer to the ZyanString instance.
  index | The insert index.
  value | The value.
  padding_length | Padds the converted value with leading zeros, if the number of chars is less than the padding_length.
  force_sign | Set ZYAN_TRUE, to force printing of the + sign for positive numbers.
  prefix | The string to use as prefix or ZYAN_NULL, if not needed.

Returns
  A zyan status code.

This function will fail, if the ZYAN_STRING_IS_IMMUTABLE flag is set for the specified ZyanString instance.

## ZyanStringInsertDecU()

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 string.

Parameters

  string | A pointer to the ZyanString instance.
  index | The insert index.
  value | The value.
  padding_length | Padds the converted value with leading zeros, if the number of chars is less than the padding_length.

Returns
  A zyan status code.

This function will fail, if the ZYAN_STRING_IS_IMMUTABLE flag is set for the specified ZyanString instance.

## ZyanStringInsertFormat()

ZYCORE_EXPORT ZyanStatus ZyanStringInsertFormat | ( | ZyanString * | string,
|  | ZyanUSize | index,
|  | const char * | format,
|  |  | ... )

Inserts formatted text in the destination string at the given index.

Parameters

  string | The destination string.
  index | The insert index.
  format | The format string.
  ... | The format arguments.

Returns
  A zyan status code.

This function will fail, if the ZYAN_STRING_IS_IMMUTABLE flag is set for the specified ZyanString instance.

## ZyanStringInsertHexS()

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 string.

Parameters

  string | A pointer to the ZyanString instance.
  index | The insert index.
  value | The value.
  padding_length | Padds the converted value with leading zeros, if the number of chars is less than the padding_length.
  uppercase | Set ZYAN_TRUE to use uppercase letters ('A'-'F') instead of lowercase ones ('a'-'f').
  force_sign | Set ZYAN_TRUE, to force printing of the + sign for positive numbers.
  prefix | The string to use as prefix or ZYAN_NULL, if not needed.

Returns
  A zyan status code.

This function will fail, if the ZYAN_STRING_IS_IMMUTABLE flag is set for the specified ZyanString instance.

## ZyanStringInsertHexU()

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 string.

Parameters

  string | A pointer to the ZyanString instance.
  index | The insert index.
  value | The value.
  padding_length | Padds the converted value with leading zeros, if the number of chars is less than the padding_length.
  uppercase | Set ZYAN_TRUE to use uppercase letters ('A'-'F') instead of lowercase ones ('a'-'f').

Returns
  A zyan status code.

This function will fail, if the ZYAN_STRING_IS_IMMUTABLE flag is set for the specified ZyanString instance.