OLD | NEW |
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 "../../include/fxcrt/fx_basic.h" | 7 #include "../../include/fxcrt/fx_basic.h" |
8 static CFX_StringDataW* FX_AllocStringW(int nLen) | 8 static CFX_StringDataW* FX_AllocStringW(int nLen) |
9 { | 9 { |
10 if (nLen == 0) { | 10 if (nLen == 0) { |
11 return NULL; | 11 return NULL; |
12 } | 12 } |
13 CFX_StringDataW* pData = (CFX_StringDataW*)FX_Alloc(FX_BYTE, sizeof(long) *
3 + (nLen + 1) * sizeof(FX_WCHAR)); | 13 CFX_StringDataW* pData = (CFX_StringDataW*)FX_Alloc(FX_BYTE, sizeof(long) *
3 + (nLen + 1) * sizeof(FX_WCHAR)); |
14 if (!pData) { | 14 if (!pData) { |
(...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 } | 1042 } |
1043 return FXSYS_wtoi(m_pData->m_String); | 1043 return FXSYS_wtoi(m_pData->m_String); |
1044 } | 1044 } |
1045 FX_FLOAT CFX_WideString::GetFloat() const | 1045 FX_FLOAT CFX_WideString::GetFloat() const |
1046 { | 1046 { |
1047 if (m_pData == NULL) { | 1047 if (m_pData == NULL) { |
1048 return 0.0; | 1048 return 0.0; |
1049 } | 1049 } |
1050 return FX_wtof(m_pData->m_String, m_pData->m_nDataLength); | 1050 return FX_wtof(m_pData->m_String, m_pData->m_nDataLength); |
1051 } | 1051 } |
1052 void CFX_WideStringL::Empty(IFX_Allocator* pAllocator) | |
1053 { | |
1054 if (m_Ptr) { | |
1055 FX_Allocator_Free(pAllocator, (FX_LPVOID)m_Ptr); | |
1056 } | |
1057 m_Ptr = NULL, m_Length = 0; | |
1058 } | |
1059 void CFX_WideStringL::Set(FX_WSTR src, IFX_Allocator* pAllocator) | |
1060 { | |
1061 Empty(pAllocator); | |
1062 if (src.GetPtr() != NULL && src.GetLength() > 0) { | |
1063 FX_LPWSTR str = FX_Allocator_Alloc(pAllocator, FX_WCHAR, src.GetLength()
+ 1); | |
1064 if (!str) { | |
1065 return; | |
1066 } | |
1067 FXSYS_memcpy32(str, src.GetPtr(), src.GetLength()*sizeof(FX_WCHAR)); | |
1068 str[src.GetLength()] = '\0'; | |
1069 *(FX_LPWSTR*)(&m_Ptr) = str; | |
1070 m_Length = src.GetLength(); | |
1071 } | |
1072 } | |
1073 int CFX_WideStringL::GetInteger() const | |
1074 { | |
1075 if (!m_Ptr) { | |
1076 return 0; | |
1077 } | |
1078 return FXSYS_wtoi(m_Ptr); | |
1079 } | |
1080 FX_FLOAT CFX_WideStringL::GetFloat() const | |
1081 { | |
1082 if (!m_Ptr) { | |
1083 return 0.0f; | |
1084 } | |
1085 return FX_wtof(m_Ptr, m_Length); | |
1086 } | |
1087 void CFX_WideStringL::TrimRight(FX_LPCWSTR lpszTargets) | |
1088 { | |
1089 if (!lpszTargets || *lpszTargets == 0 || !m_Ptr || m_Length < 1) { | |
1090 return; | |
1091 } | |
1092 FX_STRSIZE pos = m_Length; | |
1093 while (pos) { | |
1094 if (FXSYS_wcschr(lpszTargets, m_Ptr[pos - 1]) == NULL) { | |
1095 break; | |
1096 } | |
1097 pos --; | |
1098 } | |
1099 if (pos < m_Length) { | |
1100 (*(FX_LPWSTR*)(&m_Ptr))[pos] = 0; | |
1101 m_Length = pos; | |
1102 } | |
1103 } | |
1104 static CFX_ByteString _DefMap_GetByteString(CFX_CharMap* pCharMap, const CFX_Wid
eString& widestr) | 1052 static CFX_ByteString _DefMap_GetByteString(CFX_CharMap* pCharMap, const CFX_Wid
eString& widestr) |
1105 { | 1053 { |
1106 int src_len = widestr.GetLength(); | 1054 int src_len = widestr.GetLength(); |
1107 int codepage = pCharMap->m_GetCodePage ? pCharMap->m_GetCodePage() : 0; | 1055 int codepage = pCharMap->m_GetCodePage ? pCharMap->m_GetCodePage() : 0; |
1108 int dest_len = FXSYS_WideCharToMultiByte(codepage, 0, widestr, src_len, NULL
, 0, NULL, NULL); | 1056 int dest_len = FXSYS_WideCharToMultiByte(codepage, 0, widestr, src_len, NULL
, 0, NULL, NULL); |
1109 if (dest_len == 0) { | 1057 if (dest_len == 0) { |
1110 return CFX_ByteString(); | 1058 return CFX_ByteString(); |
1111 } | 1059 } |
1112 CFX_ByteString bytestr; | 1060 CFX_ByteString bytestr; |
1113 FX_LPSTR dest_buf = bytestr.GetBuffer(dest_len); | 1061 FX_LPSTR dest_buf = bytestr.GetBuffer(dest_len); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 return (CFX_CharMap*)&g_DefaultJISMapper; | 1107 return (CFX_CharMap*)&g_DefaultJISMapper; |
1160 case 936: | 1108 case 936: |
1161 return (CFX_CharMap*)&g_DefaultGBKMapper; | 1109 return (CFX_CharMap*)&g_DefaultGBKMapper; |
1162 case 949: | 1110 case 949: |
1163 return (CFX_CharMap*)&g_DefaultUHCMapper; | 1111 return (CFX_CharMap*)&g_DefaultUHCMapper; |
1164 case 950: | 1112 case 950: |
1165 return (CFX_CharMap*)&g_DefaultBig5Mapper; | 1113 return (CFX_CharMap*)&g_DefaultBig5Mapper; |
1166 } | 1114 } |
1167 return NULL; | 1115 return NULL; |
1168 } | 1116 } |
OLD | NEW |