File tree 1 file changed +29
-23
lines changed
1 file changed +29
-23
lines changed Original file line number Diff line number Diff line change @@ -9,32 +9,38 @@ namespace {
9
9
template <typename T>
10
10
bool GenericTryFloatFromString (TStringBuf buf, T& value) {
11
11
value = 0 ;
12
- if (!buf.size () || !TryFromString (buf.data (), buf.size (), value)) {
13
- const char * ptr = buf.data ();
14
- ui32 size = buf.size ();
15
- char sign = ' +' ;
16
- if (*ptr == ' +' || *ptr == ' -' ) {
17
- sign = *ptr;
18
- ++ptr;
19
- --size;
20
- }
12
+ if (!buf.size ()) {
13
+ return false ;
14
+ }
15
+
16
+ if (TryFromString (buf.data (), buf.size (), value)) {
17
+ return true ;
18
+ }
19
+
20
+ const char * ptr = buf.data ();
21
+ ui32 size = buf.size ();
22
+ char sign = ' +' ;
23
+ if (*ptr == ' +' || *ptr == ' -' ) {
24
+ sign = *ptr;
25
+ ++ptr;
26
+ --size;
27
+ }
21
28
22
- if (size != 3 ) {
23
- return false ;
24
- }
29
+ if (size != 3 ) {
30
+ return false ;
31
+ }
25
32
26
- // NaN or Inf (ignoring case)
27
- if (AsciiToUpper (ptr[0 ]) == ' N' && AsciiToUpper (ptr[1 ]) == ' A' && AsciiToUpper (ptr[2 ]) == ' N' ) {
28
- value = std::numeric_limits<T>::quiet_NaN ();
29
- } else if (AsciiToUpper (ptr[0 ]) == ' I' && AsciiToUpper (ptr[1 ]) == ' N' && AsciiToUpper (ptr[2 ]) == ' F' ) {
30
- value = std::numeric_limits<T>::infinity ();
31
- } else {
32
- return false ;
33
- }
33
+ // NaN or Inf (ignoring case)
34
+ if (AsciiToUpper (ptr[0 ]) == ' N' && AsciiToUpper (ptr[1 ]) == ' A' && AsciiToUpper (ptr[2 ]) == ' N' ) {
35
+ value = std::numeric_limits<T>::quiet_NaN ();
36
+ } else if (AsciiToUpper (ptr[0 ]) == ' I' && AsciiToUpper (ptr[1 ]) == ' N' && AsciiToUpper (ptr[2 ]) == ' F' ) {
37
+ value = std::numeric_limits<T>::infinity ();
38
+ } else {
39
+ return false ;
40
+ }
34
41
35
- if (sign == ' -' ) {
36
- value = -value;
37
- }
42
+ if (sign == ' -' ) {
43
+ value = -value;
38
44
}
39
45
40
46
return true ;
You can’t perform that action at this time.
0 commit comments