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 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 13 | void CBC_UtilCodingConvert::UnicodeToLocale(const WideString& src, |
| 14 | ByteString& dst) { |
| 15 | dst = ByteString::FromUnicode(src); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 16 | } |
| 17 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 18 | void CBC_UtilCodingConvert::LocaleToUtf8(const ByteString& src, |
| 19 | ByteString& dst) { |
| 20 | WideString unicode = WideString::FromLocal(src.AsStringView()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 21 | dst = unicode.UTF8Encode(); |
| 22 | } |
| 23 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 24 | void CBC_UtilCodingConvert::LocaleToUtf8(const ByteString& src, |
Tom Sepez | 8b6186f | 2017-03-28 12:06:45 -0700 | [diff] [blame] | 25 | std::vector<uint8_t>& dst) { |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 26 | WideString unicode = WideString::FromLocal(src.AsStringView()); |
| 27 | 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, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 32 | ByteString& dst) { |
| 33 | ByteString utf8; |
Tom Sepez | 8b6186f | 2017-03-28 12:06:45 -0700 | [diff] [blame] | 34 | for (uint8_t value : src) |
| 35 | utf8 += value; |
| 36 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 37 | WideString unicode = WideString::FromUTF8(utf8.AsStringView()); |
| 38 | dst = ByteString::FromUnicode(unicode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | void CBC_UtilCodingConvert::Utf8ToLocale(const uint8_t* src, |
| 42 | int32_t count, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 43 | ByteString& dst) { |
| 44 | WideString unicode = WideString::FromUTF8(ByteStringView(src, count)); |
| 45 | dst = ByteString::FromUnicode(unicode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 46 | } |
| 47 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 48 | void CBC_UtilCodingConvert::UnicodeToUTF8(const WideString& src, |
| 49 | ByteString& dst) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 50 | dst = src.UTF8Encode(); |
| 51 | } |