• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // 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 
7 #include "fxbarcode/BC_UtilCodingConvert.h"
8 
CBC_UtilCodingConvert()9 CBC_UtilCodingConvert::CBC_UtilCodingConvert() {}
10 
~CBC_UtilCodingConvert()11 CBC_UtilCodingConvert::~CBC_UtilCodingConvert() {}
12 
UnicodeToLocale(const WideString & src,ByteString & dst)13 void CBC_UtilCodingConvert::UnicodeToLocale(const WideString& src,
14                                             ByteString& dst) {
15   dst = ByteString::FromUnicode(src);
16 }
17 
LocaleToUtf8(const ByteString & src,ByteString & dst)18 void CBC_UtilCodingConvert::LocaleToUtf8(const ByteString& src,
19                                          ByteString& dst) {
20   WideString unicode = WideString::FromLocal(src.AsStringView());
21   dst = unicode.UTF8Encode();
22 }
23 
LocaleToUtf8(const ByteString & src,std::vector<uint8_t> & dst)24 void CBC_UtilCodingConvert::LocaleToUtf8(const ByteString& src,
25                                          std::vector<uint8_t>& dst) {
26   WideString unicode = WideString::FromLocal(src.AsStringView());
27   ByteString utf8 = unicode.UTF8Encode();
28   dst = std::vector<uint8_t>(utf8.begin(), utf8.end());
29 }
30 
Utf8ToLocale(const std::vector<uint8_t> & src,ByteString & dst)31 void CBC_UtilCodingConvert::Utf8ToLocale(const std::vector<uint8_t>& src,
32                                          ByteString& dst) {
33   ByteString utf8;
34   for (uint8_t value : src)
35     utf8 += value;
36 
37   WideString unicode = WideString::FromUTF8(utf8.AsStringView());
38   dst = ByteString::FromUnicode(unicode);
39 }
40 
Utf8ToLocale(const uint8_t * src,int32_t count,ByteString & dst)41 void CBC_UtilCodingConvert::Utf8ToLocale(const uint8_t* src,
42                                          int32_t count,
43                                          ByteString& dst) {
44   WideString unicode = WideString::FromUTF8(ByteStringView(src, count));
45   dst = ByteString::FromUnicode(unicode);
46 }
47 
UnicodeToUTF8(const WideString & src,ByteString & dst)48 void CBC_UtilCodingConvert::UnicodeToUTF8(const WideString& src,
49                                           ByteString& dst) {
50   dst = src.UTF8Encode();
51 }
52