Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(510)

Side by Side Diff: core/fxcrt/fx_basic_wstring.cpp

Issue 1821043003: Remove FX_WORD in favor of uint16_t. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Use stdint.h directly, bitfield minefield. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fxcrt/fx_arabic.cpp ('k') | core/fxcrt/fx_unicode.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cctype> 10 #include <cctype>
11 11
12 #include "core/include/fxcrt/fx_basic.h" 12 #include "core/include/fxcrt/fx_basic.h"
13 #include "core/include/fxcrt/fx_ext.h" 13 #include "core/include/fxcrt/fx_ext.h"
14 #include "third_party/base/numerics/safe_math.h" 14 #include "third_party/base/numerics/safe_math.h"
15 15
16 namespace { 16 namespace {
17 17
18 #ifndef NDEBUG 18 #ifndef NDEBUG
19 bool IsValidCodePage(FX_WORD codepage) { 19 bool IsValidCodePage(uint16_t codepage) {
20 switch (codepage) { 20 switch (codepage) {
21 case 0: 21 case 0:
22 case 932: 22 case 932:
23 case 936: 23 case 936:
24 case 949: 24 case 949:
25 case 950: 25 case 950:
26 return true; 26 return true;
27 27
28 default: 28 default:
29 return false; 29 return false;
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 return m_pData->m_String; 360 return m_pData->m_String;
361 } 361 }
362 362
363 // static 363 // static
364 CFX_WideString CFX_WideString::FromLocal(const CFX_ByteString& str) { 364 CFX_WideString CFX_WideString::FromLocal(const CFX_ByteString& str) {
365 return FromCodePage(str, 0); 365 return FromCodePage(str, 0);
366 } 366 }
367 367
368 // static 368 // static
369 CFX_WideString CFX_WideString::FromCodePage(const CFX_ByteString& str, 369 CFX_WideString CFX_WideString::FromCodePage(const CFX_ByteString& str,
370 FX_WORD codepage) { 370 uint16_t codepage) {
371 return CFX_CharMap::GetWideString(codepage, str); 371 return CFX_CharMap::GetWideString(codepage, str);
372 } 372 }
373 373
374 // static 374 // static
375 CFX_WideString CFX_WideString::FromUTF8(const char* str, FX_STRSIZE len) { 375 CFX_WideString CFX_WideString::FromUTF8(const char* str, FX_STRSIZE len) {
376 if (!str || 0 == len) { 376 if (!str || 0 == len) {
377 return CFX_WideString(); 377 return CFX_WideString();
378 } 378 }
379 379
380 CFX_UTF8Decoder decoder; 380 CFX_UTF8Decoder decoder;
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 return bNegative ? -fraction : fraction; 1010 return bNegative ? -fraction : fraction;
1011 } 1011 }
1012 int CFX_WideString::GetInteger() const { 1012 int CFX_WideString::GetInteger() const {
1013 return m_pData ? FXSYS_wtoi(m_pData->m_String) : 0; 1013 return m_pData ? FXSYS_wtoi(m_pData->m_String) : 0;
1014 } 1014 }
1015 FX_FLOAT CFX_WideString::GetFloat() const { 1015 FX_FLOAT CFX_WideString::GetFloat() const {
1016 return m_pData ? FX_wtof(m_pData->m_String, m_pData->m_nDataLength) : 0.0f; 1016 return m_pData ? FX_wtof(m_pData->m_String, m_pData->m_nDataLength) : 0.0f;
1017 } 1017 }
1018 1018
1019 // static 1019 // static
1020 CFX_ByteString CFX_CharMap::GetByteString(FX_WORD codepage, 1020 CFX_ByteString CFX_CharMap::GetByteString(uint16_t codepage,
1021 const CFX_WideString& wstr) { 1021 const CFX_WideString& wstr) {
1022 FXSYS_assert(IsValidCodePage(codepage)); 1022 FXSYS_assert(IsValidCodePage(codepage));
1023 int src_len = wstr.GetLength(); 1023 int src_len = wstr.GetLength();
1024 int dest_len = FXSYS_WideCharToMultiByte(codepage, 0, wstr.c_str(), src_len, 1024 int dest_len = FXSYS_WideCharToMultiByte(codepage, 0, wstr.c_str(), src_len,
1025 nullptr, 0, nullptr, nullptr); 1025 nullptr, 0, nullptr, nullptr);
1026 CFX_ByteString bstr; 1026 CFX_ByteString bstr;
1027 if (dest_len) { 1027 if (dest_len) {
1028 FX_CHAR* dest_buf = bstr.GetBuffer(dest_len); 1028 FX_CHAR* dest_buf = bstr.GetBuffer(dest_len);
1029 FXSYS_WideCharToMultiByte(codepage, 0, wstr.c_str(), src_len, dest_buf, 1029 FXSYS_WideCharToMultiByte(codepage, 0, wstr.c_str(), src_len, dest_buf,
1030 dest_len, nullptr, nullptr); 1030 dest_len, nullptr, nullptr);
1031 bstr.ReleaseBuffer(dest_len); 1031 bstr.ReleaseBuffer(dest_len);
1032 } 1032 }
1033 return bstr; 1033 return bstr;
1034 } 1034 }
1035 1035
1036 // static 1036 // static
1037 CFX_WideString CFX_CharMap::GetWideString(FX_WORD codepage, 1037 CFX_WideString CFX_CharMap::GetWideString(uint16_t codepage,
1038 const CFX_ByteString& bstr) { 1038 const CFX_ByteString& bstr) {
1039 FXSYS_assert(IsValidCodePage(codepage)); 1039 FXSYS_assert(IsValidCodePage(codepage));
1040 int src_len = bstr.GetLength(); 1040 int src_len = bstr.GetLength();
1041 int dest_len = 1041 int dest_len =
1042 FXSYS_MultiByteToWideChar(codepage, 0, bstr, src_len, nullptr, 0); 1042 FXSYS_MultiByteToWideChar(codepage, 0, bstr, src_len, nullptr, 0);
1043 CFX_WideString wstr; 1043 CFX_WideString wstr;
1044 if (dest_len) { 1044 if (dest_len) {
1045 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len); 1045 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len);
1046 FXSYS_MultiByteToWideChar(codepage, 0, bstr, src_len, dest_buf, dest_len); 1046 FXSYS_MultiByteToWideChar(codepage, 0, bstr, src_len, dest_buf, dest_len);
1047 wstr.ReleaseBuffer(dest_len); 1047 wstr.ReleaseBuffer(dest_len);
1048 } 1048 }
1049 return wstr; 1049 return wstr;
1050 } 1050 }
OLDNEW
« no previous file with comments | « core/fxcrt/fx_arabic.cpp ('k') | core/fxcrt/fx_unicode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698