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
eadd2ee4
Commit
eadd2ee4
authored
Feb 15, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add FormatInt::data() and document members.
parent
f43de4a4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
1 deletion
+24
-1
format-test.cc
format-test.cc
+5
-0
format.h
format.h
+19
-1
No files found.
format-test.cc
View file @
eadd2ee4
...
@@ -1408,6 +1408,11 @@ TEST(FormatterTest, Examples) {
...
@@ -1408,6 +1408,11 @@ TEST(FormatterTest, Examples) {
ReportError
(
"File not found: {0}"
)
<<
path
;
ReportError
(
"File not found: {0}"
)
<<
path
;
}
}
TEST
(
FormatIntTest
,
Data
)
{
fmt
::
FormatInt
format_int
(
42
);
EXPECT_EQ
(
"42"
,
std
::
string
(
format_int
.
data
(),
format_int
.
size
()));
}
TEST
(
FormatIntTest
,
FormatInt
)
{
TEST
(
FormatIntTest
,
FormatInt
)
{
EXPECT_EQ
(
"42"
,
fmt
::
FormatInt
(
42
).
str
());
EXPECT_EQ
(
"42"
,
fmt
::
FormatInt
(
42
).
str
());
EXPECT_EQ
(
2
,
fmt
::
FormatInt
(
42
).
size
());
EXPECT_EQ
(
2
,
fmt
::
FormatInt
(
42
).
size
());
...
...
format.h
View file @
eadd2ee4
...
@@ -1330,12 +1330,30 @@ class FormatInt {
...
@@ -1330,12 +1330,30 @@ class FormatInt {
explicit
FormatInt
(
unsigned
long
value
)
:
str_
(
FormatDecimal
(
value
))
{}
explicit
FormatInt
(
unsigned
long
value
)
:
str_
(
FormatDecimal
(
value
))
{}
explicit
FormatInt
(
unsigned
long
long
value
)
:
str_
(
FormatDecimal
(
value
))
{}
explicit
FormatInt
(
unsigned
long
long
value
)
:
str_
(
FormatDecimal
(
value
))
{}
/**
Returns the number of characters written to the output buffer.
*/
std
::
size_t
size
()
const
{
return
buffer_
-
str_
+
BUFFER_SIZE
-
1
;
}
/**
Returns a pointer to the output buffer content. No terminating null
character is appended.
*/
const
char
*
data
()
const
{
return
str_
;
}
/**
Returns a pointer to the output buffer content with terminating null
character appended.
*/
const
char
*
c_str
()
const
{
const
char
*
c_str
()
const
{
buffer_
[
BUFFER_SIZE
-
1
]
=
'\0'
;
buffer_
[
BUFFER_SIZE
-
1
]
=
'\0'
;
return
str_
;
return
str_
;
}
}
/**
Returns the content of the output buffer as an `std::string`.
*/
std
::
string
str
()
const
{
return
std
::
string
(
str_
,
size
());
}
std
::
string
str
()
const
{
return
std
::
string
(
str_
,
size
());
}
std
::
size_t
size
()
const
{
return
buffer_
-
str_
+
BUFFER_SIZE
-
1
;
}
};
};
// Formats a decimal integer value writing into buffer and returns
// Formats a decimal integer value writing into buffer and returns
...
...
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