blob: 77c52f20747ce0a4ac3f4694df56bd86042a2892 [file] [log] [blame]
Dan Sinclair1770c022016-03-14 14:14:16 -04001// Copyright 2014 PDFium 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
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclaire7786682017-03-29 15:18:41 -04007#include "fxbarcode/BC_UtilCodingConvert.h"
Dan Sinclair1770c022016-03-14 14:14:16 -04008
9CBC_UtilCodingConvert::CBC_UtilCodingConvert() {}
10
11CBC_UtilCodingConvert::~CBC_UtilCodingConvert() {}
12
Ryan Harrison275e2602017-09-18 14:23:18 -040013void CBC_UtilCodingConvert::UnicodeToLocale(const WideString& src,
14 ByteString& dst) {
15 dst = ByteString::FromUnicode(src);
Dan Sinclair1770c022016-03-14 14:14:16 -040016}
17
Ryan Harrison275e2602017-09-18 14:23:18 -040018void CBC_UtilCodingConvert::LocaleToUtf8(const ByteString& src,
19 ByteString& dst) {
20 WideString unicode = WideString::FromLocal(src.AsStringView());
Dan Sinclair1770c022016-03-14 14:14:16 -040021 dst = unicode.UTF8Encode();
22}
23
Ryan Harrison275e2602017-09-18 14:23:18 -040024void CBC_UtilCodingConvert::LocaleToUtf8(const ByteString& src,
Tom Sepez8b6186f2017-03-28 12:06:45 -070025 std::vector<uint8_t>& dst) {
Ryan Harrison275e2602017-09-18 14:23:18 -040026 WideString unicode = WideString::FromLocal(src.AsStringView());
27 ByteString utf8 = unicode.UTF8Encode();
Tom Sepez3c3e2712017-04-17 15:38:19 -070028 dst = std::vector<uint8_t>(utf8.begin(), utf8.end());
Dan Sinclair1770c022016-03-14 14:14:16 -040029}
30
Tom Sepez8b6186f2017-03-28 12:06:45 -070031void CBC_UtilCodingConvert::Utf8ToLocale(const std::vector<uint8_t>& src,
Ryan Harrison275e2602017-09-18 14:23:18 -040032 ByteString& dst) {
33 ByteString utf8;
Tom Sepez8b6186f2017-03-28 12:06:45 -070034 for (uint8_t value : src)
35 utf8 += value;
36
Ryan Harrison275e2602017-09-18 14:23:18 -040037 WideString unicode = WideString::FromUTF8(utf8.AsStringView());
38 dst = ByteString::FromUnicode(unicode);
Dan Sinclair1770c022016-03-14 14:14:16 -040039}
40
41void CBC_UtilCodingConvert::Utf8ToLocale(const uint8_t* src,
42 int32_t count,
Ryan Harrison275e2602017-09-18 14:23:18 -040043 ByteString& dst) {
44 WideString unicode = WideString::FromUTF8(ByteStringView(src, count));
45 dst = ByteString::FromUnicode(unicode);
Dan Sinclair1770c022016-03-14 14:14:16 -040046}
47
Ryan Harrison275e2602017-09-18 14:23:18 -040048void CBC_UtilCodingConvert::UnicodeToUTF8(const WideString& src,
49 ByteString& dst) {
Dan Sinclair1770c022016-03-14 14:14:16 -040050 dst = src.UTF8Encode();
51}