Commit 1028153 1 parent 0981d44 commit 1028153 Copy full SHA for 1028153
File tree 1 file changed +36
-4
lines changed
1 file changed +36
-4
lines changed Original file line number Diff line number Diff line change 49
49
#include < cstdlib>
50
50
#include < limits>
51
51
#include < string>
52
+ #include < locale.h>
52
53
53
54
namespace mp {
54
55
@@ -920,6 +921,33 @@ class NLHandler {
920
921
921
922
namespace internal {
922
923
924
+ // TODO: test
925
+ class Locale {
926
+ private:
927
+ locale_t locale_;
928
+
929
+ locale_t dup () const {
930
+ locale_t copy = duplocale (locale_);
931
+ if (!copy)
932
+ throw fmt::SystemError (errno, " cannot duplicate locale" );
933
+ return copy;
934
+ }
935
+
936
+ public:
937
+ Locale () : locale_(newlocale(LC_NUMERIC_MASK, " C" , NULL )) {
938
+ if (!locale_)
939
+ throw fmt::SystemError (errno, " cannot create locale" );
940
+ }
941
+ Locale (const Locale &other) : locale_(other.dup()) {}
942
+ Locale &operator =(const Locale &other) {
943
+ locale_ = other.dup ();
944
+ return *this ;
945
+ }
946
+ ~Locale () { freelocale (locale_); }
947
+
948
+ locale_t get () const { return locale_; }
949
+ };
950
+
923
951
class ReaderBase {
924
952
protected:
925
953
const char *ptr_, *start_, *end_;
@@ -947,6 +975,7 @@ class TextReader : public ReaderBase {
947
975
private:
948
976
const char *line_start_;
949
977
int line_;
978
+ Locale locale_;
950
979
951
980
// Reads an integer without a sign.
952
981
// Int: signed or unsigned integer type.
@@ -1058,11 +1087,14 @@ class TextReader : public ReaderBase {
1058
1087
1059
1088
double ReadDouble () {
1060
1089
SkipSpace ();
1061
- char *end = 0 ;
1090
+ const char *end = ptr_ ;
1062
1091
double value = 0 ;
1063
- if (*ptr_ != ' \n ' )
1064
- value = std::strtod (ptr_, &end);
1065
- if (!end || ptr_ == end)
1092
+ if (*ptr_ != ' \n ' ) {
1093
+ char *mut_end = 0 ;
1094
+ value = strtod_l (ptr_, &mut_end, locale_.get ());
1095
+ end = mut_end;
1096
+ }
1097
+ if (ptr_ == end)
1066
1098
ReportError (" expected double" );
1067
1099
ptr_ = end;
1068
1100
return value;
You can’t perform that action at this time.
0 commit comments