Kea 2.5.8
utf8.cc
Go to the documentation of this file.
1// Copyright (C) 2020 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
9#include <util/encode/utf8.h>
10
11namespace isc {
12namespace util {
13namespace encode {
14
15std::vector<uint8_t> encodeUtf8(const std::string& value) {
16 std::vector<uint8_t> result;
17 if (value.empty()) {
18 return (result);
19 }
20 const uint8_t* start = reinterpret_cast<const uint8_t*>(value.c_str());
21 std::vector<uint8_t> binary(start, start + value.size());
22 for (uint8_t ch : binary) {
23 if (ch < 0x80) {
24 result.push_back(ch);
25 } else {
26 result.push_back(0xc0 | (ch >> 6));
27 result.push_back(0x80 | (ch & 0x3f));
28 }
29 }
30 return (result);
31}
32
33} // namespace encode
34} // namespace util
35} // namespace isc
std::vector< uint8_t > encodeUtf8(const std::string &value)
Encode value string into UTF-8.
Definition: utf8.cc:15
Defines the logger used by the top-level component of kea-lfc.