Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
a844d7ab
Commit
a844d7ab
authored
Jan 19, 2020
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add namespaces
parent
47d39680
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
16 deletions
+16
-16
doc/syntax.rst
doc/syntax.rst
+16
-16
No files found.
doc/syntax.rst
View file @
a844d7ab
...
@@ -320,56 +320,56 @@ following examples.
...
@@ -320,56 +320,56 @@ following examples.
Accessing arguments by position::
Accessing arguments by position::
format("{0}, {1}, {2}", 'a', 'b', 'c');
f
mt::f
ormat("{0}, {1}, {2}", 'a', 'b', 'c');
// Result: "a, b, c"
// Result: "a, b, c"
format("{}, {}, {}", 'a', 'b', 'c');
f
mt::f
ormat("{}, {}, {}", 'a', 'b', 'c');
// Result: "a, b, c"
// Result: "a, b, c"
format("{2}, {1}, {0}", 'a', 'b', 'c');
f
mt::f
ormat("{2}, {1}, {0}", 'a', 'b', 'c');
// Result: "c, b, a"
// Result: "c, b, a"
format("{0}{1}{0}", "abra", "cad"); // arguments' indices can be repeated
f
mt::f
ormat("{0}{1}{0}", "abra", "cad"); // arguments' indices can be repeated
// Result: "abracadabra"
// Result: "abracadabra"
Aligning the text and specifying a width::
Aligning the text and specifying a width::
format("{:<30}", "left aligned");
f
mt::f
ormat("{:<30}", "left aligned");
// Result: "left aligned "
// Result: "left aligned "
format("{:>30}", "right aligned");
f
mt::f
ormat("{:>30}", "right aligned");
// Result: " right aligned"
// Result: " right aligned"
format("{:^30}", "centered");
f
mt::f
ormat("{:^30}", "centered");
// Result: " centered "
// Result: " centered "
format("{:*^30}", "centered"); // use '*' as a fill char
f
mt::f
ormat("{:*^30}", "centered"); // use '*' as a fill char
// Result: "***********centered***********"
// Result: "***********centered***********"
Dynamic width::
Dynamic width::
format("{:<{}}", "left aligned", 30);
f
mt::f
ormat("{:<{}}", "left aligned", 30);
// Result: "left aligned "
// Result: "left aligned "
Dynamic precision::
Dynamic precision::
format("{:.{}f}", 3.14, 1);
f
mt::f
ormat("{:.{}f}", 3.14, 1);
// Result: "3.1"
// Result: "3.1"
Replacing ``%+f``, ``%-f``, and ``% f`` and specifying a sign::
Replacing ``%+f``, ``%-f``, and ``% f`` and specifying a sign::
format("{:+f}; {:+f}", 3.14, -3.14); // show it always
f
mt::f
ormat("{:+f}; {:+f}", 3.14, -3.14); // show it always
// Result: "+3.140000; -3.140000"
// Result: "+3.140000; -3.140000"
format("{: f}; {: f}", 3.14, -3.14); // show a space for positive numbers
f
mt::f
ormat("{: f}; {: f}", 3.14, -3.14); // show a space for positive numbers
// Result: " 3.140000; -3.140000"
// Result: " 3.140000; -3.140000"
format("{:-f}; {:-f}", 3.14, -3.14); // show only the minus -- same as '{:f}; {:f}'
f
mt::f
ormat("{:-f}; {:-f}", 3.14, -3.14); // show only the minus -- same as '{:f}; {:f}'
// Result: "3.140000; -3.140000"
// Result: "3.140000; -3.140000"
Replacing ``%x`` and ``%o`` and converting the value to different bases::
Replacing ``%x`` and ``%o`` and converting the value to different bases::
format("int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
f
mt::f
ormat("int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
// Result: "int: 42; hex: 2a; oct: 52; bin: 101010"
// Result: "int: 42; hex: 2a; oct: 52; bin: 101010"
// with 0x or 0 or 0b as prefix:
// with 0x or 0 or 0b as prefix:
format("int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}", 42);
f
mt::f
ormat("int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}", 42);
// Result: "int: 42; hex: 0x2a; oct: 052; bin: 0b101010"
// Result: "int: 42; hex: 0x2a; oct: 052; bin: 0b101010"
Padded hex byte with prefix and always prints both hex characters::
Padded hex byte with prefix and always prints both hex characters::
format("{:#04x}", 0);
f
mt::f
ormat("{:#04x}", 0);
// Result: "0x00"
// Result: "0x00"
Box drawing using Unicode fill::
Box drawing using Unicode fill::
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment