@@ -117,13 +117,42 @@ bool SpecFile::load_txt_or_csv_file( const std::string &filename )
117
117
// I *think* input should now be UTF-8???
118
118
}
119
119
*/
120
-
120
+
121
121
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
127
156
128
157
129
158
// while( input->good() )
@@ -1094,6 +1123,7 @@ void Measurement::set_info_from_txt_or_csv( std::istream& istr )
1094
1123
|| istarts_with ( fields[0 ], " data" )
1095
1124
|| istarts_with ( fields[0 ], " energy" )
1096
1125
|| istarts_with ( fields[0 ], " Ch" )
1126
+ || istarts_with ( fields[0 ], " Канал" )
1097
1127
|| fields[0 ]==" ##" ) )
1098
1128
{
1099
1129
++nlines_used;
@@ -1102,6 +1132,7 @@ void Measurement::set_info_from_txt_or_csv( std::istream& istr )
1102
1132
{
1103
1133
if ( starts_with ( fields[i], " channel" )
1104
1134
|| starts_with ( fields[i], " ch" )
1135
+ || starts_with ( fields[i], " Канал" )
1105
1136
|| fields[i]==" ##" )
1106
1137
{
1107
1138
column_map[i] = kChannel ;
@@ -1123,7 +1154,8 @@ void Measurement::set_info_from_txt_or_csv( std::istream& istr )
1123
1154
if ( istarts_with (restofline, " count" )
1124
1155
|| istarts_with (restofline, " data" )
1125
1156
|| istarts_with (restofline, " signal" )
1126
- || istarts_with (restofline, " detector" ) )
1157
+ || istarts_with (restofline, " detector" )
1158
+ || istarts_with (restofline, " Отсчеты" ) )
1127
1159
{
1128
1160
column_map[i+1 ] = kCounts ;
1129
1161
}
@@ -1244,7 +1276,8 @@ void Measurement::set_info_from_txt_or_csv( std::istream& istr )
1244
1276
1245
1277
start_time_ = time_from_string ( timestr.c_str () );
1246
1278
}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 ], " Живое время" ) )
1248
1281
{
1249
1282
++nlines_used;
1250
1283
@@ -1265,7 +1298,8 @@ void Measurement::set_info_from_txt_or_csv( std::istream& istr )
1265
1298
}
1266
1299
}else if ( istarts_with ( fields[0 ], " realtime" )
1267
1300
|| 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 ], " Реальное время" ) )
1269
1303
{
1270
1304
++nlines_used;
1271
1305
0 commit comments