test_platform.cc 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2019 The Chromium project 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. // This file is Chromium specific, to make the tests work. It will work
  5. // in the standalone (upstream) build, as well as in Chromium. In other code
  6. // bases (e.g. v8), a custom file with these two functions and with appropriate
  7. // includes may need to be provided, so it isn't necessarily part of a roll.
  8. #include "test_platform.h"
  9. #include <cstdint>
  10. #include <string>
  11. #include <vector>
  12. #include "base/strings/utf_string_conversions.h"
  13. namespace crdtp {
  14. std::string UTF16ToUTF8(span<uint16_t> in) {
  15. std::string out;
  16. bool success = base::UTF16ToUTF8(reinterpret_cast<const char16_t*>(in.data()),
  17. in.size(), &out);
  18. CHECK(success);
  19. return out;
  20. }
  21. std::vector<uint16_t> UTF8ToUTF16(span<uint8_t> in) {
  22. std::u16string tmp;
  23. bool success = base::UTF8ToUTF16(reinterpret_cast<const char*>(in.data()),
  24. in.size(), &tmp);
  25. CHECK(success);
  26. return std::vector<uint16_t>(tmp.begin(), tmp.end());
  27. }
  28. } // namespace crdtp