Tapkee
formatting Namespace Reference

Namespaces

 internal
 
 utils
 
 wrappers
 

Classes

class  formatting_error
 
class  ValueWrapper
 

Functions

std::string format (const std::string &fmt, const ValueWrapper a)
 
std::string format (const std::string &fmt, const ValueWrapper a, const ValueWrapper b)
 
std::string format (const std::string &fmt, const ValueWrapper a, const ValueWrapper b, const ValueWrapper c)
 
std::string format (const std::string &fmt, const ValueWrapper a, const ValueWrapper b, const ValueWrapper c, const ValueWrapper d)
 
std::string format (const std::string &fmt, const ValueWrapper a, const ValueWrapper b, const ValueWrapper c, const ValueWrapper d, const ValueWrapper e)
 
std::string format (const std::string &fmt, const ValueWrapper a, const ValueWrapper b, const ValueWrapper c, const ValueWrapper d, const ValueWrapper e, const ValueWrapper f)
 
std::string format (const std::string &fmt, const ValueWrapper a, const ValueWrapper b, const ValueWrapper c, const ValueWrapper d, const ValueWrapper e, const ValueWrapper f, const ValueWrapper g)
 
std::string format (const std::string &fmt, const ValueWrapper a, const ValueWrapper b, const ValueWrapper c, const ValueWrapper d, const ValueWrapper e, const ValueWrapper f, const ValueWrapper g, const ValueWrapper h)
 
std::string format (const std::string &fmt, const ValueWrapper a, const ValueWrapper b, const ValueWrapper c, const ValueWrapper d, const ValueWrapper e, const ValueWrapper f, const ValueWrapper g, const ValueWrapper h, const ValueWrapper i)
 
std::string format (const std::string &fmt, const ValueWrapper a, const ValueWrapper b, const ValueWrapper c, const ValueWrapper d, const ValueWrapper e, const ValueWrapper f, const ValueWrapper g, const ValueWrapper h, const ValueWrapper i, const ValueWrapper j)
 
template<typename T >
wrappers::HexWrapper< T > hex (T value)
 
template<typename T >
wrappers::OctWrapper< T > oct (T value)
 
wrappers::HexWrapper< size_t > raw (void *value)
 
wrappers::HexWrapper< size_t > raw (const void *value)
 

Variables

static const int WORLD_VERSION = 0
 
static const int MAJOR_VERSION = 1
 
static const int MINOR_VERSION = 2
 
const std::string placeholder = "{}"
 
static unsigned int default_precision = 9
 
static const wrappers::WidthWrapperBuilderHelper width
 
static const wrappers::PrecisionWrapperBuilderHelper precision
 

Detailed Description

A simple formatter that uses simple "{}" placeholder. Resembles SLF4J and Python format.

Copyright (c) 2013, Sergey Lisitsyn lisit.nosp@m.syn..nosp@m.s.o@g.nosp@m.mail.nosp@m..com All rights reserved.

Distributed under the BSD 2-clause license:

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

◆ format() [1/10]

std::string format ( const std::string &  fmt,
const ValueWrapper  a 
)

Constructs a string using the provided formatting string and arguments. Essentially, replaces all placeholders ("{}") in the string with the corresponding string representations of provided arguments (in the same order).

This function performs substitution of one variable.

Doesn't change the formatting string. Uses no shared state thus supposed to be thread-safe.

Parameters
fmtthe formatting string that contains one {} placeholder.
aany variable which type has the stream insertion operator (operator<<) implemented.
Returns
new string with provided parameters put instead of placeholders to the provided formatting string.
Exceptions
formatting_errorin case the number of placeholders doesn't match the number of provided parameters

Definition at line 411 of file formatting.hpp.

◆ format() [2/10]

std::string format ( const std::string &  fmt,
const ValueWrapper  a,
const ValueWrapper  b 
)

Constructs a string using the provided formatting string and arguments. Essentially, replaces all placeholders ("{}") in the string with the corresponding string representations of provided arguments (in the same order).

This function performs substitution of one variable.

Doesn't change the formatting string. Uses no shared state thus supposed to be thread-safe.

Parameters
fmtthe formatting string that contains 2 {} placeholders.
aany variable which type has the stream insertion operator (operator<<) implemented.
bany variable which type has the stream insertion operator (operator<<) implemented.
Returns
new string with provided parameters put instead of placeholders to the provided formatting string.
Exceptions
formatting_errorin case the number of placeholders doesn't match the number of provided parameters

Definition at line 418 of file formatting.hpp.

◆ format() [3/10]

std::string format ( const std::string &  fmt,
const ValueWrapper  a,
const ValueWrapper  b,
const ValueWrapper  c 
)

Constructs a string using the provided formatting string and arguments. Essentially, replaces all placeholders ("{}") in the string with the corresponding string representations of provided arguments (in the same order).

This function performs substitution of one variable.

Doesn't change the formatting string. Uses no shared state thus supposed to be thread-safe.

Parameters
fmtthe formatting string that contains 3 {} placeholders.
aany variable which type has the stream insertion operator (operator<<) implemented.
bany variable which type has the stream insertion operator (operator<<) implemented.
cany variable which type has the stream insertion operator (operator<<) implemented.
Returns
new string with provided parameters put instead of placeholders to the provided formatting string.
Exceptions
formatting_errorin case the number of placeholders doesn't match the number of provided parameters

Definition at line 425 of file formatting.hpp.

◆ format() [4/10]

std::string format ( const std::string &  fmt,
const ValueWrapper  a,
const ValueWrapper  b,
const ValueWrapper  c,
const ValueWrapper  d 
)

Constructs a string using the provided formatting string and arguments. Essentially, replaces all placeholders ("{}") in the string with the corresponding string representations of provided arguments (in the same order).

This function performs substitution of one variable.

Doesn't change the formatting string. Uses no shared state thus supposed to be thread-safe.

Parameters
fmtthe formatting string that contains 4 {} placeholders.
aany variable which type has the stream insertion operator (operator<<) implemented.
bany variable which type has the stream insertion operator (operator<<) implemented.
cany variable which type has the stream insertion operator (operator<<) implemented.
dany variable which type has the stream insertion operator (operator<<) implemented.
Returns
new string with provided parameters put instead of placeholders to the provided formatting string.
Exceptions
formatting_errorin case the number of placeholders doesn't match the number of provided parameters

Definition at line 433 of file formatting.hpp.

◆ format() [5/10]

std::string format ( const std::string &  fmt,
const ValueWrapper  a,
const ValueWrapper  b,
const ValueWrapper  c,
const ValueWrapper  d,
const ValueWrapper  e 
)

Constructs a string using the provided formatting string and arguments. Essentially, replaces all placeholders ("{}") in the string with the corresponding string representations of provided arguments (in the same order).

This function performs substitution of one variable.

Doesn't change the formatting string. Uses no shared state thus supposed to be thread-safe.

Parameters
fmtthe formatting string that contains 5 {} placeholders.
aany variable which type has the stream insertion operator (operator<<) implemented.
bany variable which type has the stream insertion operator (operator<<) implemented.
cany variable which type has the stream insertion operator (operator<<) implemented.
dany variable which type has the stream insertion operator (operator<<) implemented.
eany variable which type has the stream insertion operator (operator<<) implemented.
Returns
new string with provided parameters put instead of placeholders to the provided formatting string.
Exceptions
formatting_errorin case the number of placeholders doesn't match the number of provided parameters

Definition at line 441 of file formatting.hpp.

◆ format() [6/10]

std::string format ( const std::string &  fmt,
const ValueWrapper  a,
const ValueWrapper  b,
const ValueWrapper  c,
const ValueWrapper  d,
const ValueWrapper  e,
const ValueWrapper  f 
)

Constructs a string using the provided formatting string and arguments. Essentially, replaces all placeholders ("{}") in the string with the corresponding string representations of provided arguments (in the same order).

This function performs substitution of one variable.

Doesn't change the formatting string. Uses no shared state thus supposed to be thread-safe.

Parameters
fmtthe formatting string that contains 6 {} placeholders.
aany variable which type has the stream insertion operator (operator<<) implemented.
bany variable which type has the stream insertion operator (operator<<) implemented.
cany variable which type has the stream insertion operator (operator<<) implemented.
dany variable which type has the stream insertion operator (operator<<) implemented.
eany variable which type has the stream insertion operator (operator<<) implemented.
fany variable which type has the stream insertion operator (operator<<) implemented.
Returns
new string with provided parameters put instead of placeholders to the provided formatting string.
Exceptions
formatting_errorin case the number of placeholders doesn't match the number of provided parameters

Definition at line 450 of file formatting.hpp.

◆ format() [7/10]

std::string format ( const std::string &  fmt,
const ValueWrapper  a,
const ValueWrapper  b,
const ValueWrapper  c,
const ValueWrapper  d,
const ValueWrapper  e,
const ValueWrapper  f,
const ValueWrapper  g 
)

Constructs a string using the provided formatting string and arguments. Essentially, replaces all placeholders ("{}") in the string with the corresponding string representations of provided arguments (in the same order).

This function performs substitution of one variable.

Doesn't change the formatting string. Uses no shared state thus supposed to be thread-safe.

Parameters
fmtthe formatting string that contains 7 {} placeholders.
aany variable which type has the stream insertion operator (operator<<) implemented.
bany variable which type has the stream insertion operator (operator<<) implemented.
cany variable which type has the stream insertion operator (operator<<) implemented.
dany variable which type has the stream insertion operator (operator<<) implemented.
eany variable which type has the stream insertion operator (operator<<) implemented.
fany variable which type has the stream insertion operator (operator<<) implemented.
gany variable which type has the stream insertion operator (operator<<) implemented.
Returns
new string with provided parameters put instead of placeholders to the provided formatting string.
Exceptions
formatting_errorin case the number of placeholders doesn't match the number of provided parameters

Definition at line 459 of file formatting.hpp.

◆ format() [8/10]

std::string format ( const std::string &  fmt,
const ValueWrapper  a,
const ValueWrapper  b,
const ValueWrapper  c,
const ValueWrapper  d,
const ValueWrapper  e,
const ValueWrapper  f,
const ValueWrapper  g,
const ValueWrapper  h 
)

Constructs a string using the provided formatting string and arguments. Essentially, replaces all placeholders ("{}") in the string with the corresponding string representations of provided arguments (in the same order).

This function performs substitution of one variable.

Doesn't change the formatting string. Uses no shared state thus supposed to be thread-safe.

Parameters
fmtthe formatting string that contains 8 {} placeholders.
aany variable which type has the stream insertion operator (operator<<) implemented.
bany variable which type has the stream insertion operator (operator<<) implemented.
cany variable which type has the stream insertion operator (operator<<) implemented.
dany variable which type has the stream insertion operator (operator<<) implemented.
eany variable which type has the stream insertion operator (operator<<) implemented.
fany variable which type has the stream insertion operator (operator<<) implemented.
gany variable which type has the stream insertion operator (operator<<) implemented.
hany variable which type has the stream insertion operator (operator<<) implemented.
Returns
new string with provided parameters put instead of placeholders to the provided formatting string.
Exceptions
formatting_errorin case the number of placeholders doesn't match the number of provided parameters

Definition at line 469 of file formatting.hpp.

◆ format() [9/10]

std::string format ( const std::string &  fmt,
const ValueWrapper  a,
const ValueWrapper  b,
const ValueWrapper  c,
const ValueWrapper  d,
const ValueWrapper  e,
const ValueWrapper  f,
const ValueWrapper  g,
const ValueWrapper  h,
const ValueWrapper  i 
)

Constructs a string using the provided formatting string and arguments. Essentially, replaces all placeholders ("{}") in the string with the corresponding string representations of provided arguments (in the same order).

This function performs substitution of one variable.

Doesn't change the formatting string. Uses no shared state thus supposed to be thread-safe.

Parameters
fmtthe formatting string that contains 9 {} placeholders.
aany variable which type has the stream insertion operator (operator<<) implemented.
bany variable which type has the stream insertion operator (operator<<) implemented.
cany variable which type has the stream insertion operator (operator<<) implemented.
dany variable which type has the stream insertion operator (operator<<) implemented.
eany variable which type has the stream insertion operator (operator<<) implemented.
fany variable which type has the stream insertion operator (operator<<) implemented.
gany variable which type has the stream insertion operator (operator<<) implemented.
hany variable which type has the stream insertion operator (operator<<) implemented.
iany variable which type has the stream insertion operator (operator<<) implemented.
Returns
new string with provided parameters put instead of placeholders to the provided formatting string.
Exceptions
formatting_errorin case the number of placeholders doesn't match the number of provided parameters

Definition at line 479 of file formatting.hpp.

◆ format() [10/10]

std::string format ( const std::string &  fmt,
const ValueWrapper  a,
const ValueWrapper  b,
const ValueWrapper  c,
const ValueWrapper  d,
const ValueWrapper  e,
const ValueWrapper  f,
const ValueWrapper  g,
const ValueWrapper  h,
const ValueWrapper  i,
const ValueWrapper  j 
)

Constructs a string using the provided formatting string and arguments. Essentially, replaces all placeholders ("{}") in the string with the corresponding string representations of provided arguments (in the same order).

This function performs substitution of one variable.

Doesn't change the formatting string. Uses no shared state thus supposed to be thread-safe.

Parameters
fmtthe formatting string that contains 10 {} placeholders.
aany variable which type has the stream insertion operator (operator<<) implemented.
bany variable which type has the stream insertion operator (operator<<) implemented.
cany variable which type has the stream insertion operator (operator<<) implemented.
dany variable which type has the stream insertion operator (operator<<) implemented.
eany variable which type has the stream insertion operator (operator<<) implemented.
fany variable which type has the stream insertion operator (operator<<) implemented.
gany variable which type has the stream insertion operator (operator<<) implemented.
hany variable which type has the stream insertion operator (operator<<) implemented.
iany variable which type has the stream insertion operator (operator<<) implemented.
jany variable which type has the stream insertion operator (operator<<) implemented.
Returns
new string with provided parameters put instead of placeholders to the provided formatting string.
Exceptions
formatting_errorin case the number of placeholders doesn't match the number of provided parameters

Definition at line 490 of file formatting.hpp.

◆ hex()

wrappers::HexWrapper<T> formatting::hex ( value)

Returns a wrapper that makes the provided value represented as hex when formatting.

E.g. formatting::hex(10) => '0xA'

Parameters
valuea numerical value to be presented as hex

Definition at line 173 of file wrappers.hpp.

◆ oct()

wrappers::OctWrapper<T> formatting::oct ( value)

Returns a wrapper that makes the provided value represented as oct when formatting.

E.g formatting::oct(9) => '011'

Parameters
valuea numerical value to be presented as oct

Definition at line 186 of file wrappers.hpp.

◆ raw() [1/2]

wrappers::HexWrapper<size_t> formatting::raw ( void *  value)

Returns a wrapper that makes the provided pointer represented as hex value of a pointer.

Parameters
valuea pointer to be represented as hex

Definition at line 196 of file wrappers.hpp.

◆ raw() [2/2]

wrappers::HexWrapper<size_t> formatting::raw ( const void *  value)

Returns a wrapper that makes the provided pointer represented as hex value of a pointer.

Parameters
valuea pointer to be represented as hex

Definition at line 207 of file wrappers.hpp.

Variable Documentation

◆ default_precision

unsigned int default_precision = 9
static

Default precision - be careful to change due to no thread safety

Definition at line 36 of file implementations.hpp.

◆ MAJOR_VERSION

const int MAJOR_VERSION = 1
static

Definition at line 43 of file formatting.hpp.

◆ MINOR_VERSION

const int MINOR_VERSION = 2
static

Definition at line 44 of file formatting.hpp.

◆ placeholder

const std::string placeholder = "{}"

The placeholder of formatter.

Definition at line 47 of file formatting.hpp.

◆ precision

Precision wrapper helper that allows to set output precision with the brackets operator (e.g. precision6 => "2.71828")

Definition at line 222 of file wrappers.hpp.

◆ width

Width wrapper helper that allows to set output width with the brackets operator (e.g. width[3]('c') => " c").

Definition at line 216 of file wrappers.hpp.

◆ WORLD_VERSION

const int WORLD_VERSION = 0
static

Definition at line 42 of file formatting.hpp.