quickfix_ruby_ud 2.0.7-aarch64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. checksums.yaml +7 -0
  2. data/ext/quickfix/Acceptor.cpp +257 -0
  3. data/ext/quickfix/Acceptor.h +127 -0
  4. data/ext/quickfix/Allocator.h +9 -0
  5. data/ext/quickfix/Application.h +137 -0
  6. data/ext/quickfix/DOMDocument.h +70 -0
  7. data/ext/quickfix/DataDictionary.cpp +679 -0
  8. data/ext/quickfix/DataDictionary.h +607 -0
  9. data/ext/quickfix/DataDictionaryProvider.cpp +66 -0
  10. data/ext/quickfix/DataDictionaryProvider.h +67 -0
  11. data/ext/quickfix/DatabaseConnectionID.h +98 -0
  12. data/ext/quickfix/DatabaseConnectionPool.h +84 -0
  13. data/ext/quickfix/Dictionary.cpp +157 -0
  14. data/ext/quickfix/Dictionary.h +89 -0
  15. data/ext/quickfix/Event.h +89 -0
  16. data/ext/quickfix/Except.h +39 -0
  17. data/ext/quickfix/Exceptions.h +257 -0
  18. data/ext/quickfix/Field.h +654 -0
  19. data/ext/quickfix/FieldConvertors.cpp +86 -0
  20. data/ext/quickfix/FieldConvertors.h +800 -0
  21. data/ext/quickfix/FieldMap.cpp +254 -0
  22. data/ext/quickfix/FieldMap.h +327 -0
  23. data/ext/quickfix/FieldNumbers.h +44 -0
  24. data/ext/quickfix/FieldTypes.cpp +62 -0
  25. data/ext/quickfix/FieldTypes.h +817 -0
  26. data/ext/quickfix/Fields.h +30 -0
  27. data/ext/quickfix/FileLog.cpp +176 -0
  28. data/ext/quickfix/FileLog.h +110 -0
  29. data/ext/quickfix/FileStore.cpp +369 -0
  30. data/ext/quickfix/FileStore.h +131 -0
  31. data/ext/quickfix/FixCommonFields.h +13 -0
  32. data/ext/quickfix/FixFieldNumbers.h +6132 -0
  33. data/ext/quickfix/FixFields.h +6133 -0
  34. data/ext/quickfix/FixValues.h +5790 -0
  35. data/ext/quickfix/Group.cpp +44 -0
  36. data/ext/quickfix/Group.h +78 -0
  37. data/ext/quickfix/HostDetailsProvider.cpp +79 -0
  38. data/ext/quickfix/HostDetailsProvider.h +44 -0
  39. data/ext/quickfix/HtmlBuilder.h +178 -0
  40. data/ext/quickfix/HttpConnection.cpp +914 -0
  41. data/ext/quickfix/HttpConnection.h +74 -0
  42. data/ext/quickfix/HttpMessage.cpp +229 -0
  43. data/ext/quickfix/HttpMessage.h +112 -0
  44. data/ext/quickfix/HttpParser.cpp +49 -0
  45. data/ext/quickfix/HttpParser.h +49 -0
  46. data/ext/quickfix/HttpServer.cpp +152 -0
  47. data/ext/quickfix/HttpServer.h +76 -0
  48. data/ext/quickfix/Initiator.cpp +310 -0
  49. data/ext/quickfix/Initiator.h +151 -0
  50. data/ext/quickfix/Log.cpp +71 -0
  51. data/ext/quickfix/Log.h +254 -0
  52. data/ext/quickfix/Message.cpp +617 -0
  53. data/ext/quickfix/Message.h +419 -0
  54. data/ext/quickfix/MessageCracker.h +171 -0
  55. data/ext/quickfix/MessageSorters.cpp +101 -0
  56. data/ext/quickfix/MessageSorters.h +185 -0
  57. data/ext/quickfix/MessageStore.cpp +182 -0
  58. data/ext/quickfix/MessageStore.h +164 -0
  59. data/ext/quickfix/Mutex.h +120 -0
  60. data/ext/quickfix/MySQLConnection.h +187 -0
  61. data/ext/quickfix/MySQLLog.cpp +262 -0
  62. data/ext/quickfix/MySQLLog.h +158 -0
  63. data/ext/quickfix/MySQLStore.cpp +323 -0
  64. data/ext/quickfix/MySQLStore.h +161 -0
  65. data/ext/quickfix/MySQLStubs.h +203 -0
  66. data/ext/quickfix/NullStore.cpp +40 -0
  67. data/ext/quickfix/NullStore.h +89 -0
  68. data/ext/quickfix/OdbcConnection.h +241 -0
  69. data/ext/quickfix/OdbcLog.cpp +230 -0
  70. data/ext/quickfix/OdbcLog.h +109 -0
  71. data/ext/quickfix/OdbcStore.cpp +313 -0
  72. data/ext/quickfix/OdbcStore.h +124 -0
  73. data/ext/quickfix/PUGIXML_DOMDocument.cpp +112 -0
  74. data/ext/quickfix/PUGIXML_DOMDocument.h +81 -0
  75. data/ext/quickfix/Parser.cpp +111 -0
  76. data/ext/quickfix/Parser.h +50 -0
  77. data/ext/quickfix/PostgreSQLConnection.h +163 -0
  78. data/ext/quickfix/PostgreSQLLog.cpp +263 -0
  79. data/ext/quickfix/PostgreSQLLog.h +157 -0
  80. data/ext/quickfix/PostgreSQLStore.cpp +327 -0
  81. data/ext/quickfix/PostgreSQLStore.h +160 -0
  82. data/ext/quickfix/PostgreSQLStubs.h +203 -0
  83. data/ext/quickfix/Queue.h +66 -0
  84. data/ext/quickfix/QuickfixRuby.cpp +131900 -0
  85. data/ext/quickfix/QuickfixRuby.h +56 -0
  86. data/ext/quickfix/Responder.h +41 -0
  87. data/ext/quickfix/SSLSocketAcceptor.cpp +409 -0
  88. data/ext/quickfix/SSLSocketAcceptor.h +186 -0
  89. data/ext/quickfix/SSLSocketConnection.cpp +434 -0
  90. data/ext/quickfix/SSLSocketConnection.h +221 -0
  91. data/ext/quickfix/SSLSocketInitiator.cpp +558 -0
  92. data/ext/quickfix/SSLSocketInitiator.h +203 -0
  93. data/ext/quickfix/SSLStubs.h +129 -0
  94. data/ext/quickfix/Session.cpp +1437 -0
  95. data/ext/quickfix/Session.h +343 -0
  96. data/ext/quickfix/SessionFactory.cpp +314 -0
  97. data/ext/quickfix/SessionFactory.h +84 -0
  98. data/ext/quickfix/SessionID.h +136 -0
  99. data/ext/quickfix/SessionSettings.cpp +165 -0
  100. data/ext/quickfix/SessionSettings.h +283 -0
  101. data/ext/quickfix/SessionState.h +260 -0
  102. data/ext/quickfix/Settings.cpp +160 -0
  103. data/ext/quickfix/Settings.h +56 -0
  104. data/ext/quickfix/SharedArray.h +274 -0
  105. data/ext/quickfix/SocketAcceptor.cpp +216 -0
  106. data/ext/quickfix/SocketAcceptor.h +77 -0
  107. data/ext/quickfix/SocketConnection.cpp +256 -0
  108. data/ext/quickfix/SocketConnection.h +102 -0
  109. data/ext/quickfix/SocketConnector.cpp +112 -0
  110. data/ext/quickfix/SocketConnector.h +76 -0
  111. data/ext/quickfix/SocketInitiator.cpp +241 -0
  112. data/ext/quickfix/SocketInitiator.h +76 -0
  113. data/ext/quickfix/SocketMonitor.h +26 -0
  114. data/ext/quickfix/SocketMonitor_UNIX.cpp +238 -0
  115. data/ext/quickfix/SocketMonitor_UNIX.h +101 -0
  116. data/ext/quickfix/SocketMonitor_WIN32.cpp +248 -0
  117. data/ext/quickfix/SocketMonitor_WIN32.h +99 -0
  118. data/ext/quickfix/SocketServer.cpp +163 -0
  119. data/ext/quickfix/SocketServer.h +100 -0
  120. data/ext/quickfix/ThreadedSSLSocketAcceptor.cpp +436 -0
  121. data/ext/quickfix/ThreadedSSLSocketAcceptor.h +209 -0
  122. data/ext/quickfix/ThreadedSSLSocketConnection.cpp +364 -0
  123. data/ext/quickfix/ThreadedSSLSocketConnection.h +191 -0
  124. data/ext/quickfix/ThreadedSSLSocketInitiator.cpp +434 -0
  125. data/ext/quickfix/ThreadedSSLSocketInitiator.h +193 -0
  126. data/ext/quickfix/ThreadedSocketAcceptor.cpp +242 -0
  127. data/ext/quickfix/ThreadedSocketAcceptor.h +95 -0
  128. data/ext/quickfix/ThreadedSocketConnection.cpp +227 -0
  129. data/ext/quickfix/ThreadedSocketConnection.h +89 -0
  130. data/ext/quickfix/ThreadedSocketInitiator.cpp +238 -0
  131. data/ext/quickfix/ThreadedSocketInitiator.h +78 -0
  132. data/ext/quickfix/TimeRange.cpp +227 -0
  133. data/ext/quickfix/TimeRange.h +215 -0
  134. data/ext/quickfix/Utility.cpp +639 -0
  135. data/ext/quickfix/Utility.h +255 -0
  136. data/ext/quickfix/UtilitySSL.cpp +1612 -0
  137. data/ext/quickfix/UtilitySSL.h +274 -0
  138. data/ext/quickfix/Values.h +63 -0
  139. data/ext/quickfix/config-all.h +10 -0
  140. data/ext/quickfix/config.h +10 -0
  141. data/ext/quickfix/config_unix.h +178 -0
  142. data/ext/quickfix/config_windows.h +0 -0
  143. data/ext/quickfix/dirent_windows.h +838 -0
  144. data/ext/quickfix/double-conversion/bignum-dtoa.cc +641 -0
  145. data/ext/quickfix/double-conversion/bignum-dtoa.h +84 -0
  146. data/ext/quickfix/double-conversion/bignum.cc +766 -0
  147. data/ext/quickfix/double-conversion/bignum.h +144 -0
  148. data/ext/quickfix/double-conversion/cached-powers.cc +176 -0
  149. data/ext/quickfix/double-conversion/cached-powers.h +64 -0
  150. data/ext/quickfix/double-conversion/diy-fp.cc +57 -0
  151. data/ext/quickfix/double-conversion/diy-fp.h +118 -0
  152. data/ext/quickfix/double-conversion/double-conversion.cc +994 -0
  153. data/ext/quickfix/double-conversion/double-conversion.h +543 -0
  154. data/ext/quickfix/double-conversion/fast-dtoa.cc +665 -0
  155. data/ext/quickfix/double-conversion/fast-dtoa.h +88 -0
  156. data/ext/quickfix/double-conversion/fixed-dtoa.cc +404 -0
  157. data/ext/quickfix/double-conversion/fixed-dtoa.h +56 -0
  158. data/ext/quickfix/double-conversion/ieee.h +402 -0
  159. data/ext/quickfix/double-conversion/strtod.cc +557 -0
  160. data/ext/quickfix/double-conversion/strtod.h +45 -0
  161. data/ext/quickfix/double-conversion/utils.h +374 -0
  162. data/ext/quickfix/extconf.rb +76 -0
  163. data/ext/quickfix/index.h +37 -0
  164. data/ext/quickfix/pugiconfig.hpp +77 -0
  165. data/ext/quickfix/pugixml.cpp +13237 -0
  166. data/ext/quickfix/pugixml.hpp +1516 -0
  167. data/ext/quickfix/scope_guard.hpp +215 -0
  168. data/ext/quickfix/stdint_msvc.h +254 -0
  169. data/ext/quickfix/strptime.h +7 -0
  170. data/lib/2.4/quickfix.so +0 -0
  171. data/lib/2.5/quickfix.so +0 -0
  172. data/lib/2.6/quickfix.so +0 -0
  173. data/lib/2.7/quickfix.so +0 -0
  174. data/lib/3.0/quickfix.so +0 -0
  175. data/lib/3.1/quickfix.so +0 -0
  176. data/lib/3.2/quickfix.so +0 -0
  177. data/lib/3.3/quickfix.so +0 -0
  178. data/lib/3.4/quickfix.so +0 -0
  179. data/lib/quickfix40.rb +274 -0
  180. data/lib/quickfix41.rb +351 -0
  181. data/lib/quickfix42.rb +1184 -0
  182. data/lib/quickfix43.rb +3504 -0
  183. data/lib/quickfix44.rb +14040 -0
  184. data/lib/quickfix50.rb +20051 -0
  185. data/lib/quickfix50sp1.rb +23596 -0
  186. data/lib/quickfix50sp2.rb +412444 -0
  187. data/lib/quickfix_fields.rb +79393 -0
  188. data/lib/quickfix_ruby.rb +82 -0
  189. data/lib/quickfixt11.rb +65 -0
  190. data/spec/FIX40.xml +862 -0
  191. data/spec/FIX41.xml +1282 -0
  192. data/spec/FIX42.xml +2743 -0
  193. data/spec/FIX43.xml +4230 -0
  194. data/spec/FIX44.xml +6600 -0
  195. data/spec/FIX50.xml +8142 -0
  196. data/spec/FIX50SP1.xml +9506 -0
  197. data/spec/FIX50SP2.xml +26069 -0
  198. data/spec/FIXT11.xml +252 -0
  199. data/test/DataDictionaryTestCase.rb +268 -0
  200. data/test/DictionaryTestCase.rb +112 -0
  201. data/test/FieldBaseTestCase.rb +24 -0
  202. data/test/MessageStoreTestCase.rb +19 -0
  203. data/test/MessageTestCase.rb +368 -0
  204. data/test/SessionSettingsTestCase.rb +41 -0
  205. metadata +247 -0
@@ -0,0 +1,543 @@
1
+ // Copyright 2012 the V8 project authors. All rights reserved.
2
+ // Redistribution and use in source and binary forms, with or without
3
+ // modification, are permitted provided that the following conditions are
4
+ // met:
5
+ //
6
+ // * Redistributions of source code must retain the above copyright
7
+ // notice, this list of conditions and the following disclaimer.
8
+ // * Redistributions in binary form must reproduce the above
9
+ // copyright notice, this list of conditions and the following
10
+ // disclaimer in the documentation and/or other materials provided
11
+ // with the distribution.
12
+ // * Neither the name of Google Inc. nor the names of its
13
+ // contributors may be used to endorse or promote products derived
14
+ // from this software without specific prior written permission.
15
+ //
16
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #ifndef DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_
29
+ #define DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_
30
+
31
+ #include "double-conversion/utils.h"
32
+
33
+ namespace double_conversion {
34
+
35
+ class DoubleToStringConverter {
36
+ public:
37
+ // When calling ToFixed with a double > 10^kMaxFixedDigitsBeforePoint
38
+ // or a requested_digits parameter > kMaxFixedDigitsAfterPoint then the
39
+ // function returns false.
40
+ static const int kMaxFixedDigitsBeforePoint = 60;
41
+ static const int kMaxFixedDigitsAfterPoint = 60;
42
+
43
+ // When calling ToExponential with a requested_digits
44
+ // parameter > kMaxExponentialDigits then the function returns false.
45
+ static const int kMaxExponentialDigits = 120;
46
+
47
+ // When calling ToPrecision with a requested_digits
48
+ // parameter < kMinPrecisionDigits or requested_digits > kMaxPrecisionDigits
49
+ // then the function returns false.
50
+ static const int kMinPrecisionDigits = 1;
51
+ static const int kMaxPrecisionDigits = 120;
52
+
53
+ enum Flags {
54
+ NO_FLAGS = 0,
55
+ EMIT_POSITIVE_EXPONENT_SIGN = 1,
56
+ EMIT_TRAILING_DECIMAL_POINT = 2,
57
+ EMIT_TRAILING_ZERO_AFTER_POINT = 4,
58
+ UNIQUE_ZERO = 8
59
+ };
60
+
61
+ // Flags should be a bit-or combination of the possible Flags-enum.
62
+ // - NO_FLAGS: no special flags.
63
+ // - EMIT_POSITIVE_EXPONENT_SIGN: when the number is converted into exponent
64
+ // form, emits a '+' for positive exponents. Example: 1.2e+2.
65
+ // - EMIT_TRAILING_DECIMAL_POINT: when the input number is an integer and is
66
+ // converted into decimal format then a trailing decimal point is appended.
67
+ // Example: 2345.0 is converted to "2345.".
68
+ // - EMIT_TRAILING_ZERO_AFTER_POINT: in addition to a trailing decimal point
69
+ // emits a trailing '0'-character. This flag requires the
70
+ // EXMIT_TRAILING_DECIMAL_POINT flag.
71
+ // Example: 2345.0 is converted to "2345.0".
72
+ // - UNIQUE_ZERO: "-0.0" is converted to "0.0".
73
+ //
74
+ // Infinity symbol and nan_symbol provide the string representation for these
75
+ // special values. If the string is NULL and the special value is encountered
76
+ // then the conversion functions return false.
77
+ //
78
+ // The exponent_character is used in exponential representations. It is
79
+ // usually 'e' or 'E'.
80
+ //
81
+ // When converting to the shortest representation the converter will
82
+ // represent input numbers in decimal format if they are in the interval
83
+ // [10^decimal_in_shortest_low; 10^decimal_in_shortest_high[
84
+ // (lower boundary included, greater boundary excluded).
85
+ // Example: with decimal_in_shortest_low = -6 and
86
+ // decimal_in_shortest_high = 21:
87
+ // ToShortest(0.000001) -> "0.000001"
88
+ // ToShortest(0.0000001) -> "1e-7"
89
+ // ToShortest(111111111111111111111.0) -> "111111111111111110000"
90
+ // ToShortest(100000000000000000000.0) -> "100000000000000000000"
91
+ // ToShortest(1111111111111111111111.0) -> "1.1111111111111111e+21"
92
+ //
93
+ // When converting to precision mode the converter may add
94
+ // max_leading_padding_zeroes before returning the number in exponential
95
+ // format.
96
+ // Example with max_leading_padding_zeroes_in_precision_mode = 6.
97
+ // ToPrecision(0.0000012345, 2) -> "0.0000012"
98
+ // ToPrecision(0.00000012345, 2) -> "1.2e-7"
99
+ // Similarily the converter may add up to
100
+ // max_trailing_padding_zeroes_in_precision_mode in precision mode to avoid
101
+ // returning an exponential representation. A zero added by the
102
+ // EMIT_TRAILING_ZERO_AFTER_POINT flag is counted for this limit.
103
+ // Examples for max_trailing_padding_zeroes_in_precision_mode = 1:
104
+ // ToPrecision(230.0, 2) -> "230"
105
+ // ToPrecision(230.0, 2) -> "230." with EMIT_TRAILING_DECIMAL_POINT.
106
+ // ToPrecision(230.0, 2) -> "2.3e2" with EMIT_TRAILING_ZERO_AFTER_POINT.
107
+ DoubleToStringConverter(int flags,
108
+ const char* infinity_symbol,
109
+ const char* nan_symbol,
110
+ char exponent_character,
111
+ int decimal_in_shortest_low,
112
+ int decimal_in_shortest_high,
113
+ int max_leading_padding_zeroes_in_precision_mode,
114
+ int max_trailing_padding_zeroes_in_precision_mode)
115
+ : flags_(flags),
116
+ infinity_symbol_(infinity_symbol),
117
+ nan_symbol_(nan_symbol),
118
+ exponent_character_(exponent_character),
119
+ decimal_in_shortest_low_(decimal_in_shortest_low),
120
+ decimal_in_shortest_high_(decimal_in_shortest_high),
121
+ max_leading_padding_zeroes_in_precision_mode_(
122
+ max_leading_padding_zeroes_in_precision_mode),
123
+ max_trailing_padding_zeroes_in_precision_mode_(
124
+ max_trailing_padding_zeroes_in_precision_mode) {
125
+ // When 'trailing zero after the point' is set, then 'trailing point'
126
+ // must be set too.
127
+ ASSERT(((flags & EMIT_TRAILING_DECIMAL_POINT) != 0) ||
128
+ !((flags & EMIT_TRAILING_ZERO_AFTER_POINT) != 0));
129
+ }
130
+
131
+ // Returns a converter following the EcmaScript specification.
132
+ static const DoubleToStringConverter& EcmaScriptConverter();
133
+
134
+ // Computes the shortest string of digits that correctly represent the input
135
+ // number. Depending on decimal_in_shortest_low and decimal_in_shortest_high
136
+ // (see constructor) it then either returns a decimal representation, or an
137
+ // exponential representation.
138
+ // Example with decimal_in_shortest_low = -6,
139
+ // decimal_in_shortest_high = 21,
140
+ // EMIT_POSITIVE_EXPONENT_SIGN activated, and
141
+ // EMIT_TRAILING_DECIMAL_POINT deactived:
142
+ // ToShortest(0.000001) -> "0.000001"
143
+ // ToShortest(0.0000001) -> "1e-7"
144
+ // ToShortest(111111111111111111111.0) -> "111111111111111110000"
145
+ // ToShortest(100000000000000000000.0) -> "100000000000000000000"
146
+ // ToShortest(1111111111111111111111.0) -> "1.1111111111111111e+21"
147
+ //
148
+ // Note: the conversion may round the output if the returned string
149
+ // is accurate enough to uniquely identify the input-number.
150
+ // For example the most precise representation of the double 9e59 equals
151
+ // "899999999999999918767229449717619953810131273674690656206848", but
152
+ // the converter will return the shorter (but still correct) "9e59".
153
+ //
154
+ // Returns true if the conversion succeeds. The conversion always succeeds
155
+ // except when the input value is special and no infinity_symbol or
156
+ // nan_symbol has been given to the constructor.
157
+ bool ToShortest(double value, StringBuilder* result_builder) const {
158
+ return ToShortestIeeeNumber(value, result_builder, SHORTEST);
159
+ }
160
+
161
+ // Same as ToShortest, but for single-precision floats.
162
+ bool ToShortestSingle(float value, StringBuilder* result_builder) const {
163
+ return ToShortestIeeeNumber(value, result_builder, SHORTEST_SINGLE);
164
+ }
165
+
166
+
167
+ // Computes a decimal representation with a fixed number of digits after the
168
+ // decimal point. The last emitted digit is rounded.
169
+ //
170
+ // Examples:
171
+ // ToFixed(3.12, 1) -> "3.1"
172
+ // ToFixed(3.1415, 3) -> "3.142"
173
+ // ToFixed(1234.56789, 4) -> "1234.5679"
174
+ // ToFixed(1.23, 5) -> "1.23000"
175
+ // ToFixed(0.1, 4) -> "0.1000"
176
+ // ToFixed(1e30, 2) -> "1000000000000000019884624838656.00"
177
+ // ToFixed(0.1, 30) -> "0.100000000000000005551115123126"
178
+ // ToFixed(0.1, 17) -> "0.10000000000000001"
179
+ //
180
+ // If requested_digits equals 0, then the tail of the result depends on
181
+ // the EMIT_TRAILING_DECIMAL_POINT and EMIT_TRAILING_ZERO_AFTER_POINT.
182
+ // Examples, for requested_digits == 0,
183
+ // let EMIT_TRAILING_DECIMAL_POINT and EMIT_TRAILING_ZERO_AFTER_POINT be
184
+ // - false and false: then 123.45 -> 123
185
+ // 0.678 -> 1
186
+ // - true and false: then 123.45 -> 123.
187
+ // 0.678 -> 1.
188
+ // - true and true: then 123.45 -> 123.0
189
+ // 0.678 -> 1.0
190
+ //
191
+ // Returns true if the conversion succeeds. The conversion always succeeds
192
+ // except for the following cases:
193
+ // - the input value is special and no infinity_symbol or nan_symbol has
194
+ // been provided to the constructor,
195
+ // - 'value' > 10^kMaxFixedDigitsBeforePoint, or
196
+ // - 'requested_digits' > kMaxFixedDigitsAfterPoint.
197
+ // The last two conditions imply that the result will never contain more than
198
+ // 1 + kMaxFixedDigitsBeforePoint + 1 + kMaxFixedDigitsAfterPoint characters
199
+ // (one additional character for the sign, and one for the decimal point).
200
+ bool ToFixed(double value,
201
+ int requested_digits,
202
+ StringBuilder* result_builder) const;
203
+
204
+ // Computes a representation in exponential format with requested_digits
205
+ // after the decimal point. The last emitted digit is rounded.
206
+ // If requested_digits equals -1, then the shortest exponential representation
207
+ // is computed.
208
+ //
209
+ // Examples with EMIT_POSITIVE_EXPONENT_SIGN deactivated, and
210
+ // exponent_character set to 'e'.
211
+ // ToExponential(3.12, 1) -> "3.1e0"
212
+ // ToExponential(5.0, 3) -> "5.000e0"
213
+ // ToExponential(0.001, 2) -> "1.00e-3"
214
+ // ToExponential(3.1415, -1) -> "3.1415e0"
215
+ // ToExponential(3.1415, 4) -> "3.1415e0"
216
+ // ToExponential(3.1415, 3) -> "3.142e0"
217
+ // ToExponential(123456789000000, 3) -> "1.235e14"
218
+ // ToExponential(1000000000000000019884624838656.0, -1) -> "1e30"
219
+ // ToExponential(1000000000000000019884624838656.0, 32) ->
220
+ // "1.00000000000000001988462483865600e30"
221
+ // ToExponential(1234, 0) -> "1e3"
222
+ //
223
+ // Returns true if the conversion succeeds. The conversion always succeeds
224
+ // except for the following cases:
225
+ // - the input value is special and no infinity_symbol or nan_symbol has
226
+ // been provided to the constructor,
227
+ // - 'requested_digits' > kMaxExponentialDigits.
228
+ // The last condition implies that the result will never contain more than
229
+ // kMaxExponentialDigits + 8 characters (the sign, the digit before the
230
+ // decimal point, the decimal point, the exponent character, the
231
+ // exponent's sign, and at most 3 exponent digits).
232
+ bool ToExponential(double value,
233
+ int requested_digits,
234
+ StringBuilder* result_builder) const;
235
+
236
+ // Computes 'precision' leading digits of the given 'value' and returns them
237
+ // either in exponential or decimal format, depending on
238
+ // max_{leading|trailing}_padding_zeroes_in_precision_mode (given to the
239
+ // constructor).
240
+ // The last computed digit is rounded.
241
+ //
242
+ // Example with max_leading_padding_zeroes_in_precision_mode = 6.
243
+ // ToPrecision(0.0000012345, 2) -> "0.0000012"
244
+ // ToPrecision(0.00000012345, 2) -> "1.2e-7"
245
+ // Similarily the converter may add up to
246
+ // max_trailing_padding_zeroes_in_precision_mode in precision mode to avoid
247
+ // returning an exponential representation. A zero added by the
248
+ // EMIT_TRAILING_ZERO_AFTER_POINT flag is counted for this limit.
249
+ // Examples for max_trailing_padding_zeroes_in_precision_mode = 1:
250
+ // ToPrecision(230.0, 2) -> "230"
251
+ // ToPrecision(230.0, 2) -> "230." with EMIT_TRAILING_DECIMAL_POINT.
252
+ // ToPrecision(230.0, 2) -> "2.3e2" with EMIT_TRAILING_ZERO_AFTER_POINT.
253
+ // Examples for max_trailing_padding_zeroes_in_precision_mode = 3, and no
254
+ // EMIT_TRAILING_ZERO_AFTER_POINT:
255
+ // ToPrecision(123450.0, 6) -> "123450"
256
+ // ToPrecision(123450.0, 5) -> "123450"
257
+ // ToPrecision(123450.0, 4) -> "123500"
258
+ // ToPrecision(123450.0, 3) -> "123000"
259
+ // ToPrecision(123450.0, 2) -> "1.2e5"
260
+ //
261
+ // Returns true if the conversion succeeds. The conversion always succeeds
262
+ // except for the following cases:
263
+ // - the input value is special and no infinity_symbol or nan_symbol has
264
+ // been provided to the constructor,
265
+ // - precision < kMinPericisionDigits
266
+ // - precision > kMaxPrecisionDigits
267
+ // The last condition implies that the result will never contain more than
268
+ // kMaxPrecisionDigits + 7 characters (the sign, the decimal point, the
269
+ // exponent character, the exponent's sign, and at most 3 exponent digits).
270
+ bool ToPrecision(double value,
271
+ int precision,
272
+ StringBuilder* result_builder) const;
273
+
274
+ enum DtoaMode {
275
+ // Produce the shortest correct representation.
276
+ // For example the output of 0.299999999999999988897 is (the less accurate
277
+ // but correct) 0.3.
278
+ SHORTEST,
279
+ // Same as SHORTEST, but for single-precision floats.
280
+ SHORTEST_SINGLE,
281
+ // Produce a fixed number of digits after the decimal point.
282
+ // For instance fixed(0.1, 4) becomes 0.1000
283
+ // If the input number is big, the output will be big.
284
+ FIXED,
285
+ // Fixed number of digits (independent of the decimal point).
286
+ PRECISION
287
+ };
288
+
289
+ // The maximal number of digits that are needed to emit a double in base 10.
290
+ // A higher precision can be achieved by using more digits, but the shortest
291
+ // accurate representation of any double will never use more digits than
292
+ // kBase10MaximalLength.
293
+ // Note that DoubleToAscii null-terminates its input. So the given buffer
294
+ // should be at least kBase10MaximalLength + 1 characters long.
295
+ static const int kBase10MaximalLength = 17;
296
+
297
+ // Converts the given double 'v' to ascii. 'v' must not be NaN, +Infinity, or
298
+ // -Infinity. In SHORTEST_SINGLE-mode this restriction also applies to 'v'
299
+ // after it has been casted to a single-precision float. That is, in this
300
+ // mode static_cast<float>(v) must not be NaN, +Infinity or -Infinity.
301
+ //
302
+ // The result should be interpreted as buffer * 10^(point-length).
303
+ //
304
+ // The output depends on the given mode:
305
+ // - SHORTEST: produce the least amount of digits for which the internal
306
+ // identity requirement is still satisfied. If the digits are printed
307
+ // (together with the correct exponent) then reading this number will give
308
+ // 'v' again. The buffer will choose the representation that is closest to
309
+ // 'v'. If there are two at the same distance, than the one farther away
310
+ // from 0 is chosen (halfway cases - ending with 5 - are rounded up).
311
+ // In this mode the 'requested_digits' parameter is ignored.
312
+ // - SHORTEST_SINGLE: same as SHORTEST but with single-precision.
313
+ // - FIXED: produces digits necessary to print a given number with
314
+ // 'requested_digits' digits after the decimal point. The produced digits
315
+ // might be too short in which case the caller has to fill the remainder
316
+ // with '0's.
317
+ // Example: toFixed(0.001, 5) is allowed to return buffer="1", point=-2.
318
+ // Halfway cases are rounded towards +/-Infinity (away from 0). The call
319
+ // toFixed(0.15, 2) thus returns buffer="2", point=0.
320
+ // The returned buffer may contain digits that would be truncated from the
321
+ // shortest representation of the input.
322
+ // - PRECISION: produces 'requested_digits' where the first digit is not '0'.
323
+ // Even though the length of produced digits usually equals
324
+ // 'requested_digits', the function is allowed to return fewer digits, in
325
+ // which case the caller has to fill the missing digits with '0's.
326
+ // Halfway cases are again rounded away from 0.
327
+ // DoubleToAscii expects the given buffer to be big enough to hold all
328
+ // digits and a terminating null-character. In SHORTEST-mode it expects a
329
+ // buffer of at least kBase10MaximalLength + 1. In all other modes the
330
+ // requested_digits parameter and the padding-zeroes limit the size of the
331
+ // output. Don't forget the decimal point, the exponent character and the
332
+ // terminating null-character when computing the maximal output size.
333
+ // The given length is only used in debug mode to ensure the buffer is big
334
+ // enough.
335
+ static void DoubleToAscii(double v,
336
+ DtoaMode mode,
337
+ int requested_digits,
338
+ char* buffer,
339
+ int buffer_length,
340
+ bool* sign,
341
+ int* length,
342
+ int* point);
343
+
344
+ private:
345
+ // Implementation for ToShortest and ToShortestSingle.
346
+ bool ToShortestIeeeNumber(double value,
347
+ StringBuilder* result_builder,
348
+ DtoaMode mode) const;
349
+
350
+ // If the value is a special value (NaN or Infinity) constructs the
351
+ // corresponding string using the configured infinity/nan-symbol.
352
+ // If either of them is NULL or the value is not special then the
353
+ // function returns false.
354
+ bool HandleSpecialValues(double value, StringBuilder* result_builder) const;
355
+ // Constructs an exponential representation (i.e. 1.234e56).
356
+ // The given exponent assumes a decimal point after the first decimal digit.
357
+ void CreateExponentialRepresentation(const char* decimal_digits,
358
+ int length,
359
+ int exponent,
360
+ StringBuilder* result_builder) const;
361
+ // Creates a decimal representation (i.e 1234.5678).
362
+ void CreateDecimalRepresentation(const char* decimal_digits,
363
+ int length,
364
+ int decimal_point,
365
+ int digits_after_point,
366
+ StringBuilder* result_builder) const;
367
+
368
+ const int flags_;
369
+ const char* const infinity_symbol_;
370
+ const char* const nan_symbol_;
371
+ const char exponent_character_;
372
+ const int decimal_in_shortest_low_;
373
+ const int decimal_in_shortest_high_;
374
+ const int max_leading_padding_zeroes_in_precision_mode_;
375
+ const int max_trailing_padding_zeroes_in_precision_mode_;
376
+
377
+ DISALLOW_IMPLICIT_CONSTRUCTORS(DoubleToStringConverter);
378
+ };
379
+
380
+
381
+ class StringToDoubleConverter {
382
+ public:
383
+ // Enumeration for allowing octals and ignoring junk when converting
384
+ // strings to numbers.
385
+ enum Flags {
386
+ NO_FLAGS = 0,
387
+ ALLOW_HEX = 1,
388
+ ALLOW_OCTALS = 2,
389
+ ALLOW_TRAILING_JUNK = 4,
390
+ ALLOW_LEADING_SPACES = 8,
391
+ ALLOW_TRAILING_SPACES = 16,
392
+ ALLOW_SPACES_AFTER_SIGN = 32
393
+ };
394
+
395
+ // Flags should be a bit-or combination of the possible Flags-enum.
396
+ // - NO_FLAGS: no special flags.
397
+ // - ALLOW_HEX: recognizes the prefix "0x". Hex numbers may only be integers.
398
+ // Ex: StringToDouble("0x1234") -> 4660.0
399
+ // In StringToDouble("0x1234.56") the characters ".56" are trailing
400
+ // junk. The result of the call is hence dependent on
401
+ // the ALLOW_TRAILING_JUNK flag and/or the junk value.
402
+ // With this flag "0x" is a junk-string. Even with ALLOW_TRAILING_JUNK,
403
+ // the string will not be parsed as "0" followed by junk.
404
+ //
405
+ // - ALLOW_OCTALS: recognizes the prefix "0" for octals:
406
+ // If a sequence of octal digits starts with '0', then the number is
407
+ // read as octal integer. Octal numbers may only be integers.
408
+ // Ex: StringToDouble("01234") -> 668.0
409
+ // StringToDouble("012349") -> 12349.0 // Not a sequence of octal
410
+ // // digits.
411
+ // In StringToDouble("01234.56") the characters ".56" are trailing
412
+ // junk. The result of the call is hence dependent on
413
+ // the ALLOW_TRAILING_JUNK flag and/or the junk value.
414
+ // In StringToDouble("01234e56") the characters "e56" are trailing
415
+ // junk, too.
416
+ // - ALLOW_TRAILING_JUNK: ignore trailing characters that are not part of
417
+ // a double literal.
418
+ // - ALLOW_LEADING_SPACES: skip over leading whitespace, including spaces,
419
+ // new-lines, and tabs.
420
+ // - ALLOW_TRAILING_SPACES: ignore trailing whitespace.
421
+ // - ALLOW_SPACES_AFTER_SIGN: ignore whitespace after the sign.
422
+ // Ex: StringToDouble("- 123.2") -> -123.2.
423
+ // StringToDouble("+ 123.2") -> 123.2
424
+ //
425
+ // empty_string_value is returned when an empty string is given as input.
426
+ // If ALLOW_LEADING_SPACES or ALLOW_TRAILING_SPACES are set, then a string
427
+ // containing only spaces is converted to the 'empty_string_value', too.
428
+ //
429
+ // junk_string_value is returned when
430
+ // a) ALLOW_TRAILING_JUNK is not set, and a junk character (a character not
431
+ // part of a double-literal) is found.
432
+ // b) ALLOW_TRAILING_JUNK is set, but the string does not start with a
433
+ // double literal.
434
+ //
435
+ // infinity_symbol and nan_symbol are strings that are used to detect
436
+ // inputs that represent infinity and NaN. They can be null, in which case
437
+ // they are ignored.
438
+ // The conversion routine first reads any possible signs. Then it compares the
439
+ // following character of the input-string with the first character of
440
+ // the infinity, and nan-symbol. If either matches, the function assumes, that
441
+ // a match has been found, and expects the following input characters to match
442
+ // the remaining characters of the special-value symbol.
443
+ // This means that the following restrictions apply to special-value symbols:
444
+ // - they must not start with signs ('+', or '-'),
445
+ // - they must not have the same first character.
446
+ // - they must not start with digits.
447
+ //
448
+ // Examples:
449
+ // flags = ALLOW_HEX | ALLOW_TRAILING_JUNK,
450
+ // empty_string_value = 0.0,
451
+ // junk_string_value = NaN,
452
+ // infinity_symbol = "infinity",
453
+ // nan_symbol = "nan":
454
+ // StringToDouble("0x1234") -> 4660.0.
455
+ // StringToDouble("0x1234K") -> 4660.0.
456
+ // StringToDouble("") -> 0.0 // empty_string_value.
457
+ // StringToDouble(" ") -> NaN // junk_string_value.
458
+ // StringToDouble(" 1") -> NaN // junk_string_value.
459
+ // StringToDouble("0x") -> NaN // junk_string_value.
460
+ // StringToDouble("-123.45") -> -123.45.
461
+ // StringToDouble("--123.45") -> NaN // junk_string_value.
462
+ // StringToDouble("123e45") -> 123e45.
463
+ // StringToDouble("123E45") -> 123e45.
464
+ // StringToDouble("123e+45") -> 123e45.
465
+ // StringToDouble("123E-45") -> 123e-45.
466
+ // StringToDouble("123e") -> 123.0 // trailing junk ignored.
467
+ // StringToDouble("123e-") -> 123.0 // trailing junk ignored.
468
+ // StringToDouble("+NaN") -> NaN // NaN string literal.
469
+ // StringToDouble("-infinity") -> -inf. // infinity literal.
470
+ // StringToDouble("Infinity") -> NaN // junk_string_value.
471
+ //
472
+ // flags = ALLOW_OCTAL | ALLOW_LEADING_SPACES,
473
+ // empty_string_value = 0.0,
474
+ // junk_string_value = NaN,
475
+ // infinity_symbol = NULL,
476
+ // nan_symbol = NULL:
477
+ // StringToDouble("0x1234") -> NaN // junk_string_value.
478
+ // StringToDouble("01234") -> 668.0.
479
+ // StringToDouble("") -> 0.0 // empty_string_value.
480
+ // StringToDouble(" ") -> 0.0 // empty_string_value.
481
+ // StringToDouble(" 1") -> 1.0
482
+ // StringToDouble("0x") -> NaN // junk_string_value.
483
+ // StringToDouble("0123e45") -> NaN // junk_string_value.
484
+ // StringToDouble("01239E45") -> 1239e45.
485
+ // StringToDouble("-infinity") -> NaN // junk_string_value.
486
+ // StringToDouble("NaN") -> NaN // junk_string_value.
487
+ StringToDoubleConverter(int flags,
488
+ double empty_string_value,
489
+ double junk_string_value,
490
+ const char* infinity_symbol,
491
+ const char* nan_symbol)
492
+ : flags_(flags),
493
+ empty_string_value_(empty_string_value),
494
+ junk_string_value_(junk_string_value),
495
+ infinity_symbol_(infinity_symbol),
496
+ nan_symbol_(nan_symbol) {
497
+ }
498
+
499
+ // Performs the conversion.
500
+ // The output parameter 'processed_characters_count' is set to the number
501
+ // of characters that have been processed to read the number.
502
+ // Spaces than are processed with ALLOW_{LEADING|TRAILING}_SPACES are included
503
+ // in the 'processed_characters_count'. Trailing junk is never included.
504
+ double StringToDouble(const char* buffer,
505
+ int length,
506
+ int* processed_characters_count) const;
507
+
508
+ // Same as StringToDouble above but for 16 bit characters.
509
+ double StringToDouble(const uc16* buffer,
510
+ int length,
511
+ int* processed_characters_count) const;
512
+
513
+ // Same as StringToDouble but reads a float.
514
+ // Note that this is not equivalent to static_cast<float>(StringToDouble(...))
515
+ // due to potential double-rounding.
516
+ float StringToFloat(const char* buffer,
517
+ int length,
518
+ int* processed_characters_count) const;
519
+
520
+ // Same as StringToFloat above but for 16 bit characters.
521
+ float StringToFloat(const uc16* buffer,
522
+ int length,
523
+ int* processed_characters_count) const;
524
+
525
+ private:
526
+ const int flags_;
527
+ const double empty_string_value_;
528
+ const double junk_string_value_;
529
+ const char* const infinity_symbol_;
530
+ const char* const nan_symbol_;
531
+
532
+ template <class Iterator>
533
+ double StringToIeee(Iterator start_pointer,
534
+ int length,
535
+ bool read_as_double,
536
+ int* processed_characters_count) const;
537
+
538
+ DISALLOW_IMPLICIT_CONSTRUCTORS(StringToDoubleConverter);
539
+ };
540
+
541
+ } // namespace double_conversion
542
+
543
+ #endif // DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_