Move QuicheTextUtils out of platform.
All methods are now defined in terms of Abseil or STL, there is no need
for QuicheTextUtils to live in platform.
PiperOrigin-RevId: 370889335
Change-Id: Id75b2f7c6d694481eea17d85690ce12bca03f917
diff --git a/common/quiche_text_utils.h b/common/quiche_text_utils.h
new file mode 100644
index 0000000..c99d9e2
--- /dev/null
+++ b/common/quiche_text_utils.h
@@ -0,0 +1,60 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef QUICHE_COMMON_QUICHE_TEXT_UTILS_H_
+#define QUICHE_COMMON_QUICHE_TEXT_UTILS_H_
+
+#include <string>
+
+#include "absl/strings/ascii.h"
+#include "absl/strings/escaping.h"
+#include "absl/strings/string_view.h"
+#include "absl/types/optional.h"
+#include "common/platform/api/quiche_export.h"
+
+namespace quiche {
+
+// Various utilities for manipulating text.
+class QUICHE_EXPORT QuicheTextUtils {
+ public:
+ // Returns a new string in which |data| has been converted to lower case.
+ static std::string ToLower(absl::string_view data) {
+ return absl::AsciiStrToLower(data);
+ }
+
+ // Removes leading and trailing whitespace from |data|.
+ static void RemoveLeadingAndTrailingWhitespace(absl::string_view* data) {
+ *data = absl::StripAsciiWhitespace(*data);
+ }
+
+ // Base64 encodes with no padding |data_len| bytes of |data| into |output|.
+ static void Base64Encode(const uint8_t* data,
+ size_t data_len,
+ std::string* output);
+
+ // Decodes a base64-encoded |input|. Returns nullopt when the input is
+ // invalid.
+ static absl::optional<std::string> Base64Decode(absl::string_view input);
+
+ // Returns a string containing hex and ASCII representations of |binary|,
+ // side-by-side in the style of hexdump. Non-printable characters will be
+ // printed as '.' in the ASCII output.
+ // For example, given the input "Hello, QUIC!\01\02\03\04", returns:
+ // "0x0000: 4865 6c6c 6f2c 2051 5549 4321 0102 0304 Hello,.QUIC!...."
+ static std::string HexDump(absl::string_view binary_data);
+
+ // Returns true if |data| contains any uppercase characters.
+ static bool ContainsUpperCase(absl::string_view data) {
+ return std::any_of(data.begin(), data.end(), absl::ascii_isupper);
+ }
+
+ // Returns true if |data| contains only decimal digits.
+ static bool IsAllDigits(absl::string_view data) {
+ return std::all_of(data.begin(), data.end(), absl::ascii_isdigit);
+ }
+};
+
+} // namespace quiche
+
+#endif // QUICHE_COMMON_QUICHE_TEXT_UTILS_H_