summaryrefslogtreecommitdiff
path: root/absl/strings
diff options
context:
space:
mode:
Diffstat (limited to 'absl/strings')
-rw-r--r--absl/strings/BUILD.bazel1
-rw-r--r--absl/strings/escaping.cc7
-rw-r--r--absl/strings/escaping_test.cc2
-rw-r--r--absl/strings/internal/char_map_test.cc4
-rw-r--r--absl/strings/internal/memutil_test.cc1
-rw-r--r--absl/strings/internal/ostringstream_test.cc1
-rw-r--r--absl/strings/internal/utf8_test.cc5
-rw-r--r--absl/strings/match.cc6
-rw-r--r--absl/strings/match.h32
-rw-r--r--absl/strings/numbers.cc387
-rw-r--r--absl/strings/numbers.h3
-rw-r--r--absl/strings/numbers_test.cc41
-rw-r--r--absl/strings/str_cat.cc4
-rw-r--r--absl/strings/str_join_test.cc7
-rw-r--r--absl/strings/str_replace_test.cc3
-rw-r--r--absl/strings/str_split.cc3
-rw-r--r--absl/strings/str_split_test.cc7
-rw-r--r--absl/strings/string_view.cc1
-rw-r--r--absl/strings/string_view.h9
-rw-r--r--absl/strings/string_view_test.cc6
-rw-r--r--absl/strings/strip.cc1
-rw-r--r--absl/strings/substitute.h16
22 files changed, 61 insertions, 486 deletions
diff --git a/absl/strings/BUILD.bazel b/absl/strings/BUILD.bazel
index 070721cc..da441e20 100644
--- a/absl/strings/BUILD.bazel
+++ b/absl/strings/BUILD.bazel
@@ -162,6 +162,7 @@ cc_test(
deps = [
":strings",
":internal",
+ "//absl/base:core_headers",
] + select(GUNIT_MAIN_DEPS_SELECTOR),
)
diff --git a/absl/strings/escaping.cc b/absl/strings/escaping.cc
index f1576057..7d688ac3 100644
--- a/absl/strings/escaping.cc
+++ b/absl/strings/escaping.cc
@@ -14,22 +14,21 @@
#include "absl/strings/escaping.h"
+#include <algorithm>
#include <cassert>
#include <cstdint>
-#include <cstdio>
#include <cstring>
+#include <iterator>
#include <limits>
#include <string>
-#include <vector>
#include "absl/base/internal/endian.h"
#include "absl/base/internal/raw_logging.h"
#include "absl/base/internal/unaligned_access.h"
-#include "absl/base/macros.h"
-#include "absl/base/port.h"
#include "absl/strings/internal/char_map.h"
#include "absl/strings/internal/resize_uninitialized.h"
#include "absl/strings/internal/utf8.h"
+#include "absl/strings/str_cat.h"
#include "absl/strings/str_join.h"
#include "absl/strings/string_view.h"
diff --git a/absl/strings/escaping_test.cc b/absl/strings/escaping_test.cc
index d464051d..ecac9ca8 100644
--- a/absl/strings/escaping_test.cc
+++ b/absl/strings/escaping_test.cc
@@ -17,11 +17,11 @@
#include <array>
#include <cstdio>
#include <cstring>
+#include <memory>
#include <vector>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
-#include "absl/base/macros.h"
#include "absl/container/fixed_array.h"
#include "absl/strings/str_cat.h"
diff --git a/absl/strings/internal/char_map_test.cc b/absl/strings/internal/char_map_test.cc
index 2167be97..c3601e10 100644
--- a/absl/strings/internal/char_map_test.cc
+++ b/absl/strings/internal/char_map_test.cc
@@ -14,9 +14,9 @@
#include "absl/strings/internal/char_map.h"
-#include <cstdio>
-#include <cstdlib>
#include <cctype>
+#include <string>
+#include <vector>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
diff --git a/absl/strings/internal/memutil_test.cc b/absl/strings/internal/memutil_test.cc
index 1ff60f20..09424de9 100644
--- a/absl/strings/internal/memutil_test.cc
+++ b/absl/strings/internal/memutil_test.cc
@@ -16,7 +16,6 @@
#include "absl/strings/internal/memutil.h"
-#include <algorithm>
#include <cstdlib>
#include "gtest/gtest.h"
diff --git a/absl/strings/internal/ostringstream_test.cc b/absl/strings/internal/ostringstream_test.cc
index 0047ec82..069a0e1f 100644
--- a/absl/strings/internal/ostringstream_test.cc
+++ b/absl/strings/internal/ostringstream_test.cc
@@ -16,7 +16,6 @@
#include <memory>
#include <ostream>
-#include <sstream>
#include <string>
#include <type_traits>
diff --git a/absl/strings/internal/utf8_test.cc b/absl/strings/internal/utf8_test.cc
index 4d437427..64cec70d 100644
--- a/absl/strings/internal/utf8_test.cc
+++ b/absl/strings/internal/utf8_test.cc
@@ -14,12 +14,11 @@
#include "absl/strings/internal/utf8.h"
-#include <cctype>
-#include <cstdlib>
-#include <cstring>
#include <cstdint>
+#include <utility>
#include "gtest/gtest.h"
+#include "absl/base/port.h"
namespace {
diff --git a/absl/strings/match.cc b/absl/strings/match.cc
index 53881bdd..25bd7f0b 100644
--- a/absl/strings/match.cc
+++ b/absl/strings/match.cc
@@ -27,9 +27,9 @@ bool CaseEqual(absl::string_view piece1, absl::string_view piece2) {
}
} // namespace
-bool StartsWithIgnoreCase(absl::string_view text, absl::string_view preffix) {
- return (text.size() >= preffix.size()) &&
- CaseEqual(text.substr(0, preffix.size()), preffix);
+bool StartsWithIgnoreCase(absl::string_view text, absl::string_view prefix) {
+ return (text.size() >= prefix.size()) &&
+ CaseEqual(text.substr(0, prefix.size()), prefix);
}
bool EndsWithIgnoreCase(absl::string_view text, absl::string_view suffix) {
diff --git a/absl/strings/match.h b/absl/strings/match.h
index 4a5d1c03..4ac35f19 100644
--- a/absl/strings/match.h
+++ b/absl/strings/match.h
@@ -41,40 +41,42 @@ namespace absl {
// StrContains()
//
-// Returns whether a given std::string `s` contains the substring `x`.
-inline bool StrContains(absl::string_view s, absl::string_view x) {
- return static_cast<absl::string_view::size_type>(s.find(x, 0)) != s.npos;
+// Returns whether a given std::string `haystack` contains the substring `needle`.
+inline bool StrContains(absl::string_view haystack, absl::string_view needle) {
+ return static_cast<absl::string_view::size_type>(haystack.find(needle, 0)) !=
+ haystack.npos;
}
// StartsWith()
//
-// Returns whether a given std::string `s` begins with `x`.
-inline bool StartsWith(absl::string_view s, absl::string_view x) {
- return x.empty() ||
- (s.size() >= x.size() && memcmp(s.data(), x.data(), x.size()) == 0);
+// Returns whether a given std::string `text` begins with `prefix`.
+inline bool StartsWith(absl::string_view text, absl::string_view prefix) {
+ return prefix.empty() ||
+ (text.size() >= prefix.size() &&
+ memcmp(text.data(), prefix.data(), prefix.size()) == 0);
}
// EndsWith()
//
-// Returns whether a given std::string `s` ends `x`.
-inline bool EndsWith(absl::string_view s, absl::string_view x) {
- return x.empty() ||
- (s.size() >= x.size() &&
- memcmp(s.data() + (s.size() - x.size()), x.data(), x.size()) == 0);
+// Returns whether a given std::string `text` ends with `suffix`.
+inline bool EndsWith(absl::string_view text, absl::string_view suffix) {
+ return suffix.empty() ||
+ (text.size() >= suffix.size() &&
+ memcmp(text.data() + (text.size() - suffix.size()), suffix.data(),
+ suffix.size()) == 0);
}
// StartsWithIgnoreCase()
//
// Returns whether a given std::string `text` starts with `starts_with`, ignoring
// case in the comparison.
-bool StartsWithIgnoreCase(absl::string_view text,
- absl::string_view starts_with);
+bool StartsWithIgnoreCase(absl::string_view text, absl::string_view prefix);
// EndsWithIgnoreCase()
//
// Returns whether a given std::string `text` ends with `ends_with`, ignoring case
// in the comparison.
-bool EndsWithIgnoreCase(absl::string_view text, absl::string_view ends_with);
+bool EndsWithIgnoreCase(absl::string_view text, absl::string_view suffix);
} // namespace absl
diff --git a/absl/strings/numbers.cc b/absl/strings/numbers.cc
index 3b093b98..ac73f530 100644
--- a/absl/strings/numbers.cc
+++ b/absl/strings/numbers.cc
@@ -3,19 +3,20 @@
#include "absl/strings/numbers.h"
+#include <algorithm>
#include <cassert>
-#include <cctype>
#include <cfloat> // for DBL_DIG and FLT_DIG
#include <cmath> // for HUGE_VAL
+#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
+#include <iterator>
#include <limits>
#include <memory>
-#include <string>
+#include <utility>
#include "absl/base/internal/raw_logging.h"
-#include "absl/numeric/int128.h"
#include "absl/strings/ascii.h"
#include "absl/strings/internal/memutil.h"
#include "absl/strings/str_cat.h"
@@ -291,386 +292,6 @@ char* numbers_internal::FastInt64ToBuffer(int64_t i, char* buffer) {
return numbers_internal::FastUInt64ToBuffer(u, buffer);
}
-// Although DBL_DIG is typically 15, DBL_MAX is normally represented with 17
-// digits of precision. When converted to a std::string value with fewer digits
-// of precision using strtod(), the result can be bigger than DBL_MAX due to
-// a rounding error. Converting this value back to a double will produce an
-// Inf which will trigger a SIGFPE if FP exceptions are enabled. We skip
-// the precision check for sufficiently large values to avoid the SIGFPE.
-static const double kDoublePrecisionCheckMax = DBL_MAX / 1.000000000000001;
-
-char* numbers_internal::RoundTripDoubleToBuffer(double d, char* buffer) {
- // DBL_DIG is 15 for IEEE-754 doubles, which are used on almost all
- // platforms these days. Just in case some system exists where DBL_DIG
- // is significantly larger -- and risks overflowing our buffer -- we have
- // this assert.
- static_assert(DBL_DIG < 20, "DBL_DIG is too big");
-
- bool full_precision_needed = true;
- if (std::abs(d) <= kDoublePrecisionCheckMax) {
- int snprintf_result = snprintf(buffer, numbers_internal::kFastToBufferSize,
- "%.*g", DBL_DIG, d);
-
- // The snprintf should never overflow because the buffer is significantly
- // larger than the precision we asked for.
- assert(snprintf_result > 0 &&
- snprintf_result < numbers_internal::kFastToBufferSize);
- (void)snprintf_result;
-
- full_precision_needed = strtod(buffer, nullptr) != d;
- }
-
- if (full_precision_needed) {
- int snprintf_result = snprintf(buffer, numbers_internal::kFastToBufferSize,
- "%.*g", DBL_DIG + 2, d);
-
- // Should never overflow; see above.
- assert(snprintf_result > 0 &&
- snprintf_result < numbers_internal::kFastToBufferSize);
- (void)snprintf_result;
- }
- return buffer;
-}
-// This table is used to quickly calculate the base-ten exponent of a given
-// float, and then to provide a multiplier to bring that number into the
-// range 1-999,999,999, that is, into uint32_t range. Finally, the exp
-// std::string is made available so there is one less int-to-std::string conversion
-// to be done.
-
-struct Spec {
- double min_range;
- double multiplier;
- const char expstr[5];
-};
-const Spec neg_exp_table[] = {
- {1.4e-45f, 1e+55, "e-45"}, //
- {1e-44f, 1e+54, "e-44"}, //
- {1e-43f, 1e+53, "e-43"}, //
- {1e-42f, 1e+52, "e-42"}, //
- {1e-41f, 1e+51, "e-41"}, //
- {1e-40f, 1e+50, "e-40"}, //
- {1e-39f, 1e+49, "e-39"}, //
- {1e-38f, 1e+48, "e-38"}, //
- {1e-37f, 1e+47, "e-37"}, //
- {1e-36f, 1e+46, "e-36"}, //
- {1e-35f, 1e+45, "e-35"}, //
- {1e-34f, 1e+44, "e-34"}, //
- {1e-33f, 1e+43, "e-33"}, //
- {1e-32f, 1e+42, "e-32"}, //
- {1e-31f, 1e+41, "e-31"}, //
- {1e-30f, 1e+40, "e-30"}, //
- {1e-29f, 1e+39, "e-29"}, //
- {1e-28f, 1e+38, "e-28"}, //
- {1e-27f, 1e+37, "e-27"}, //
- {1e-26f, 1e+36, "e-26"}, //
- {1e-25f, 1e+35, "e-25"}, //
- {1e-24f, 1e+34, "e-24"}, //
- {1e-23f, 1e+33, "e-23"}, //
- {1e-22f, 1e+32, "e-22"}, //
- {1e-21f, 1e+31, "e-21"}, //
- {1e-20f, 1e+30, "e-20"}, //
- {1e-19f, 1e+29, "e-19"}, //
- {1e-18f, 1e+28, "e-18"}, //
- {1e-17f, 1e+27, "e-17"}, //
- {1e-16f, 1e+26, "e-16"}, //
- {1e-15f, 1e+25, "e-15"}, //
- {1e-14f, 1e+24, "e-14"}, //
- {1e-13f, 1e+23, "e-13"}, //
- {1e-12f, 1e+22, "e-12"}, //
- {1e-11f, 1e+21, "e-11"}, //
- {1e-10f, 1e+20, "e-10"}, //
- {1e-09f, 1e+19, "e-09"}, //
- {1e-08f, 1e+18, "e-08"}, //
- {1e-07f, 1e+17, "e-07"}, //
- {1e-06f, 1e+16, "e-06"}, //
- {1e-05f, 1e+15, "e-05"}, //
- {1e-04f, 1e+14, "e-04"}, //
-};
-
-const Spec pos_exp_table[] = {
- {1e+08f, 1e+02, "e+08"}, //
- {1e+09f, 1e+01, "e+09"}, //
- {1e+10f, 1e+00, "e+10"}, //
- {1e+11f, 1e-01, "e+11"}, //
- {1e+12f, 1e-02, "e+12"}, //
- {1e+13f, 1e-03, "e+13"}, //
- {1e+14f, 1e-04, "e+14"}, //
- {1e+15f, 1e-05, "e+15"}, //
- {1e+16f, 1e-06, "e+16"}, //
- {1e+17f, 1e-07, "e+17"}, //
- {1e+18f, 1e-08, "e+18"}, //
- {1e+19f, 1e-09, "e+19"}, //
- {1e+20f, 1e-10, "e+20"}, //
- {1e+21f, 1e-11, "e+21"}, //
- {1e+22f, 1e-12, "e+22"}, //
- {1e+23f, 1e-13, "e+23"}, //
- {1e+24f, 1e-14, "e+24"}, //
- {1e+25f, 1e-15, "e+25"}, //
- {1e+26f, 1e-16, "e+26"}, //
- {1e+27f, 1e-17, "e+27"}, //
- {1e+28f, 1e-18, "e+28"}, //
- {1e+29f, 1e-19, "e+29"}, //
- {1e+30f, 1e-20, "e+30"}, //
- {1e+31f, 1e-21, "e+31"}, //
- {1e+32f, 1e-22, "e+32"}, //
- {1e+33f, 1e-23, "e+33"}, //
- {1e+34f, 1e-24, "e+34"}, //
- {1e+35f, 1e-25, "e+35"}, //
- {1e+36f, 1e-26, "e+36"}, //
- {1e+37f, 1e-27, "e+37"}, //
- {1e+38f, 1e-28, "e+38"}, //
- {1e+39, 1e-29, "e+39"}, //
-};
-
-struct ExpCompare {
- bool operator()(const Spec& spec, double d) const {
- return spec.min_range < d;
- }
-};
-
-// Utility routine(s) for RoundTripFloatToBuffer:
-// OutputNecessaryDigits takes two 11-digit numbers, whose integer portion
-// represents the fractional part of a floating-point number, and outputs a
-// number that is in-between them, with the fewest digits possible. For
-// instance, given 12345678900 and 12345876900, it would output "0123457".
-// When there are multiple final digits that would satisfy this requirement,
-// this routine attempts to use a digit that would represent the average of
-// lower_double and upper_double.
-//
-// Although the routine works using integers, all callers use doubles, so
-// for their convenience this routine accepts doubles.
-static char* OutputNecessaryDigits(double lower_double, double upper_double,
- char* out) {
- assert(lower_double > 0);
- assert(lower_double < upper_double - 10);
- assert(upper_double < 100000000000.0);
-
- // Narrow the range a bit; without this bias, an input of lower=87654320010.0
- // and upper=87654320100.0 would produce an output of 876543201
- //
- // We do this in three steps: first, we lower the upper bound and truncate it
- // to an integer. Then, we increase the lower bound by exactly the amount we
- // just decreased the upper bound by - at that point, the midpoint is exactly
- // where it used to be. Then we truncate the lower bound.
-
- uint64_t upper64 = upper_double - (1.0 / 1024);
- double shrink = upper_double - upper64;
- uint64_t lower64 = lower_double + shrink;
-
- // Theory of operation: we convert the lower number to ascii representation,
- // two digits at a time. As we go, we remove the same digits from the upper
- // number. When we see the upper number does not share those same digits, we
- // know we can stop converting. When we stop, the last digit we output is
- // taken from the average of upper and lower values, rounded up.
- char buf[2];
- uint32_t lodigits =
- static_cast<uint32_t>(lower64 / 1000000000); // 1,000,000,000
- uint64_t mul64 = lodigits * uint64_t{1000000000};
-
- PutTwoDigits(lodigits, out);
- out += 2;
- if (upper64 - mul64 >= 1000000000) { // digit mismatch!
- PutTwoDigits(upper64 / 1000000000, buf);
- if (out[-2] != buf[0]) {
- out[-2] = '0' + (upper64 + lower64 + 10000000000) / 20000000000;
- --out;
- } else {
- PutTwoDigits((upper64 + lower64 + 1000000000) / 2000000000, out - 2);
- }
- *out = '\0';
- return out;
- }
- uint32_t lower = static_cast<uint32_t>(lower64 - mul64);
- uint32_t upper = static_cast<uint32_t>(upper64 - mul64);
-
- lodigits = lower / 10000000; // 10,000,000
- uint32_t mul = lodigits * 10000000;
- PutTwoDigits(lodigits, out);
- out += 2;
- if (upper - mul >= 10000000) { // digit mismatch!
- PutTwoDigits(upper / 10000000, buf);
- if (out[-2] != buf[0]) {
- out[-2] = '0' + (upper + lower + 100000000) / 200000000;
- --out;
- } else {
- PutTwoDigits((upper + lower + 10000000) / 20000000, out - 2);
- }
- *out = '\0';
- return out;
- }
- lower -= mul;
- upper -= mul;
-
- lodigits = lower / 100000; // 100,000
- mul = lodigits * 100000;
- PutTwoDigits(lodigits, out);
- out += 2;
- if (upper - mul >= 100000) { // digit mismatch!
- PutTwoDigits(upper / 100000, buf);
- if (out[-2] != buf[0]) {
- out[-2] = '0' + (upper + lower + 1000000) / 2000000;
- --out;
- } else {
- PutTwoDigits((upper + lower + 100000) / 200000, out - 2);
- }
- *out = '\0';
- return out;
- }
- lower -= mul;
- upper -= mul;
-
- lodigits = lower / 1000;
- mul = lodigits * 1000;
- PutTwoDigits(lodigits, out);
- out += 2;
- if (upper - mul >= 1000) { // digit mismatch!
- PutTwoDigits(upper / 1000, buf);
- if (out[-2] != buf[0]) {
- out[-2] = '0' + (upper + lower + 10000) / 20000;
- --out;
- } else {
- PutTwoDigits((upper + lower + 1000) / 2000, out - 2);
- }
- *out = '\0';
- return out;
- }
- lower -= mul;
- upper -= mul;
-
- PutTwoDigits(lower / 10, out);
- out += 2;
- PutTwoDigits(upper / 10, buf);
- if (out[-2] != buf[0]) {
- out[-2] = '0' + (upper + lower + 100) / 200;
- --out;
- } else {
- PutTwoDigits((upper + lower + 10) / 20, out - 2);
- }
- *out = '\0';
- return out;
-}
-
-// RoundTripFloatToBuffer converts the given float into a std::string which, if
-// passed to strtof, will produce the exact same original float. It does this
-// by computing the range of possible doubles which map to the given float, and
-// then examining the digits of the doubles in that range. If all the doubles
-// in the range start with "2.37", then clearly our float does, too. As soon as
-// they diverge, only one more digit is needed.
-char* numbers_internal::RoundTripFloatToBuffer(float f, char* buffer) {
- static_assert(std::numeric_limits<float>::is_iec559,
- "IEEE-754/IEC-559 support only");
-
- char* out = buffer; // we write data to out, incrementing as we go, but
- // FloatToBuffer always returns the address of the buffer
- // passed in.
-
- if (std::isnan(f)) {
- strcpy(out, "nan"); // NOLINT(runtime/printf)
- return buffer;
- }
- if (f == 0) { // +0 and -0 are handled here
- if (std::signbit(f)) {
- strcpy(out, "-0"); // NOLINT(runtime/printf)
- } else {
- strcpy(out, "0"); // NOLINT(runtime/printf)
- }
- return buffer;
- }
- if (f < 0) {
- *out++ = '-';
- f = -f;
- }
- if (std::isinf(f)) {
- strcpy(out, "inf"); // NOLINT(runtime/printf)
- return buffer;
- }
-
- double next_lower = nextafterf(f, 0.0f);
- // For all doubles in the range lower_bound < f < upper_bound, the
- // nearest float is f.
- double lower_bound = (f + next_lower) * 0.5;
- double upper_bound = f + (f - lower_bound);
- // Note: because std::nextafter is slow, we calculate upper_bound
- // assuming that it is the same distance from f as lower_bound is.
- // For exact powers of two, upper_bound is actually twice as far
- // from f as lower_bound is, but this turns out not to matter.
-
- // Most callers pass floats that are either 0 or within the
- // range 0.0001 through 100,000,000, so handle those first,
- // since they don't need exponential notation.
- const Spec* spec = nullptr;
- if (f < 1.0) {
- if (f >= 0.0001f) {
- // for fractional values, we set up the multiplier at the same
- // time as we output the leading "0." / "0.0" / "0.00" / "0.000"
- double multiplier = 1e+11;
- *out++ = '0';
- *out++ = '.';
- if (f < 0.1f) {
- multiplier = 1e+12;
- *out++ = '0';
- if (f < 0.01f) {
- multiplier = 1e+13;
- *out++ = '0';
- if (f < 0.001f) {
- multiplier = 1e+14;
- *out++ = '0';
- }
- }
- }
- OutputNecessaryDigits(lower_bound * multiplier, upper_bound * multiplier,
- out);
- return buffer;
- }
- spec = std::lower_bound(std::begin(neg_exp_table), std::end(neg_exp_table),
- double{f}, ExpCompare());
- if (spec == std::end(neg_exp_table)) --spec;
- } else if (f < 1e8) {
- // Handling non-exponential format greater than 1.0 is similar to the above,
- // but instead of 0.0 / 0.00 / 0.000, the prefix is simply the truncated
- // integer part of f.
- int32_t as_int = f;
- out = numbers_internal::FastUInt32ToBuffer(as_int, out);
- // Easy: if the integer part is within (lower_bound, upper_bound), then we
- // are already done.
- if (as_int > lower_bound && as_int < upper_bound) {
- return buffer;
- }
- *out++ = '.';
- OutputNecessaryDigits((lower_bound - as_int) * 1e11,
- (upper_bound - as_int) * 1e11, out);
- return buffer;
- } else {
- spec = std::lower_bound(std::begin(pos_exp_table),
- std::end(pos_exp_table),
- double{f}, ExpCompare());
- if (spec == std::end(pos_exp_table)) --spec;
- }
- // Exponential notation from here on. "spec" was computed using lower_bound,
- // which means it's the first spec from the table where min_range is greater
- // or equal to f.
- // Unfortunately that's not quite what we want; we want a min_range that is
- // less or equal. So first thing, if it was greater, back up one entry.
- if (spec->min_range > f) --spec;
-
- // The digits might be "237000123", but we want "2.37000123",
- // so we output the digits one character later, and then move the first
- // digit back so we can stick the "." in.
- char* start = out;
- out = OutputNecessaryDigits(lower_bound * spec->multiplier,
- upper_bound * spec->multiplier, start + 1);
- start[0] = start[1];
- start[1] = '.';
-
- // If it turns out there was only one digit output, then back up over the '.'
- if (out == &start[2]) --out;
-
- // Now add the "e+NN" part.
- memcpy(out, spec->expstr, 4);
- out[4] = '\0';
- return buffer;
-}
-
// Returns the number of leading 0 bits in a 64-bit value.
// TODO(jorg): Replace with builtin_clzll if available.
// Are we shipping util/bits in absl?
diff --git a/absl/strings/numbers.h b/absl/strings/numbers.h
index f17dc97b..74aebc80 100644
--- a/absl/strings/numbers.h
+++ b/absl/strings/numbers.h
@@ -92,9 +92,6 @@ char* FastUInt64ToBuffer(uint64_t i, char* buffer);
static const int kFastToBufferSize = 32;
static const int kSixDigitsToBufferSize = 16;
-char* RoundTripDoubleToBuffer(double d, char* buffer);
-char* RoundTripFloatToBuffer(float f, char* buffer);
-
// Helper function for fast formatting of floating-point values.
// The result is the same as printf's "%g", a.k.a. "%.6g"; that is, six
// significant digits are returned, trailing zeros are removed, and numbers
diff --git a/absl/strings/numbers_test.cc b/absl/strings/numbers_test.cc
index 9b74d67b..817604d7 100644
--- a/absl/strings/numbers_test.cc
+++ b/absl/strings/numbers_test.cc
@@ -3,10 +3,7 @@
#include "absl/strings/numbers.h"
#include <sys/types.h>
-#include <algorithm>
-#include <cctype>
#include <cfenv> // NOLINT(build/c++11)
-#include <cfloat>
#include <cinttypes>
#include <climits>
#include <cmath>
@@ -25,7 +22,6 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/base/internal/raw_logging.h"
-#include "absl/base/port.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/internal/numbers_test_common.inc"
@@ -42,7 +38,6 @@ using absl::numbers_internal::safe_strto32_base;
using absl::numbers_internal::safe_strto64_base;
using absl::numbers_internal::safe_strtou32_base;
using absl::numbers_internal::safe_strtou64_base;
-using absl::numbers_internal::RoundTripFloatToBuffer;
using absl::numbers_internal::SixDigitsToBuffer;
using absl::SimpleAtoi;
using testing::Eq;
@@ -776,42 +771,6 @@ void ExhaustiveFloat(uint32_t cases, R&& runnable) {
}
}
-TEST_F(SimpleDtoaTest, ExhaustiveFloatToBuffer) {
- uint64_t test_count = 0;
- std::vector<float> mismatches;
- ExhaustiveFloat(kFloatNumCases, [&](float f) {
- if (f != f) return; // rule out NaNs
- ++test_count;
- char fastbuf[kFastToBufferSize];
- RoundTripFloatToBuffer(f, fastbuf);
- float round_trip = strtof(fastbuf, nullptr);
- if (f != round_trip) {
- mismatches.push_back(f);
- if (mismatches.size() < 10) {
- ABSL_RAW_LOG(ERROR, "%s",
- absl::StrCat("Round-trip failure with float. ", "f=", f,
- "=", ToNineDigits(f), " fast=", fastbuf,
- " strtof=", ToNineDigits(round_trip))
- .c_str());
- }
- }
- });
- if (!mismatches.empty()) {
- EXPECT_EQ(mismatches.size(), 0);
- for (size_t i = 0; i < mismatches.size(); ++i) {
- if (i > 100) i = mismatches.size() - 1;
- float f = mismatches[i];
- std::string msg =
- absl::StrCat("Mismatch #", i, " f=", f, " (", ToNineDigits(f), ")");
- char buf[kFastToBufferSize];
- absl::StrAppend(&msg, " fast='", RoundTripFloatToBuffer(f, buf), "'");
- float rt = strtof(buf, nullptr);
- absl::StrAppend(&msg, " rt=", ToNineDigits(rt));
- ABSL_RAW_LOG(ERROR, "%s", msg.c_str());
- }
- }
-}
-
TEST_F(SimpleDtoaTest, ExhaustiveDoubleToSixDigits) {
uint64_t test_count = 0;
std::vector<double> mismatches;
diff --git a/absl/strings/str_cat.cc b/absl/strings/str_cat.cc
index 0c75655c..99eb2890 100644
--- a/absl/strings/str_cat.cc
+++ b/absl/strings/str_cat.cc
@@ -14,9 +14,9 @@
#include "absl/strings/str_cat.h"
-#include <cstdarg>
+#include <assert.h>
+#include <algorithm>
#include <cstdint>
-#include <cstdio>
#include <cstring>
#include "absl/strings/ascii.h"
diff --git a/absl/strings/str_join_test.cc b/absl/strings/str_join_test.cc
index 7c2ed09b..03b60f03 100644
--- a/absl/strings/str_join_test.cc
+++ b/absl/strings/str_join_test.cc
@@ -16,22 +16,21 @@
#include "absl/strings/str_join.h"
-#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstdio>
+#include <functional>
#include <initializer_list>
#include <map>
+#include <memory>
#include <ostream>
-#include <random>
#include <set>
#include <tuple>
+#include <type_traits>
#include <vector>
-#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/base/macros.h"
-#include "absl/base/port.h"
#include "absl/memory/memory.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
diff --git a/absl/strings/str_replace_test.cc b/absl/strings/str_replace_test.cc
index f49c7e1c..5d003a22 100644
--- a/absl/strings/str_replace_test.cc
+++ b/absl/strings/str_replace_test.cc
@@ -15,11 +15,12 @@
#include "absl/strings/str_replace.h"
#include <list>
+#include <map>
#include <tuple>
#include "gtest/gtest.h"
-#include "absl/strings/str_split.h"
#include "absl/strings/str_cat.h"
+#include "absl/strings/str_split.h"
TEST(StrReplaceAll, OneReplacement) {
std::string s;
diff --git a/absl/strings/str_split.cc b/absl/strings/str_split.cc
index 910a67cf..0207213c 100644
--- a/absl/strings/str_split.cc
+++ b/absl/strings/str_split.cc
@@ -14,11 +14,14 @@
#include "absl/strings/str_split.h"
+#include <algorithm>
#include <cassert>
+#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <iterator>
#include <limits>
+#include <memory>
#include "absl/base/internal/raw_logging.h"
#include "absl/strings/ascii.h"
diff --git a/absl/strings/str_split_test.cc b/absl/strings/str_split_test.cc
index a95a0fbd..22a68d0f 100644
--- a/absl/strings/str_split_test.cc
+++ b/absl/strings/str_split_test.cc
@@ -14,15 +14,13 @@
#include "absl/strings/str_split.h"
-#include <climits>
-#include <cstdlib>
-#include <cstring>
#include <deque>
-#include <limits>
+#include <initializer_list>
#include <list>
#include <map>
#include <memory>
#include <string>
+#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>
@@ -31,7 +29,6 @@
#include "gtest/gtest.h"
#include "absl/base/dynamic_annotations.h" // for RunningOnValgrind
#include "absl/base/macros.h"
-#include "absl/base/port.h"
#include "absl/strings/numbers.h"
namespace {
diff --git a/absl/strings/string_view.cc b/absl/strings/string_view.cc
index 4d4ba6c1..0e172954 100644
--- a/absl/strings/string_view.cc
+++ b/absl/strings/string_view.cc
@@ -20,7 +20,6 @@
#include <climits>
#include <cstring>
#include <ostream>
-#include <string>
#include "absl/strings/internal/memutil.h"
#include "absl/strings/internal/resize_uninitialized.h"
diff --git a/absl/strings/string_view.h b/absl/strings/string_view.h
index e2609f17..8e37acb8 100644
--- a/absl/strings/string_view.h
+++ b/absl/strings/string_view.h
@@ -180,9 +180,9 @@ class string_view {
constexpr string_view(const char* data, size_type len)
: ptr_(data), length_(CheckLengthInternal(len)) {}
- // NOTE(b/36227513): harmlessly omitted to work around gdb bug.
- // constexpr string_view(const string_view&) noexcept = default;
- // string_view& operator=(const string_view&) noexcept = default;
+ // NOTE: Harmlessly omitted to work around gdb bug.
+ // constexpr string_view(const string_view&) noexcept = default;
+ // string_view& operator=(const string_view&) noexcept = default;
// Iterators
@@ -550,8 +550,7 @@ namespace absl {
// ClippedSubstr()
//
// Like `s.substr(pos, n)`, but clips `pos` to an upper bound of `s.size()`.
-// Provided because std::string_view::substr throws if `pos > size()`,
-// to support b/37991613.
+// Provided because std::string_view::substr throws if `pos > size()`
inline string_view ClippedSubstr(string_view s, size_t pos,
size_t n = string_view::npos) {
pos = std::min(pos, static_cast<size_t>(s.size()));
diff --git a/absl/strings/string_view_test.cc b/absl/strings/string_view_test.cc
index 439d6499..6be6f3b8 100644
--- a/absl/strings/string_view_test.cc
+++ b/absl/strings/string_view_test.cc
@@ -14,12 +14,13 @@
#include "absl/strings/string_view.h"
-#include <algorithm>
+#include <stdlib.h>
#include <iomanip>
#include <iterator>
+#include <limits>
#include <map>
-#include <random>
#include <sstream>
+#include <stdexcept>
#include <string>
#include <type_traits>
#include <utility>
@@ -27,7 +28,6 @@
#include "gtest/gtest.h"
#include "absl/base/config.h"
#include "absl/base/dynamic_annotations.h"
-#include "absl/base/port.h"
namespace {
diff --git a/absl/strings/strip.cc b/absl/strings/strip.cc
index 968c09c6..adc219f1 100644
--- a/absl/strings/strip.cc
+++ b/absl/strings/strip.cc
@@ -18,7 +18,6 @@
#include "absl/strings/strip.h"
#include <algorithm>
-#include <cassert>
#include <cstring>
#include <string>
diff --git a/absl/strings/substitute.h b/absl/strings/substitute.h
index 5d6bfd90..3fc4ac4c 100644
--- a/absl/strings/substitute.h
+++ b/absl/strings/substitute.h
@@ -73,7 +73,7 @@
// * calls for a position argument which is not provided,
// e.g. Substitute("Hello $2", "world"), or
// * specifies a non-digit, non-$ character after an unescaped $ character,
-// e.g. "Hello %f".
+// e.g. "Hello $f".
// In debug mode, i.e. #ifndef NDEBUG, such errors terminate the program.
#ifndef ABSL_STRINGS_SUBSTITUTE_H_
@@ -149,9 +149,11 @@ class Arg {
: piece_(scratch_,
numbers_internal::FastIntToBuffer(value, scratch_) - scratch_) {}
Arg(float value) // NOLINT(runtime/explicit)
- : piece_(numbers_internal::RoundTripFloatToBuffer(value, scratch_)) {}
+ : piece_(scratch_, numbers_internal::SixDigitsToBuffer(value, scratch_)) {
+ }
Arg(double value) // NOLINT(runtime/explicit)
- : piece_(numbers_internal::RoundTripDoubleToBuffer(value, scratch_)) {}
+ : piece_(scratch_, numbers_internal::SixDigitsToBuffer(value, scratch_)) {
+ }
Arg(bool value) // NOLINT(runtime/explicit)
: piece_(value ? "true" : "false") {}
// `void*` values, with the exception of `char*`, are printed as
@@ -211,9 +213,9 @@ constexpr int PlaceholderBitmask(const char* format) {
//
// Example:
// template <typename... Args>
-// void VarMsg(std::string* boilerplate, const std::string& format,
+// void VarMsg(std::string* boilerplate, absl::string_view format,
// const Args&... args) {
-// std::string s = absl::SubstituteAndAppend(boilerplate, format, args...)";
+// absl::SubstituteAndAppend(boilerplate, format, args...);
// }
//
inline void SubstituteAndAppend(std::string* output, absl::string_view format) {
@@ -458,8 +460,8 @@ void SubstituteAndAppend(
//
// Example:
// template <typename... Args>
-// void VarMsg(const std::string& format, const Args&... args) {
-// std::string s = absl::Substitute(format, args...)";
+// void VarMsg(absl::string_view format, const Args&... args) {
+// std::string s = absl::Substitute(format, args...);
ABSL_MUST_USE_RESULT inline std::string Substitute(absl::string_view format) {
std::string result;