Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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 | |
Dan Sinclair | e778668 | 2017-03-29 15:18:41 -0400 | [diff] [blame] | 7 | #include "fxbarcode/BC_UtilCodingConvert.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 8 | |
| 9 | CBC_UtilCodingConvert::CBC_UtilCodingConvert() {} |
| 10 | |
| 11 | CBC_UtilCodingConvert::~CBC_UtilCodingConvert() {} |
| 12 | |
| 13 | void CBC_UtilCodingConvert::UnicodeToLocale(const CFX_WideString& src, |
| 14 | CFX_ByteString& dst) { |
| 15 | dst = CFX_ByteString::FromUnicode(src); |
| 16 | } |
| 17 | |
| 18 | void CBC_UtilCodingConvert::LocaleToUtf8(const CFX_ByteString& src, |
| 19 | CFX_ByteString& dst) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 20 | CFX_WideString unicode = CFX_WideString::FromLocal(src.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 21 | dst = unicode.UTF8Encode(); |
| 22 | } |
| 23 | |
| 24 | void CBC_UtilCodingConvert::LocaleToUtf8(const CFX_ByteString& src, |
Tom Sepez | 8b6186f | 2017-03-28 12:06:45 -0700 | [diff] [blame] | 25 | std::vector<uint8_t>& dst) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 26 | CFX_WideString unicode = CFX_WideString::FromLocal(src.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 27 | CFX_ByteString utf8 = unicode.UTF8Encode(); |
Tom Sepez | 3c3e271 | 2017-04-17 15:38:19 -0700 | [diff] [blame] | 28 | dst = std::vector<uint8_t>(utf8.begin(), utf8.end()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 29 | } |
| 30 | |
Tom Sepez | 8b6186f | 2017-03-28 12:06:45 -0700 | [diff] [blame] | 31 | void CBC_UtilCodingConvert::Utf8ToLocale(const std::vector<uint8_t>& src, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 32 | CFX_ByteString& dst) { |
| 33 | CFX_ByteString utf8; |
Tom Sepez | 8b6186f | 2017-03-28 12:06:45 -0700 | [diff] [blame] | 34 | for (uint8_t value : src) |
| 35 | utf8 += value; |
| 36 | |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 37 | CFX_WideString unicode = CFX_WideString::FromUTF8(utf8.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 38 | dst = CFX_ByteString::FromUnicode(unicode); |
| 39 | } |
| 40 | |
| 41 | void CBC_UtilCodingConvert::Utf8ToLocale(const uint8_t* src, |
| 42 | int32_t count, |
| 43 | CFX_ByteString& dst) { |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 44 | CFX_WideString unicode = |
| 45 | CFX_WideString::FromUTF8(CFX_ByteStringC(src, count)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 46 | dst = CFX_ByteString::FromUnicode(unicode); |
| 47 | } |
| 48 | |
| 49 | void CBC_UtilCodingConvert::UnicodeToUTF8(const CFX_WideString& src, |
| 50 | CFX_ByteString& dst) { |
| 51 | dst = src.UTF8Encode(); |
| 52 | } |