xref: /aosp_15_r20/external/icu/libicu/cts_headers/double-conversion-strtod.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2018 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker //
4*0e209d39SAndroid Build Coastguard Worker // From the double-conversion library. Original license:
5*0e209d39SAndroid Build Coastguard Worker //
6*0e209d39SAndroid Build Coastguard Worker // Copyright 2010 the V8 project authors. All rights reserved.
7*0e209d39SAndroid Build Coastguard Worker // Redistribution and use in source and binary forms, with or without
8*0e209d39SAndroid Build Coastguard Worker // modification, are permitted provided that the following conditions are
9*0e209d39SAndroid Build Coastguard Worker // met:
10*0e209d39SAndroid Build Coastguard Worker //
11*0e209d39SAndroid Build Coastguard Worker //     * Redistributions of source code must retain the above copyright
12*0e209d39SAndroid Build Coastguard Worker //       notice, this list of conditions and the following disclaimer.
13*0e209d39SAndroid Build Coastguard Worker //     * Redistributions in binary form must reproduce the above
14*0e209d39SAndroid Build Coastguard Worker //       copyright notice, this list of conditions and the following
15*0e209d39SAndroid Build Coastguard Worker //       disclaimer in the documentation and/or other materials provided
16*0e209d39SAndroid Build Coastguard Worker //       with the distribution.
17*0e209d39SAndroid Build Coastguard Worker //     * Neither the name of Google Inc. nor the names of its
18*0e209d39SAndroid Build Coastguard Worker //       contributors may be used to endorse or promote products derived
19*0e209d39SAndroid Build Coastguard Worker //       from this software without specific prior written permission.
20*0e209d39SAndroid Build Coastguard Worker //
21*0e209d39SAndroid Build Coastguard Worker // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22*0e209d39SAndroid Build Coastguard Worker // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23*0e209d39SAndroid Build Coastguard Worker // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24*0e209d39SAndroid Build Coastguard Worker // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25*0e209d39SAndroid Build Coastguard Worker // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26*0e209d39SAndroid Build Coastguard Worker // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27*0e209d39SAndroid Build Coastguard Worker // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28*0e209d39SAndroid Build Coastguard Worker // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29*0e209d39SAndroid Build Coastguard Worker // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30*0e209d39SAndroid Build Coastguard Worker // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31*0e209d39SAndroid Build Coastguard Worker // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*0e209d39SAndroid Build Coastguard Worker 
33*0e209d39SAndroid Build Coastguard Worker // ICU PATCH: ifdef around UCONFIG_NO_FORMATTING
34*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
35*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_FORMATTING
36*0e209d39SAndroid Build Coastguard Worker 
37*0e209d39SAndroid Build Coastguard Worker #ifndef DOUBLE_CONVERSION_STRTOD_H_
38*0e209d39SAndroid Build Coastguard Worker #define DOUBLE_CONVERSION_STRTOD_H_
39*0e209d39SAndroid Build Coastguard Worker 
40*0e209d39SAndroid Build Coastguard Worker // ICU PATCH: Customize header file paths for ICU.
41*0e209d39SAndroid Build Coastguard Worker 
42*0e209d39SAndroid Build Coastguard Worker #include "double-conversion-utils.h"
43*0e209d39SAndroid Build Coastguard Worker 
44*0e209d39SAndroid Build Coastguard Worker // ICU PATCH: Wrap in ICU namespace
45*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
46*0e209d39SAndroid Build Coastguard Worker 
47*0e209d39SAndroid Build Coastguard Worker namespace double_conversion {
48*0e209d39SAndroid Build Coastguard Worker 
49*0e209d39SAndroid Build Coastguard Worker // The buffer must only contain digits in the range [0-9]. It must not
50*0e209d39SAndroid Build Coastguard Worker // contain a dot or a sign. It must not start with '0', and must not be empty.
51*0e209d39SAndroid Build Coastguard Worker double Strtod(Vector<const char> buffer, int exponent);
52*0e209d39SAndroid Build Coastguard Worker 
53*0e209d39SAndroid Build Coastguard Worker // The buffer must only contain digits in the range [0-9]. It must not
54*0e209d39SAndroid Build Coastguard Worker // contain a dot or a sign. It must not start with '0', and must not be empty.
55*0e209d39SAndroid Build Coastguard Worker float Strtof(Vector<const char> buffer, int exponent);
56*0e209d39SAndroid Build Coastguard Worker 
57*0e209d39SAndroid Build Coastguard Worker // Same as Strtod, but assumes that 'trimmed' is already trimmed, as if run
58*0e209d39SAndroid Build Coastguard Worker // through TrimAndCut. That is, 'trimmed' must have no leading or trailing
59*0e209d39SAndroid Build Coastguard Worker // zeros, must not be a lone zero, and must not have 'too many' digits.
60*0e209d39SAndroid Build Coastguard Worker double StrtodTrimmed(Vector<const char> trimmed, int exponent);
61*0e209d39SAndroid Build Coastguard Worker 
62*0e209d39SAndroid Build Coastguard Worker // Same as Strtof, but assumes that 'trimmed' is already trimmed, as if run
63*0e209d39SAndroid Build Coastguard Worker // through TrimAndCut. That is, 'trimmed' must have no leading or trailing
64*0e209d39SAndroid Build Coastguard Worker // zeros, must not be a lone zero, and must not have 'too many' digits.
65*0e209d39SAndroid Build Coastguard Worker float StrtofTrimmed(Vector<const char> trimmed, int exponent);
66*0e209d39SAndroid Build Coastguard Worker 
TrimTrailingZeros(Vector<const char> buffer)67*0e209d39SAndroid Build Coastguard Worker inline Vector<const char> TrimTrailingZeros(Vector<const char> buffer) {
68*0e209d39SAndroid Build Coastguard Worker   for (int i = buffer.length() - 1; i >= 0; --i) {
69*0e209d39SAndroid Build Coastguard Worker     if (buffer[i] != '0') {
70*0e209d39SAndroid Build Coastguard Worker       return buffer.SubVector(0, i + 1);
71*0e209d39SAndroid Build Coastguard Worker     }
72*0e209d39SAndroid Build Coastguard Worker   }
73*0e209d39SAndroid Build Coastguard Worker   return Vector<const char>(buffer.start(), 0);
74*0e209d39SAndroid Build Coastguard Worker }
75*0e209d39SAndroid Build Coastguard Worker 
76*0e209d39SAndroid Build Coastguard Worker }  // namespace double_conversion
77*0e209d39SAndroid Build Coastguard Worker 
78*0e209d39SAndroid Build Coastguard Worker // ICU PATCH: Close ICU namespace
79*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
80*0e209d39SAndroid Build Coastguard Worker 
81*0e209d39SAndroid Build Coastguard Worker #endif  // DOUBLE_CONVERSION_STRTOD_H_
82*0e209d39SAndroid Build Coastguard Worker #endif // ICU PATCH: close #if !UCONFIG_NO_FORMATTING
83