1 | #include <IO/readFloatText.h> |
2 | |
3 | namespace DB |
4 | { |
5 | |
6 | namespace ErrorCodes |
7 | { |
8 | extern const int CANNOT_PARSE_INPUT_ASSERTION_FAILED; |
9 | } |
10 | |
11 | /** Must successfully parse inf, INF and Infinity. |
12 | * All other variants in different cases are also parsed for simplicity. |
13 | */ |
14 | bool parseInfinity(ReadBuffer & buf) |
15 | { |
16 | if (!checkStringCaseInsensitive("inf" , buf)) |
17 | return false; |
18 | |
19 | /// Just inf. |
20 | if (buf.eof() || !isWordCharASCII(*buf.position())) |
21 | return true; |
22 | |
23 | /// If word characters after inf, it should be infinity. |
24 | return checkStringCaseInsensitive("inity" , buf); |
25 | } |
26 | |
27 | |
28 | /** Must successfully parse nan, NAN and NaN. |
29 | * All other variants in different cases are also parsed for simplicity. |
30 | */ |
31 | bool parseNaN(ReadBuffer & buf) |
32 | { |
33 | return checkStringCaseInsensitive("nan" , buf); |
34 | } |
35 | |
36 | |
37 | void assertInfinity(ReadBuffer & buf) |
38 | { |
39 | if (!parseInfinity(buf)) |
40 | throw Exception("Cannot parse infinity." , ErrorCodes::CANNOT_PARSE_INPUT_ASSERTION_FAILED); |
41 | } |
42 | |
43 | void assertNaN(ReadBuffer & buf) |
44 | { |
45 | if (!parseNaN(buf)) |
46 | throw Exception("Cannot parse NaN." , ErrorCodes::CANNOT_PARSE_INPUT_ASSERTION_FAILED); |
47 | } |
48 | |
49 | |
50 | template void readFloatTextPrecise<Float32>(Float32 &, ReadBuffer &); |
51 | template void readFloatTextPrecise<Float64>(Float64 &, ReadBuffer &); |
52 | template bool tryReadFloatTextPrecise<Float32>(Float32 &, ReadBuffer &); |
53 | template bool tryReadFloatTextPrecise<Float64>(Float64 &, ReadBuffer &); |
54 | |
55 | template void readFloatTextFast<Float32>(Float32 &, ReadBuffer &); |
56 | template void readFloatTextFast<Float64>(Float64 &, ReadBuffer &); |
57 | template bool tryReadFloatTextFast<Float32>(Float32 &, ReadBuffer &); |
58 | template bool tryReadFloatTextFast<Float64>(Float64 &, ReadBuffer &); |
59 | |
60 | template void readFloatTextSimple<Float32>(Float32 &, ReadBuffer &); |
61 | template void readFloatTextSimple<Float64>(Float64 &, ReadBuffer &); |
62 | template bool tryReadFloatTextSimple<Float32>(Float32 &, ReadBuffer &); |
63 | template bool tryReadFloatTextSimple<Float64>(Float64 &, ReadBuffer &); |
64 | |
65 | template void readFloatText<Float32>(Float32 &, ReadBuffer &); |
66 | template void readFloatText<Float64>(Float64 &, ReadBuffer &); |
67 | template bool tryReadFloatText<Float32>(Float32 &, ReadBuffer &); |
68 | template bool tryReadFloatText<Float64>(Float64 &, ReadBuffer &); |
69 | |
70 | } |
71 | |