abseil_string_conversions.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_STRINGS_ABSEIL_STRING_CONVERSIONS_H_
  5. #define BASE_STRINGS_ABSEIL_STRING_CONVERSIONS_H_
  6. #include <vector>
  7. #include "base/base_export.h"
  8. #include "base/containers/span.h"
  9. #include "base/strings/string_piece.h"
  10. #include "third_party/abseil-cpp/absl/strings/string_view.h"
  11. namespace base {
  12. // Converts `piece` to a string view, pointing to the same piece of memory.
  13. constexpr absl::string_view StringPieceToStringView(StringPiece piece) {
  14. return {piece.data(), piece.size()};
  15. }
  16. // Converts `view` to a string piece, pointing to the same piece of memory.
  17. constexpr StringPiece StringViewToStringPiece(absl::string_view view) {
  18. return {view.data(), view.size()};
  19. }
  20. // Converts `pieces` to string views, pointing to the same piece of memory.
  21. BASE_EXPORT std::vector<absl::string_view> StringPiecesToStringViews(
  22. span<const StringPiece> pieces);
  23. // Converts `views` to string pieces, pointing to the same piece of memory.
  24. BASE_EXPORT std::vector<StringPiece> StringViewsToStringPieces(
  25. span<const absl::string_view> views);
  26. } // namespace base
  27. #endif // BASE_STRINGS_ABSEIL_STRING_CONVERSIONS_H_