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
a659d807
Commit
a659d807
authored
Jan 31, 2016
by
Mario Werner
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into update-project-layout
parents
00fda9b2
4952e79e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
5 deletions
+68
-5
cppformat/format.cc
cppformat/format.cc
+4
-2
cppformat/posix.h
cppformat/posix.h
+51
-1
doc/syntax.rst
doc/syntax.rst
+2
-0
test/posix-test.cc
test/posix-test.cc
+9
-0
test/printf-test.cc
test/printf-test.cc
+2
-2
No files found.
cppformat/format.cc
View file @
a659d807
...
...
@@ -328,8 +328,10 @@ class ArgConverter : public fmt::internal::ArgVisitor<ArgConverter<T>, void> {
}
else
{
if
(
is_signed
)
{
arg_
.
type
=
Arg
::
LONG_LONG
;
arg_
.
long_long_value
=
static_cast
<
typename
fmt
::
internal
::
MakeUnsigned
<
U
>::
Type
>
(
value
);
// glibc's printf doesn't sign extend arguments of smaller types:
// std::printf("%lld", -42); // prints "4294967254"
// but we don't have to do the same because it's a UB.
arg_
.
long_long_value
=
value
;
}
else
{
arg_
.
type
=
Arg
::
ULONG_LONG
;
arg_
.
ulong_long_value
=
...
...
cppformat/posix.h
View file @
a659d807
...
...
@@ -34,8 +34,10 @@
#endif
#include <errno.h>
#include <fcntl.h> // for O_RDONLY
#include <fcntl.h> // for O_RDONLY
#include <locale.h> // for locale_t
#include <stdio.h>
#include <stdlib.h> // for strtod_l
#include <cstddef>
...
...
@@ -331,6 +333,54 @@ class File {
// Returns the memory page size.
long
getpagesize
();
#if defined(LC_NUMERIC_MASK) || defined(_MSC_VER)
// A "C" numeric locale.
class
Locale
{
private:
# ifdef _MSC_VER
typedef
_locale_t
locale_t
;
enum
{
LC_NUMERIC_MASK
=
LC_NUMERIC
};
static
locale_t
newlocale
(
int
category_mask
,
const
char
*
locale
,
locale_t
)
{
return
_create_locale
(
category_mask
,
locale
);
}
static
void
freelocale
(
locale_t
locale
)
{
_free_locale
(
locale
);
}
static
double
strtod_l
(
const
char
*
nptr
,
char
**
endptr
,
_locale_t
locale
)
{
return
_strtod_l
(
nptr
,
endptr
,
locale
);
}
# endif
locale_t
locale_
;
FMT_DISALLOW_COPY_AND_ASSIGN
(
Locale
);
public:
Locale
()
:
locale_
(
newlocale
(
LC_NUMERIC_MASK
,
"C"
,
NULL
))
{
if
(
!
locale_
)
throw
fmt
::
SystemError
(
errno
,
"cannot create locale"
);
}
~
Locale
()
{
freelocale
(
locale_
);
}
locale_t
get
()
const
{
return
locale_
;
}
// Converts string to floating-point number and advances str past the end
// of the parsed input.
double
strtod
(
const
char
*&
str
)
const
{
char
*
end
=
0
;
double
result
=
strtod_l
(
str
,
&
end
,
locale_
);
str
=
end
;
return
result
;
}
};
#endif // LC_NUMERIC
}
// namespace fmt
#if !FMT_USE_RVALUE_REFERENCES
...
...
doc/syntax.rst
View file @
a659d807
...
...
@@ -262,6 +262,8 @@ The available presentation types for floating-point values are:
| none | The same as ``'g'``. |
+---------+----------------------------------------------------------+
Floating-point formatting is locale-dependent.
.. ifconfig:: False
+---------+----------------------------------------------------------+
...
...
test/posix-test.cc
View file @
a659d807
...
...
@@ -387,3 +387,12 @@ TEST(FileTest, FdopenError) {
EXPECT_SYSTEM_ERROR_NOASSERT
(
f
.
fdopen
(
"r"
),
EBADF
,
"cannot associate stream with file descriptor"
);
}
#ifdef LC_NUMERIC_MASK
TEST
(
LocaleTest
,
Strtod
)
{
fmt
::
Locale
locale
;
const
char
*
start
=
"4.2"
,
*
ptr
=
start
;
EXPECT_EQ
(
4.2
,
locale
.
strtod
(
ptr
));
EXPECT_EQ
(
start
+
3
,
ptr
);
}
#endif
test/printf-test.cc
View file @
a659d807
...
...
@@ -306,8 +306,8 @@ void TestLength(const char *length_spec, U value) {
}
using
fmt
::
internal
::
MakeUnsigned
;
if
(
sizeof
(
U
)
<=
sizeof
(
int
)
&&
sizeof
(
int
)
<
sizeof
(
T
))
{
signed_value
=
unsigned_value
=
static_cast
<
typename
MakeUnsigned
<
unsigned
>::
Type
>
(
value
);
signed_value
=
value
;
unsigned_value
=
static_cast
<
typename
MakeUnsigned
<
unsigned
>::
Type
>
(
value
);
}
else
{
signed_value
=
static_cast
<
typename
MakeSigned
<
T
>::
Type
>
(
value
);
unsigned_value
=
static_cast
<
typename
MakeUnsigned
<
T
>::
Type
>
(
value
);
...
...
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