File tree Expand file tree Collapse file tree 6 files changed +48
-17
lines changed
Expand file tree Collapse file tree 6 files changed +48
-17
lines changed Original file line number Diff line number Diff line change 2020pict
2121* .o
2222.DS_Store
23- build
23+ build
24+ .vscode /settings.json
Original file line number Diff line number Diff line change @@ -574,27 +574,27 @@ wstring ConstraintsTokenizer::getParameterName()
574574//
575575double ConstraintsTokenizer::getNumber ()
576576{
577- // declare new stream from text we'd like to parse
578- // then try to get numeric value preserving old and new
579- // position within a stream to properly update cursor
580577 wstring substring ( _currentPosition, _constraintsText.end () );
581- wistringstream ist ( substring );
582-
583- unsigned int positionBefore = (unsigned int ) ist.tellg ();
584-
578+
579+ size_t charsConsumed = 0 ;
585580 double number;
586- ist>>number;
587-
588- if (ist.rdstate () & ios::failbit)
581+
582+ try
583+ {
584+ number = stod ( substring, &charsConsumed );
585+ }
586+ catch ( ... )
589587 {
590588 throw CSyntaxError ( SyntaxErrorType::NotNumericValue, _currentPosition );
591589 }
592-
593- // success, update current cursor position
594- unsigned int difference = (unsigned int ) ist.tellg () - positionBefore;
595- _currentPosition += difference;
596590
597- return ( number );
591+ if ( charsConsumed == 0 )
592+ {
593+ throw CSyntaxError ( SyntaxErrorType::NotNumericValue, _currentPosition );
594+ }
595+
596+ _currentPosition += charsConsumed;
597+ return ( number );
598598}
599599
600600//
Original file line number Diff line number Diff line change 11#include < fstream>
22#include < sstream>
3+ #include < locale>
34#include " model.h"
45using namespace std ;
56
@@ -442,6 +443,8 @@ bool CModelData::readModel( const wstring& filePath )
442443 PrintMessage ( InputDataError, L" Couldn't open file:" , filePath.data () );
443444 return ( false );
444445 }
446+ // Use the current global locale (set to UTF-8 in main) for decoding
447+ file.imbue ( std::locale () );
445448
446449 wstring line;
447450
@@ -543,6 +546,8 @@ bool CModelData::ReadRowSeedFile( const wstring& filePath )
543546 PrintMessage ( InputDataError, L" Couldn't open file:" , filePath.data () );
544547 return ( false );
545548 }
549+ // Use the current global locale (set to UTF-8 in main) for decoding
550+ file.imbue ( std::locale () );
546551 wstring line;
547552
548553 // parameter names
Original file line number Diff line number Diff line change 55
66#include < ctime>
77#include < cstring>
8+ #include < iostream>
89#include < locale>
910#include < stdexcept>
1011using namespace std ;
1112
1213#include " cmdline.h"
1314#include " gcd.h"
15+ #include " strings.h"
1416using namespace pictcli_gcd ;
1517
1618//
@@ -119,9 +121,24 @@ int __cdecl wmain
119121 IN wchar_t * args[]
120122 )
121123{
124+ // Align all wide I/O with the current environment locale (UTF-8 on modern systems)
125+ try
126+ {
127+ std::locale loc ( " " );
128+ std::locale::global ( loc );
129+ std::wcout.imbue ( loc );
130+ std::wcerr.imbue ( loc );
131+ }
132+ catch ( const std::runtime_error& )
133+ {
134+ // Fall back to the classic locale if the environment locale is unavailable
135+ std::locale::global ( std::locale::classic () );
136+ }
137+
122138 wstring output;
123139 int ret = execute ( argc, args, output );
124- wcout << output;
140+
141+ std::wcout << output;
125142
126143 return ret;
127144}
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ bug020.txt /d:* -> SUCCESS
3737bug021.txt -> SUCCESS
3838bug022.txt -> SUCCESS
3939bug023.txt /o:1 -> SUCCESS
40+ bug024.txt -> SUCCESS
4041
4142bug002.txt -> BAD_MODEL
4243bug003.txt -> BAD_MODEL
Original file line number Diff line number Diff line change 1+ # Testing Japanese Kanji characters in parameter names and constraints
2+ 予:Hoge,X,Y,Z
3+ 予定日時:Scheduled,NotScheduled
4+ Foo:Bar,Baz,A,B
5+
6+ if [予定日時] = "Scheduled" then [Foo] = "Bar";
7+ if [予] = "Hoge" then [Foo] <> "Bar";
You can’t perform that action at this time.
0 commit comments