Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 493177d

Browse files
Set locale to ensure dots are recognized as decimal points in SWC files
1 parent 01700d4 commit 493177d

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/readers/morphologySWC.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "morphologySWC.h"
22

33
#include <cstdint> // uint32_t
4+
#include <cstdio> // sscanf
5+
#include <locale> // std::locale
46
#include <memory> // std::shared_ptr
57
#include <sstream> // std::stringstream
68
#include <string> // std::string
@@ -29,6 +31,9 @@ morphio::readers::Sample readSample(const char* line, unsigned int lineNumber_)
2931
morphio::floatType radius = -1.;
3032
int int_type = -1;
3133
morphio::readers::Sample sample;
34+
35+
// Set local to classic in order to ensure that dots are recognized as decimal points by sscanf
36+
std::locale prev_locale = std::locale::global( std::locale::classic() );
3237
sample.valid = sscanf(line,
3338
format,
3439
&sample.id,
@@ -39,6 +44,9 @@ morphio::readers::Sample readSample(const char* line, unsigned int lineNumber_)
3944
&radius,
4045
&sample.parentId) == 7;
4146

47+
// Restore locale
48+
std::locale::global( prev_locale );
49+
4250
sample.type = static_cast<morphio::SectionType>(int_type);
4351
sample.diameter = radius * 2; // The point array stores diameters.
4452
sample.lineNumber = lineNumber_;

0 commit comments

Comments
 (0)