-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathfuzz_str_utils.cpp
727 lines (574 loc) · 24.8 KB
/
fuzz_str_utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
/**
SpecUtils: a library to parse, save, and manipulate gamma spectrum data files.
Copyright (C) 2016 William Johnson
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "SpecUtils_config.h"
#include <stdint.h>
#include <stddef.h>
#include <cstdint>
#include <sstream>
#include <random>
#include "SpecUtils/DateTime.h"
#include "SpecUtils/StringAlgo.h"
#include "SpecUtils/ParseUtils.h"
#include "SpecUtils/Filesystem.h"
#if( SpecUtils_ENABLE_D3_CHART )
#include "SpecUtils/D3SpectrumExport.h"
#else
static_assert( 0, "You should enable SpecUtils_ENABLE_D3_CHART" );
#endif
using namespace std;
// A little helper to figure out what call things are crashing on.
#define PRINT_WAYPOINTS 0
#if( PRINT_WAYPOINTS )
#include <chrono>
#include <iomanip>
#include <iostream>
std::chrono::time_point<std::chrono::system_clock> g_start_waypoint = std::chrono::system_clock::now();
std::chrono::time_point<std::chrono::system_clock> g_last_waypoint = std::chrono::system_clock::now();
#endif
// First argument is course location (we'll increment it as we go throughout this file), and
// the second argument is to get a little more fine grained if necessary.
void print_waypoint( int i, int j = 0 )
{
#if( PRINT_WAYPOINTS )
if( i == 0 )
g_start_waypoint = g_last_waypoint = std::chrono::system_clock::now();
const auto current = std::chrono::system_clock::now();
std::chrono::duration<long, std::milli> diff = std::chrono::duration_cast<std::chrono::milliseconds>( current - g_last_waypoint );
std::chrono::duration<long, std::milli> diff_total = std::chrono::duration_cast<std::chrono::milliseconds>( current - g_start_waypoint );
std::cout << "At - " << std::setw(2) << i;
if( j )
cout << "." << j;
std::cout << " (" << std::setw(5) << diff.count() << "ms since last waypoint, "
<< std::setw(5) << diff_total.count() << "ms since start)" << std::endl;
g_last_waypoint = current;
#endif
}//print_waypoint(...)
extern "C" int LLVMFuzzerTestOneInput( const uint8_t *data, size_t size )
{
print_waypoint( 0 );
const string datastr( (const char *)data, size );
std::uniform_int_distribution<size_t> distribution(0,size);
std::random_device generator; //std::random_device is a uniformly-distributed integer random number generator that produces non-deterministic random numbers.
const size_t str1_len = distribution(generator);
const string str_1 = datastr.substr( 0, str1_len );
const string str_2 = datastr.substr( str1_len );
print_waypoint( 1 );
using namespace SpecUtils;
{
string c1 = datastr, c2 = str_1, c3 = str_2;
trim( c1 );
trim( c2 );
trim( c3 );
}
print_waypoint( 2 );
{
trim_copy( datastr );
trim_copy( str_1 );
trim_copy( str_2 );
}
print_waypoint( 3 );
{
string c1 = datastr, c2 = str_1, c3 = str_2;
to_lower_ascii( c1 );
to_lower_ascii( c2 );
to_lower_ascii( c3 );
}
print_waypoint( 4 );
{
to_lower_ascii_copy( datastr );
to_lower_ascii_copy( str_1 );
to_lower_ascii_copy( str_2 );
}
print_waypoint( 5 );
{
string c1 = datastr, c2 = str_1, c3 = str_2;
to_upper_ascii( c1 );
to_upper_ascii( c2 );
to_upper_ascii( c3 );
}
print_waypoint( 6 );
{
iequals_ascii( datastr, str_1 );
iequals_ascii( datastr, str_2 );
iequals_ascii( str_1, str_2 );
iequals_ascii( str_1, datastr );
iequals_ascii( str_2, datastr );
iequals_ascii( str_2, str_1 );
}
print_waypoint( 7 );
{
const size_t max_strlen = 256;
const string str_1_short = str_1.size() < max_strlen ? str_1 : str_1.substr(0,max_strlen);
const string str_2_short = str_2.size() < max_strlen ? str_2 : str_2.substr(0,max_strlen);
const string datastr_short = datastr.size() < max_strlen ? datastr : datastr.substr(0,max_strlen);
contains( datastr_short, str_1_short.c_str() );
contains( datastr_short, str_2_short.c_str() );
contains( str_1_short, str_2_short.c_str() );
contains( str_1_short, datastr_short.c_str() );
//contains( str_2_short, datastr.c_str() );
contains( str_2_short, str_1_short.c_str() );
}
print_waypoint( 8 );
{
icontains( datastr, str_1 );
icontains( datastr, str_2 );
icontains( str_1, str_2 );
icontains( str_1, datastr );
icontains( str_2, datastr );
icontains( str_2, str_1 );
}
print_waypoint( 9 );
{
starts_with( datastr, str_1.c_str() );
starts_with( datastr, str_2.c_str() );
starts_with( str_1, str_2.c_str() );
starts_with( str_1, datastr.c_str() );
starts_with( str_2, datastr.c_str() );
starts_with( str_2, str_1.c_str() );
}
print_waypoint( 10 );
{
iends_with( datastr, str_1 );
iends_with( datastr, str_2 );
iends_with( str_1, str_2 );
iends_with( str_1, datastr );
iends_with( str_2, datastr );
iends_with( str_2, str_1 );
}
print_waypoint( 11 );
{
ifind_substr_ascii( datastr, str_1.c_str() );
ifind_substr_ascii( datastr, str_2.c_str() );
ifind_substr_ascii( str_1, str_2.c_str() );
ifind_substr_ascii( str_1, datastr.c_str() );
ifind_substr_ascii( str_2, datastr.c_str() );
ifind_substr_ascii( str_2, str_1.c_str() );
}
print_waypoint( 12 );
{
const size_t max_delims = 10;
const string str_1_short = str_1.size() < max_delims ? str_1 : str_1.substr(0,max_delims);
const string str_2_short = str_2.size() < max_delims ? str_2 : str_2.substr(0,max_delims);
const string datastr_short = datastr.size() < max_delims ? datastr : datastr.substr(0,max_delims);
string s = datastr;
erase_any_character( s, str_1_short.c_str() );
s = datastr;
erase_any_character( s, str_2_short.c_str() );
s = str_1_short;
erase_any_character( s, str_2_short.c_str() );
s = str_1_short;
erase_any_character( s, datastr_short.c_str() );
s = str_2_short;
erase_any_character( s, datastr_short.c_str() );
s = str_2_short;
erase_any_character( s, str_1_short.c_str() );
}
print_waypoint( 13 );
{
string c1 = datastr, c2 = str_1, c3 = str_2;
ireplace_all( c1, c2.c_str(), c3.c_str() );
c1 = datastr, c2 = str_1, c3 = str_2;
ireplace_all( c1, c3.c_str(), c2.c_str() );
c1 = datastr, c2 = str_1, c3 = str_2;
ireplace_all( c2, c1.c_str(), c2.c_str() );
//c1 = datastr, c2 = str_1, c3 = str_2;
//ireplace_all( c2, c2.c_str(), c1.c_str() );
//c1 = datastr, c2 = str_1, c3 = str_2;
//ireplace_all( c3, c1.c_str(), c2.c_str() );
//c1 = datastr, c2 = str_1, c3 = str_2;
//ireplace_all( c3, c2.c_str(), c1.c_str() );
}
print_waypoint( 14 );
{
std::vector<std::string> results;
split( results, str_1, str_2.c_str() );
split( results, str_2, str_1.c_str() );
split( results, datastr, str_2.c_str() );
split( results, str_2, datastr.c_str() );
split( results, str_1, datastr.c_str() );
split( results, datastr, str_1.c_str() );
split( results, datastr, datastr.c_str() );
split( results, str_1, datastr.c_str() );
split( results, str_1, str_1.c_str() );
split( results, str_2, str_2.c_str() );
split( results, datastr, datastr.c_str() );
split( results, datastr, "" );
split( results, str_1, "" );
split( results, str_2, "" );
}
print_waypoint( 15 );
{
std::vector<std::string> results;
// Having a long list of delimiters can cause things to go pretty slowly, so we'll
// limit things.
const size_t max_delims = 5;
const string str_1_short = str_1.size() < max_delims ? str_1 : str_1.substr(0,max_delims);
const string str_2_short = str_2.size() < max_delims ? str_2 : str_2.substr(0,max_delims);
const string datastr_short = datastr.size() < max_delims ? datastr : datastr.substr(0,max_delims);
split_no_delim_compress( results, str_1, str_2_short.c_str() );
split_no_delim_compress( results, str_2, str_1_short.c_str() );
split_no_delim_compress( results, datastr, str_2_short.c_str() );
//split_no_delim_compress( results, str_2, datastr_short.c_str() );
//split_no_delim_compress( results, str_1, datastr_short.c_str() );
split_no_delim_compress( results, datastr, str_1_short.c_str() );
//split_no_delim_compress( results, datastr, datastr_short.c_str() );
split_no_delim_compress( results, str_1, datastr_short.c_str() );
//split_no_delim_compress( results, str_1, str_1_short.c_str() );
//split_no_delim_compress( results, str_2, str_2_short.c_str() );
split_no_delim_compress( results, datastr, datastr_short.c_str() );
split_no_delim_compress( results, datastr, "" );
//split_no_delim_compress( results, str_1, "" );
//split_no_delim_compress( results, str_2, "" );
}
print_waypoint( 16 );
utf8_str_len( (const char *)data, size );
utf8_str_len( datastr.c_str(), datastr.size() );
utf8_str_len( str_1.c_str(), str_1.size() );
utf8_str_len( str_2.c_str(), str_2.size() );
print_waypoint( 17 );
utf8_str_len( datastr.c_str() );
utf8_str_len( str_1.c_str() );
utf8_str_len( str_2.c_str() );
print_waypoint( 18 );
{
string s = datastr;
utf8_limit_str_size( s, str1_len );
s = datastr;
utf8_limit_str_size( s, size );
s = str_1;
utf8_limit_str_size( s, str1_len );
s = str_2;
utf8_limit_str_size( s, str1_len );
s = str_1;
utf8_limit_str_size( s, size );
s = str_2;
utf8_limit_str_size( s, size );
}
print_waypoint( 19 );
if( size >= sizeof(float) )
{
float fdummy;
parse_float( (const char *)data, size, fdummy );
parse_float( datastr.c_str(), datastr.size(), fdummy );
parse_float( str_1.c_str(), str_1.size(), fdummy );
parse_float( str_2.c_str(), str_2.size(), fdummy );
}
print_waypoint( 20 );
if( size >= sizeof(int) )
{
int idummy;
parse_int( (const char *)data, size, idummy );
parse_int( datastr.c_str(), datastr.size(), idummy );
parse_int( str_1.c_str(), str_1.size(), idummy );
parse_int( str_2.c_str(), str_2.size(), idummy );
}
print_waypoint( 21 );
{
const size_t max_delims = 16;
const string str_1_short = str_1.size() < max_delims ? str_1 : str_1.substr(0,max_delims);
const string str_2_short = str_2.size() < max_delims ? str_2 : str_2.substr(0,max_delims);
const string datastr_short = datastr.size() < max_delims ? datastr : datastr.substr(0,max_delims);
std::vector<float> fvdummy;
split_to_floats( datastr.c_str(), fvdummy, str_1_short.c_str(), true );
split_to_floats( datastr.c_str(), fvdummy, str_1_short.c_str(), false );
split_to_floats( datastr.c_str(), fvdummy, str_2_short.c_str(), false );
split_to_floats( datastr.c_str(), fvdummy, str_2_short.c_str(), true );
split_to_floats( datastr.c_str(), fvdummy, " ,\r\n\t", true );
split_to_floats( datastr.c_str(), fvdummy, " ,\r\n\t", false );
}
print_waypoint( 22 );
std::vector<float> fvdummy;
split_to_floats( (const char *)data, size, fvdummy );
split_to_floats( str_1.c_str(), str_1.size(), fvdummy );
split_to_floats( str_2.c_str(), str_2.size(), fvdummy );
print_waypoint( 23 );
split_to_floats( datastr, fvdummy );
split_to_floats( str_1, fvdummy );
split_to_floats( str_2, fvdummy );
print_waypoint( 24 );
std::vector<int> fidummy;
split_to_ints( (const char *)data, size, fidummy );
split_to_ints( str_1.c_str(), str_1.size(), fidummy );
split_to_ints( str_2.c_str(), str_2.size(), fidummy );
print_waypoint( 25 );
std::vector<long long> flldummy;
split_to_long_longs( (const char *)data, size, flldummy );
split_to_long_longs( str_1.c_str(), str_1.size(), flldummy );
split_to_long_longs( str_2.c_str(), str_2.size(), flldummy );
print_waypoint( 26 );
convert_from_utf8_to_utf16( datastr );
convert_from_utf8_to_utf16( str_1 );
convert_from_utf8_to_utf16( str_2 );
print_waypoint( 27 );
{
const size_t wlen = sizeof(uint8_t) / sizeof(wchar_t);
const wchar_t * const wbegin = (const wchar_t *)data;
const wchar_t * const wend = wbegin + wlen;
const wstring wdata( wbegin, wend );
convert_from_utf16_to_utf8( wdata );
}
print_waypoint( 28 );
{
const size_t ilen = sizeof(uint8_t) / sizeof(int);
const int * const ibegin = (const int *)data;
const int * const iend = ibegin + ilen;
set<int> sdata( ibegin, iend );
sequencesToBriefString( sdata );
}
print_waypoint( 29 );
const size_t max_lev_str = 64;
levenshtein_distance( datastr, datastr, max_lev_str );
levenshtein_distance( datastr, str_1, max_lev_str );
levenshtein_distance( str_1, datastr, max_lev_str );
levenshtein_distance( datastr, str_2, max_lev_str );
levenshtein_distance( str_2, datastr, max_lev_str );
levenshtein_distance( str_1, str_1, max_lev_str );
levenshtein_distance( str_1, str_2, max_lev_str );
levenshtein_distance( str_2, str_1, max_lev_str );
levenshtein_distance( str_2, str_2, max_lev_str );
levenshtein_distance( datastr, "", max_lev_str );
levenshtein_distance( "", datastr, max_lev_str );
levenshtein_distance( str_1, "", max_lev_str );
levenshtein_distance( "", str_1, max_lev_str );
levenshtein_distance( str_2, "", max_lev_str );
levenshtein_distance( "", str_2, max_lev_str );
print_waypoint( 30 );
// Filesystem functions we can test
lexically_normalize_path( datastr );
lexically_normalize_path( str_1 );
lexically_normalize_path( str_2 );
lexically_normalize_path( datastr + "../" );
lexically_normalize_path( "/" + datastr + "../" ); //we could go wild doing various combination of path delimeiters
print_waypoint( 31 );
likely_not_spec_file( datastr );
likely_not_spec_file( str_1 );
likely_not_spec_file( str_2 );
print_waypoint( 32 );
append_path( datastr, datastr );
append_path( datastr, str_1 );
append_path( str_1, datastr );
append_path( datastr, str_2 );
append_path( str_2, datastr );
append_path( str_1, str_1 );
append_path( str_1, str_2 );
append_path( str_2, str_1 );
append_path( str_2, str_2 );
append_path( str_1, "" );
append_path( "", str_1 );
append_path( datastr, "" );
append_path( "", datastr );
print_waypoint( 33 );
try{ file_extension( datastr ); }catch( std::exception & ){ }
try{ file_extension( str_1 ); }catch( std::exception & ){ }
try{ file_extension( str_2 ); }catch( std::exception & ){ }
print_waypoint( 34 );
temp_file_name( datastr, datastr );
temp_file_name( datastr, str_1 );
temp_file_name( datastr, str_2 );
temp_file_name( str_1, datastr );
temp_file_name( str_2, datastr );
temp_file_name( str_1, str_1 );
temp_file_name( str_1, str_2 );
temp_file_name( str_2, str_1 );
temp_file_name( str_2, str_2 );
print_waypoint( 35 );
{
// Having a large sizes can cause things to go pretty slowly, so we'll
// limit things, to 256 arbitrarily.
// We'll keep one full-length, and comment out a number of the possible cases
const size_t max_fs_rel_len = 256;
const string str_1_short = str_1.size() < max_fs_rel_len ? str_1 : str_1.substr(0,max_fs_rel_len);
const string str_2_short = str_2.size() < max_fs_rel_len ? str_2 : str_2.substr(0,max_fs_rel_len);
const string datastr_short = datastr.size() < max_fs_rel_len ? datastr : datastr.substr(0,max_fs_rel_len);
if( datastr.size() < 1024)
fs_relative( datastr, str_2 ); //full path
else
fs_relative( datastr_short, str_2_short ); //full path
fs_relative( datastr_short, datastr_short );
fs_relative( datastr_short, str_1_short );
//fs_relative( datastr_short, str_2_short );
fs_relative( str_1_short, datastr_short );
//fs_relative( str_2_short, datastr_short );
//fs_relative( str_1_short, str_1_short );
//fs_relative( str_2_short, str_2_short );
//fs_relative( str_1_short, str_2_short );
fs_relative( str_2_short, str_1_short );
fs_relative( datastr_short, "" );
//fs_relative( str_1_short, "" );
//fs_relative( str_2_short, "" );
fs_relative( "", datastr_short );
//fs_relative( "", str_1_short );
//fs_relative( "", str_2_short );
}
print_waypoint( 36 );
try{ filename( datastr ); }catch(const std::exception&){}
try{ filename( str_1 ); }catch(const std::exception&){}
try{ filename( str_2 ); }catch(const std::exception&){}
print_waypoint( 37 );
try{ parent_path( datastr ); } catch(const std::exception&){}
try{ parent_path( str_1 ); } catch(const std::exception&){}
try{ parent_path( str_2 ); } catch(const std::exception&){}
print_waypoint( 38 );
// Filesystem functions we cant really test here
// bool remove_file( const std::string &name );
// bool rename_file( const std::string &source, const std::string &destination );
// int create_directory( const std::string &name );
// static const size_t sm_recursive_ls_max_depth = 25;
// static const size_t sm_ls_max_results = 100000;
// typedef bool(*file_match_function_t)( const std::string &filename, void *userdata );
// std::vector<std::string> recursive_ls( const std::string &sourcedir,
// const std::string &ending = "" );
// std::vector<std::string> recursive_ls( const std::string &sourcedir,
// file_match_function_t match_fcn,
// void *user_data );
// std::vector<std::string> ls_files_in_directory( const std::string &sourcedir,
// const std::string &ending = "" );
// std::vector<std::string> ls_files_in_directory( const std::string &sourcedir,
// file_match_function_t match_fcn,
// void *match_data );
// std::vector<std::string> ls_directories_in_directory( const std::string &src );
// bool is_file( const std::string &name );
// bool is_directory( const std::string &name );
// bool can_rw_in_directory( const std::string &name );
// size_t file_size( const std::string &path );
// std::string temp_dir();
// std::string get_working_path();
// bool is_absolute_path( const std::string &path );
// bool make_canonical_path( std::string &path, const std::string &cwd = "" );
// void load_file_data( const char * const filename, std::vector<char> &data );
// Date/Time functions we can test
auto test_to_str = []( const SpecUtils::time_point_t dt ){
if( SpecUtils::is_special(dt) )
return;
to_vax_string( dt );
to_common_string( dt, true );
to_common_string( dt, false );
to_extended_iso_string( dt );
SpecUtils::to_iso_string( dt );
};//test_to_str(...)
print_waypoint( 39 );
{
const size_t max_time_strlen = 96;
const string str_1_short = str_1.size() < max_time_strlen ? str_1 : str_1.substr(0,max_time_strlen);
const string str_2_short = str_2.size() < max_time_strlen ? str_2 : str_2.substr(0,max_time_strlen);
const string datastr_short = datastr.size() < max_time_strlen ? datastr : datastr.substr(0,max_time_strlen);
auto dt = time_from_string( datastr_short.c_str() );
test_to_str( dt );
dt = time_from_string( str_1_short.c_str() );
test_to_str( dt );
dt = time_from_string( str_2_short.c_str() );
test_to_str( dt );
print_waypoint( 40 );
test_to_str( time_from_string( datastr_short, DateParseEndianType::LittleEndianFirst ) );
//test_to_str( time_from_string( datastr_short, DateParseEndianType::LittleEndianOnly ) );
test_to_str( time_from_string( datastr_short, DateParseEndianType::MiddleEndianFirst ) );
//test_to_str( time_from_string( datastr_short, DateParseEndianType::MiddleEndianOnly ) );
print_waypoint( 41 );
test_to_str( time_from_string( str_1_short, DateParseEndianType::LittleEndianFirst ) );
//test_to_str( time_from_string( str_1_short, DateParseEndianType::LittleEndianOnly ) );
test_to_str( time_from_string( str_1_short, DateParseEndianType::MiddleEndianFirst ) );
//test_to_str( time_from_string( str_1_short, DateParseEndianType::MiddleEndianOnly ) );
print_waypoint( 42 );
test_to_str( time_from_string( str_2_short, DateParseEndianType::LittleEndianFirst ) );
//test_to_str( time_from_string( str_2_short, DateParseEndianType::LittleEndianOnly ) );
test_to_str( time_from_string( str_2_short, DateParseEndianType::MiddleEndianFirst ) );
//test_to_str( time_from_string( str_2_short, DateParseEndianType::MiddleEndianOnly ) );
}
print_waypoint( 43 );
time_duration_string_to_seconds( datastr );
time_duration_string_to_seconds( str_1 );
time_duration_string_to_seconds( str_2 );
print_waypoint( 44 );
try{ delimited_duration_string_to_seconds( datastr ); }catch(std::exception &){ }
try{ delimited_duration_string_to_seconds( str_1 ); }catch(std::exception &){ }
try{ delimited_duration_string_to_seconds( str_2 ); }catch(std::exception &){ }
print_waypoint( 45 );
// Test for Parse Utils
{
const size_t max_len = std::max( size_t(1), distribution(generator));
string dummy;
stringstream strm( datastr ), strm_1( str_1 ), strm_2( str_2 );
while( safe_get_line( strm, dummy, max_len) ){}
while( safe_get_line( strm_1, dummy, max_len) ){}
while( safe_get_line( strm_2, dummy, max_len) ){}
}
print_waypoint( 46 );
{
double lat, lon;
const size_t max_deg_strlen = 64;
const string str_1_short = str_1.size() < max_deg_strlen ? str_1 : str_1.substr(0,max_deg_strlen);
const string str_2_short = str_2.size() < max_deg_strlen ? str_2 : str_2.substr(0,max_deg_strlen);
const string datastr_short = datastr.size() < max_deg_strlen ? datastr : datastr.substr(0,max_deg_strlen);
parse_deg_min_sec_lat_lon( datastr_short.c_str(), datastr_short.size(), lat, lon );
parse_deg_min_sec_lat_lon( str_1_short.c_str(), str_1_short.size(), lat, lon );
parse_deg_min_sec_lat_lon( str_2_short.c_str(), str_2_short.size(), lat, lon );
}
print_waypoint( 47 );
conventional_lat_or_long_str_to_flt( datastr );
conventional_lat_or_long_str_to_flt( str_1 );
conventional_lat_or_long_str_to_flt( str_2 );
print_waypoint( 48 );
sample_num_from_remark( datastr );
sample_num_from_remark( str_1 );
sample_num_from_remark( str_2 );
print_waypoint( 49 );
try{ speed_from_remark( datastr ); }catch(std::exception &){}
try{ speed_from_remark( str_1 ); }catch(std::exception &){}
try{ speed_from_remark( str_2 ); }catch(std::exception &){}
print_waypoint( 50 );
detector_name_from_remark( datastr );
detector_name_from_remark( str_1 );
detector_name_from_remark( str_2 );
print_waypoint( 51 );
try{ dx_from_remark( datastr ); }catch(std::exception &){}
try{ dx_from_remark( str_1 ); }catch(std::exception &){}
try{ dx_from_remark( str_2 ); }catch(std::exception &){}
print_waypoint( 52 );
try{ dy_from_remark( datastr ); }catch(std::exception &){}
try{ dy_from_remark( str_1 ); }catch(std::exception &){}
try{ dy_from_remark( str_2 ); }catch(std::exception &){}
print_waypoint( 53 );
try{ dose_units_usvPerH( (const char *)data, size ); }catch(std::exception &){}
//dose_units_usvPerH( datastr.c_str(), datastr.size() );
//dose_units_usvPerH( str_1.c_str(), str_1.size() );
//dose_units_usvPerH( str_2.c_str(), str_2.size() );
print_waypoint( 54 );
convert_n42_instrument_type_from_2006_to_2012( datastr );
convert_n42_instrument_type_from_2006_to_2012( str_1 );
convert_n42_instrument_type_from_2006_to_2012( str_1 );
print_waypoint( 55 );
// ParseUtils functions it may not make total sense to test.
//void expand_counted_zeros( const std::vector<float> &data, std::vector<float> &results );
//void compress_to_counted_zeros( const std::vector<float> &data, std::vector<float> &results );
//bool valid_latitude( const double latitude );
//bool valid_longitude( const double longitude );
//std::istream &read_binary_data( std::istream &input, T &val );
//size_t write_binary_data( std::ostream &input, const T &val );
#if( SpecUtils_ENABLE_D3_CHART )
{
D3SpectrumExport::escape_text_test( datastr );
char buf[4];
for( const char *c = datastr.c_str(); *c; )
{
char *b = buf;
D3SpectrumExport::copy_check_utf8_test(c, b);
}
std::stringstream outstrm;
D3SpectrumExport::sanitize_unicode_test( outstrm, datastr );
}
#endif
return 0;
}//LLVMFuzzerTestOneInput