17
17
18
18
#include < string>
19
19
#include < memory>
20
+ #include < charconv>
20
21
21
22
#include " src/operators/operator.h"
22
23
@@ -29,34 +30,29 @@ bool ValidateByteRange::getRange(const std::string &rangeRepresentation,
29
30
int start;
30
31
int end;
31
32
32
- if (pos == std::string::npos) {
33
- try {
34
- start = std::stoi (rangeRepresentation);
35
- } catch (...) {
33
+ if (pos == std::string::npos) {
34
+ const auto conv_res = std::from_chars (rangeRepresentation.data (), rangeRepresentation.data () + rangeRepresentation.size (), start);
35
+ if (conv_res.ec == std::errc::invalid_argument) {
36
36
error->assign (" Not able to convert '" + rangeRepresentation +
37
37
" ' into a number" );
38
38
return false ;
39
39
}
40
+
40
41
table[start >> 3 ] = (table[start >> 3 ] | (1 << (start & 0x7 )));
41
42
return true ;
42
43
}
43
44
44
- try {
45
- start = std::stoi (std::string (rangeRepresentation, 0 , pos));
46
- } catch (...) {
47
- error->assign (" Not able to convert '" +
48
- std::string (rangeRepresentation, 0 , pos) +
49
- " ' into a number" );
45
+ std::string to_be_converted (rangeRepresentation, 0 , pos);
46
+ const auto conv_res2 = std::from_chars (to_be_converted.data (), to_be_converted.data () + to_be_converted.size (), start);
47
+ if (conv_res2.ec == std::errc::invalid_argument) {
48
+ error->assign (" Not able to convert '" + to_be_converted + " ' into a number" );
50
49
return false ;
51
50
}
52
51
53
- try {
54
- end = std::stoi (std::string (rangeRepresentation, pos + 1 ,
55
- rangeRepresentation.length () - (pos + 1 )));
56
- } catch (...) {
57
- error->assign (" Not able to convert '" + std::string (rangeRepresentation,
58
- pos + 1 , rangeRepresentation.length () - (pos + 1 )) +
59
- " ' into a number" );
52
+ std::string to_be_converted2 (rangeRepresentation, pos + 1 , rangeRepresentation.length () - (pos + 1 ));
53
+ const auto conv_res3 = std::from_chars (to_be_converted2.data (), to_be_converted2.data () + to_be_converted2.size (), end);
54
+ if (conv_res3.ec == std::errc::invalid_argument) {
55
+ error->assign (" Not able to convert '" + to_be_converted2 + " ' into a number" );
60
56
return false ;
61
57
}
62
58
0 commit comments