https://github.com/localvoid/cxx-fmt
C++ string formatting library
https://github.com/localvoid/cxx-fmt
Last synced: 8 months ago
JSON representation
C++ string formatting library
- Host: GitHub
- URL: https://github.com/localvoid/cxx-fmt
- Owner: localvoid
- Created: 2013-02-05T08:33:37.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2013-02-09T08:12:07.000Z (about 13 years ago)
- Last Synced: 2025-01-25T06:25:25.520Z (about 1 year ago)
- Language: C++
- Homepage:
- Size: 254 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
===============================
C++ string formatting library
===============================
The library is in alpha state.
And currently doesn't support fast conversion of floating point
values, it is now using sprintf for this purposes.
Synopsis
--------
::
#include
template
uint32_t fmt::format(const char *out, const char *format, Args&& ... args);
Description
-----------
Format strings contain "placeholder fields" surrounded by curly braces
`{}`. Anything that is not contained in braces is considered literal
text. If you need to include a open brace character in the literal
text, it can be escaped by doubling: {{.
::
fmt::format("Hello curly brace {{ and {}", "world");
Argument specification
++++++++++++++++++++++
::
arg = '{' arg_index? (':' flags* options*)? '}'
arg_index = [0-9]+
flags = [<>+ cefoxEGX%#0,]
options = (width | precision)
width = 'w' [0-9]+
precision = '.' [0-9]+
Flags
+++++
==== =================================================================
Flag Description
==== =================================================================
> Align right
< Align left
\+ A sign (+ or -) should always be placed before a number.
' ' A space should be placed before a positive number.
c Convert to char
e Exponent
f Fixed
o Octal
x Hexadecimal
E Upper Exponent
G Large Exponent
X Upper Hexadecimal
% Percentage
# Prefixed
0 Zero padding
, Comma separator
==== =================================================================
Options
+++++++
Example
-------
::
char buf[128];
uint32_t size = fmt::format(buf, "format integer: {:X>w6}", 0xff);
std::cout << std::string(buf, size) << std::endl;
should output: ``"format integer: 0xFF"``
Roadmap
-------
- Native floating point conversion
- Width flag for string values
- Percentage flag
- Unit Tests coverage
- API for IO stream