mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-12-14 16:49:30 +08:00
Replace sscanf by std::istringstream
Using std::istringstream allows conversion of string to float independent of the current locale setting. Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
8cc751136d
commit
25f2e0cb10
@ -142,17 +142,22 @@ uint16_t ReadSampleSize(TFile *fp) {
|
|||||||
*/
|
*/
|
||||||
PARAM_DESC *ReadParamDesc(TFile *fp, uint16_t N) {
|
PARAM_DESC *ReadParamDesc(TFile *fp, uint16_t N) {
|
||||||
PARAM_DESC *ParamDesc;
|
PARAM_DESC *ParamDesc;
|
||||||
char linear_token[TOKENSIZE], essential_token[TOKENSIZE];
|
|
||||||
|
|
||||||
ParamDesc = static_cast<PARAM_DESC *>(Emalloc (N * sizeof (PARAM_DESC)));
|
ParamDesc = static_cast<PARAM_DESC *>(Emalloc (N * sizeof (PARAM_DESC)));
|
||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
const int kMaxLineSize = TOKENSIZE * 4;
|
const int kMaxLineSize = TOKENSIZE * 4;
|
||||||
char line[kMaxLineSize];
|
char line[kMaxLineSize];
|
||||||
ASSERT_HOST(fp->FGets(line, kMaxLineSize) != nullptr);
|
ASSERT_HOST(fp->FGets(line, kMaxLineSize) != nullptr);
|
||||||
ASSERT_HOST(sscanf(line,
|
std::istringstream stream(line);
|
||||||
"%" QUOTED_TOKENSIZE "s %" QUOTED_TOKENSIZE "s %f %f",
|
// Use "C" locale (needed for float values Min, Max).
|
||||||
linear_token, essential_token, &ParamDesc[i].Min,
|
stream.imbue(std::locale::classic());
|
||||||
&ParamDesc[i].Max) == 4);
|
std::string linear_token;
|
||||||
|
stream >> linear_token;
|
||||||
|
std::string essential_token;
|
||||||
|
stream >> essential_token;
|
||||||
|
stream >> ParamDesc[i].Min;
|
||||||
|
stream >> ParamDesc[i].Max;
|
||||||
|
ASSERT_HOST(!stream.fail());
|
||||||
ParamDesc[i].Circular = (linear_token[0] == 'c');
|
ParamDesc[i].Circular = (linear_token[0] == 'c');
|
||||||
ParamDesc[i].NonEssential = (essential_token[0] != 'e');
|
ParamDesc[i].NonEssential = (essential_token[0] != 'e');
|
||||||
ParamDesc[i].Range = ParamDesc[i].Max - ParamDesc[i].Min;
|
ParamDesc[i].Range = ParamDesc[i].Max - ParamDesc[i].Min;
|
||||||
|
Loading…
Reference in New Issue
Block a user