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
f43de4a4
Commit
f43de4a4
authored
Feb 15, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only append terminating '\0' when necessary.
parent
430c45d6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
5 deletions
+7
-5
format.h
format.h
+7
-5
No files found.
format.h
View file @
f43de4a4
...
...
@@ -1287,13 +1287,12 @@ class FormatInt {
// Buffer should be large enough to hold all digits (digits10 + 1),
// a sign and a null character.
enum
{
BUFFER_SIZE
=
std
::
numeric_limits
<
unsigned
long
long
>::
digits10
+
3
};
char
buffer_
[
BUFFER_SIZE
];
mutable
char
buffer_
[
BUFFER_SIZE
];
char
*
str_
;
// Formats value in reverse and returns the number of digits.
char
*
FormatDecimal
(
unsigned
long
long
value
)
{
char
*
buffer_end
=
buffer_
+
BUFFER_SIZE
;
*--
buffer_end
=
'\0'
;
char
*
buffer_end
=
buffer_
+
BUFFER_SIZE
-
1
;
while
(
value
>=
100
)
{
// Integer division is slow so do it for a group of two digits instead
// of for every digit. The idea comes from the talk by Alexandrescu
...
...
@@ -1331,8 +1330,11 @@ class FormatInt {
explicit
FormatInt
(
unsigned
long
value
)
:
str_
(
FormatDecimal
(
value
))
{}
explicit
FormatInt
(
unsigned
long
long
value
)
:
str_
(
FormatDecimal
(
value
))
{}
const
char
*
c_str
()
const
{
return
str_
;
}
std
::
string
str
()
const
{
return
str_
;
}
const
char
*
c_str
()
const
{
buffer_
[
BUFFER_SIZE
-
1
]
=
'\0'
;
return
str_
;
}
std
::
string
str
()
const
{
return
std
::
string
(
str_
,
size
());
}
std
::
size_t
size
()
const
{
return
buffer_
-
str_
+
BUFFER_SIZE
-
1
;
}
};
...
...
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