Skip to content

Commit 9e00e5a

Browse files
committed
Add support for CSV spectrum files in Russian.
Still need to cleanup - this is for testing at this point.
1 parent 18cb4d4 commit 9e00e5a

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

src/SpecFile_csv.cpp

+43-9
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,42 @@ bool SpecFile::load_txt_or_csv_file( const std::string &filename )
117117
// I *think* input should now be UTF-8???
118118
}
119119
*/
120-
120+
121121

122-
for( size_t i = (is_utf8 ? 3 : 0); i < (sizeof(first_bytes) - 1); ++i )
123-
{
124-
if( first_bytes[i] > 127 )
125-
return false;
126-
}
122+
//for( size_t i = (is_utf8 ? 3 : 0); i < (sizeof(first_bytes) - 1); ++i )
123+
//{
124+
// if( first_bytes[i] > 127 )
125+
// return false;
126+
//}
127+
//TODO: extract below into its own function and add tests for
128+
{// Begin check if UTF-8 string
129+
int bytesToProcess = 0;
130+
for( size_t i = (is_utf8 ? 3 : 0); i < (sizeof(first_bytes) - 1); ++i )
131+
{
132+
const uint8_t c = first_bytes[i];
133+
if (bytesToProcess == 0)
134+
{
135+
// Determine how many bytes to expect
136+
if ((c & 0x80) == 0) {
137+
continue; // 1-byte character (ASCII)
138+
} else if ((c & 0xE0) == 0xC0) {
139+
bytesToProcess = 1; // 2-byte character
140+
} else if ((c & 0xF0) == 0xE0) {
141+
bytesToProcess = 2; // 3-byte character
142+
} else if ((c & 0xF8) == 0xF0) {
143+
bytesToProcess = 3; // 4-byte character
144+
} else {
145+
return false; // Invalid leading byte
146+
}
147+
} else {
148+
// Expecting continuation byte
149+
if ((c & 0xC0) != 0x80) {
150+
return false; // Not a valid continuation byte
151+
}
152+
bytesToProcess--;
153+
}
154+
}
155+
}// End check if valid UTF-8 string
127156

128157

129158
//while( input->good() )
@@ -1094,6 +1123,7 @@ void Measurement::set_info_from_txt_or_csv( std::istream& istr )
10941123
|| istarts_with( fields[0], "data" )
10951124
|| istarts_with( fields[0], "energy" )
10961125
|| istarts_with( fields[0], "Ch" )
1126+
|| istarts_with( fields[0], "Канал" )
10971127
|| fields[0]=="##" ) )
10981128
{
10991129
++nlines_used;
@@ -1102,6 +1132,7 @@ void Measurement::set_info_from_txt_or_csv( std::istream& istr )
11021132
{
11031133
if( starts_with( fields[i], "channel" )
11041134
|| starts_with( fields[i], "ch" )
1135+
|| starts_with( fields[i], "Канал" )
11051136
|| fields[i]=="##" )
11061137
{
11071138
column_map[i] = kChannel;
@@ -1123,7 +1154,8 @@ void Measurement::set_info_from_txt_or_csv( std::istream& istr )
11231154
if( istarts_with(restofline, "count")
11241155
|| istarts_with(restofline, "data")
11251156
|| istarts_with(restofline, "signal")
1126-
|| istarts_with(restofline, "detector") )
1157+
|| istarts_with(restofline, "detector")
1158+
|| istarts_with(restofline, "Отсчеты") )
11271159
{
11281160
column_map[i+1] = kCounts;
11291161
}
@@ -1244,7 +1276,8 @@ void Measurement::set_info_from_txt_or_csv( std::istream& istr )
12441276

12451277
start_time_ = time_from_string( timestr.c_str() );
12461278
}else if( istarts_with( fields[0], "LiveTime" )
1247-
|| istarts_with( fields[0], "live time" ) )
1279+
|| istarts_with( fields[0], "live time" )
1280+
|| istarts_with( fields[0], "Живое время" ) )
12481281
{
12491282
++nlines_used;
12501283

@@ -1265,7 +1298,8 @@ void Measurement::set_info_from_txt_or_csv( std::istream& istr )
12651298
}
12661299
}else if( istarts_with( fields[0], "realtime" )
12671300
|| istarts_with( fields[0], "Real time" )
1268-
|| istarts_with( fields[0], "Total time") )
1301+
|| istarts_with( fields[0], "Total time")
1302+
|| istarts_with( fields[0], "Реальное время") )
12691303
{
12701304
++nlines_used;
12711305

0 commit comments

Comments
 (0)