blob: 137ca4df2465b926ab32b8d3b5964e02c6f2f9f9 [file] [log] [blame]
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#include "fuchsia_web/common/string_util.h"
#include <string_view>
std::vector<uint8_t> StringToBytes(std::string_view str) {
const uint8_t* raw_data = reinterpret_cast<const uint8_t*>(str.data());
return std::vector<uint8_t>(raw_data, raw_data + str.length());
}
std::string_view BytesAsString(const std::vector<uint8_t>& bytes) {
return std::string_view(reinterpret_cast<const char*>(bytes.data()),
bytes.size());
}