-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
140 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Formatting library for C++ - std::locale support | ||
// | ||
// Copyright (c) 2012 - present, Victor Zverovich | ||
// All rights reserved. | ||
// | ||
// For the license information refer to format.h. | ||
|
||
#ifndef FMT_LOCALE_H_ | ||
#define FMT_LOCALE_H_ | ||
|
||
#include "format.h" | ||
#include <locale> | ||
|
||
FMT_BEGIN_NAMESPACE | ||
|
||
namespace internal { | ||
template <typename Char> | ||
typename buffer_context<Char>::type::iterator vformat_to( | ||
const std::locale &loc, basic_buffer<Char> &buf, | ||
basic_string_view<Char> format_str, | ||
basic_format_args<typename buffer_context<Char>::type> args) { | ||
typedef back_insert_range<basic_buffer<Char> > range; | ||
return vformat_to<arg_formatter<range>>( | ||
buf, to_string_view(format_str), args, internal::locale_ref(loc)); | ||
} | ||
|
||
template <typename Char> | ||
std::basic_string<Char> vformat( | ||
const std::locale &loc, basic_string_view<Char> format_str, | ||
basic_format_args<typename buffer_context<Char>::type> args) { | ||
basic_memory_buffer<Char> buffer; | ||
internal::vformat_to(loc, buffer, format_str, args); | ||
return fmt::to_string(buffer); | ||
} | ||
} | ||
|
||
template <typename S, typename... Args> | ||
inline std::basic_string<FMT_CHAR(S)> format( | ||
const std::locale &loc, const S &format_str, const Args &... args) { | ||
return internal::vformat( | ||
loc, to_string_view(format_str), | ||
*internal::checked_args<S, Args...>(format_str, args...)); | ||
} | ||
|
||
FMT_END_NAMESPACE | ||
|
||
#endif // FMT_LOCALE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Formatting library for C++ - core tests | ||
// | ||
// Copyright (c) 2012 - present, Victor Zverovich | ||
// All rights reserved. | ||
// | ||
// For the license information refer to format.h. | ||
|
||
#include "fmt/locale.h" | ||
#include "gmock.h" | ||
|
||
struct numpunct : std::numpunct<char> { | ||
protected: | ||
char do_thousands_sep() const FMT_OVERRIDE { return '~'; } | ||
}; | ||
|
||
TEST(LocaleTest, Format) { | ||
std::locale loc; | ||
EXPECT_EQ("1~234~567", | ||
fmt::format(std::locale(loc, new numpunct()), "{:n}", 1234567)); | ||
EXPECT_EQ("1,234,567", fmt::format(loc, "{:n}", 1234567)); | ||
} |
f2ee988
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π
Alas, this invalidates part of my list of things to be improved in the future even before having it presented to the audience. π
f2ee988
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WG21 is a strong motivator =)