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

Side by Side Diff: xfa/fxfa/parser/xfa_localemgr.cpp

Issue 2095653002: Remove NULL in xfa/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 6 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 | « xfa/fxfa/parser/xfa_locale.cpp ('k') | xfa/fxfa/parser/xfa_localevalue.h » ('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 "xfa/fxfa/parser/xfa_localemgr.h" 7 #include "xfa/fxfa/parser/xfa_localemgr.h"
8 8
9 #include "core/fxcodec/include/fx_codec.h" 9 #include "core/fxcodec/include/fx_codec.h"
10 #include "core/fxcrt/include/fx_xml.h" 10 #include "core/fxcrt/include/fx_xml.h"
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 0x1A, 0xA6, 0xA8, 0x62, 0xAA, 0x19, 0x8C, 0x59, 0x95, 0x54, 0x31, 0x5A, 1026 0x1A, 0xA6, 0xA8, 0x62, 0xAA, 0x19, 0x8C, 0x59, 0x95, 0x54, 0x31, 0x5A,
1027 0xD2, 0xFE, 0x4A, 0x59, 0xC0, 0x55, 0x8A, 0xB7, 0x72, 0x29, 0xB3, 0x54, 1027 0xD2, 0xFE, 0x4A, 0x59, 0xC0, 0x55, 0x8A, 0xB7, 0x72, 0x29, 0xB3, 0x54,
1028 0xAE, 0xC2, 0x23, 0x96, 0x47, 0x59, 0xAE, 0xCB, 0x5A, 0x06, 0x61, 0x91, 1028 0xAE, 0xC2, 0x23, 0x96, 0x47, 0x59, 0xAE, 0xCB, 0x5A, 0x06, 0x61, 0x91,
1029 0xD8, 0xD6, 0x86, 0x8C, 0xE6, 0x89, 0x59, 0xD7, 0x14, 0x9E, 0xD3, 0xD4, 1029 0xD8, 0xD6, 0x86, 0x8C, 0xE6, 0x89, 0x59, 0xD7, 0x14, 0x9E, 0xD3, 0xD4,
1030 0xB3, 0xC7, 0x48, 0xCA, 0x27, 0x43, 0x01, 0x94, 0x3A, 0x09, 0xC8, 0xE5, 1030 0xB3, 0xC7, 0x48, 0xCA, 0x27, 0x43, 0x01, 0x94, 0x3A, 0x09, 0xC8, 0xE5,
1031 0xDC, 0xA3, 0x81, 0x5B, 0xE3, 0x59, 0xA2, 0x27, 0xB9, 0xB4, 0x0A, 0x19, 1031 0xDC, 0xA3, 0x81, 0x5B, 0xE3, 0x59, 0xA2, 0x27, 0xB9, 0xB4, 0x0A, 0x19,
1032 0x89, 0x26, 0xB5, 0x2C, 0xA3, 0xB6, 0x4E, 0x5C, 0xA6, 0x17, 0xA4, 0x7B, 1032 0x89, 0x26, 0xB5, 0x2C, 0xA3, 0xB6, 0x4E, 0x5C, 0xA6, 0x17, 0xA4, 0x7B,
1033 0xB3, 0x85, 0xFA, 0x59, 0x2A, 0x7A, 0xFF, 0x3D, 0xC4, 0x3F, 0xDE, 0xCB, 1033 0xB3, 0x85, 0xFA, 0x59, 0x2A, 0x7A, 0xFF, 0x3D, 0xC4, 0x3F, 0xDE, 0xCB,
1034 0x8B, 0xC4}; 1034 0x8B, 0xC4};
1035 static IFX_Locale* XFA_GetLocaleFromBuffer(const uint8_t* pBuf, int nBufLen) { 1035 static IFX_Locale* XFA_GetLocaleFromBuffer(const uint8_t* pBuf, int nBufLen) {
1036 if (pBuf == NULL || nBufLen <= 0) { 1036 if (!pBuf || nBufLen <= 0) {
1037 return NULL; 1037 return nullptr;
1038 } 1038 }
1039 CFX_GEModule* pGeModule = CFX_GEModule::Get(); 1039 CFX_GEModule* pGeModule = CFX_GEModule::Get();
1040 if (!pGeModule) { 1040 if (!pGeModule) {
1041 return NULL; 1041 return nullptr;
1042 } 1042 }
1043 CCodec_ModuleMgr* pCodecMgr = pGeModule->GetCodecModule(); 1043 CCodec_ModuleMgr* pCodecMgr = pGeModule->GetCodecModule();
1044 if (!pCodecMgr) { 1044 if (!pCodecMgr) {
1045 return NULL; 1045 return nullptr;
1046 } 1046 }
1047 CXML_Element* pLocale = NULL; 1047 CXML_Element* pLocale = nullptr;
1048 uint8_t* pOut = NULL; 1048 uint8_t* pOut = nullptr;
1049 uint32_t dwSize; 1049 uint32_t dwSize;
1050 pCodecMgr->GetFlateModule()->FlateOrLZWDecode(FALSE, pBuf, nBufLen, TRUE, 0, 1050 pCodecMgr->GetFlateModule()->FlateOrLZWDecode(FALSE, pBuf, nBufLen, TRUE, 0,
1051 0, 0, 0, 0, pOut, dwSize); 1051 0, 0, 0, 0, pOut, dwSize);
1052 if (pOut) { 1052 if (pOut) {
1053 pLocale = CXML_Element::Parse(pOut, dwSize); 1053 pLocale = CXML_Element::Parse(pOut, dwSize);
1054 FX_Free(pOut); 1054 FX_Free(pOut);
1055 } 1055 }
1056 if (pLocale) { 1056 if (pLocale) {
1057 return new CXFA_XMLLocale(pLocale); 1057 return new CXFA_XMLLocale(pLocale);
1058 } 1058 }
1059 return NULL; 1059 return nullptr;
1060 } 1060 }
1061 static uint16_t XFA_GetLanguage(CFX_WideString wsLanguage) { 1061 static uint16_t XFA_GetLanguage(CFX_WideString wsLanguage) {
1062 uint16_t dwLangueID = XFA_LANGID_en_US; 1062 uint16_t dwLangueID = XFA_LANGID_en_US;
1063 if (wsLanguage.GetLength() < 2) { 1063 if (wsLanguage.GetLength() < 2) {
1064 return dwLangueID; 1064 return dwLangueID;
1065 } 1065 }
1066 wsLanguage.MakeLower(); 1066 wsLanguage.MakeLower();
1067 uint32_t dwIDFirst = wsLanguage.GetAt(0) << 8 | wsLanguage.GetAt(1); 1067 uint32_t dwIDFirst = wsLanguage.GetAt(0) << 8 | wsLanguage.GetAt(1);
1068 uint32_t dwIDSecond = wsLanguage.GetLength() >= 5 1068 uint32_t dwIDSecond = wsLanguage.GetLength() >= 5
1069 ? wsLanguage.GetAt(3) << 8 | wsLanguage.GetAt(4) 1069 ? wsLanguage.GetAt(3) << 8 | wsLanguage.GetAt(4)
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 return m_XMLLocaleArray[0]; 1156 return m_XMLLocaleArray[0];
1157 1157
1158 m_pDefLocale = GetLocale(m_dwDeflcid); 1158 m_pDefLocale = GetLocale(m_dwDeflcid);
1159 if (m_pDefLocale) 1159 if (m_pDefLocale)
1160 m_XMLLocaleArray.Add(m_pDefLocale); 1160 m_XMLLocaleArray.Add(m_pDefLocale);
1161 1161
1162 return m_pDefLocale; 1162 return m_pDefLocale;
1163 } 1163 }
1164 1164
1165 IFX_Locale* CXFA_LocaleMgr::GetLocale(uint16_t lcid) { 1165 IFX_Locale* CXFA_LocaleMgr::GetLocale(uint16_t lcid) {
1166 IFX_Locale* pLocal = NULL; 1166 IFX_Locale* pLocal = nullptr;
1167 switch (lcid) { 1167 switch (lcid) {
1168 case XFA_LANGID_zh_CN: 1168 case XFA_LANGID_zh_CN:
1169 pLocal = XFA_GetLocaleFromBuffer(g_zhCN_Locale, sizeof(g_zhCN_Locale)); 1169 pLocal = XFA_GetLocaleFromBuffer(g_zhCN_Locale, sizeof(g_zhCN_Locale));
1170 break; 1170 break;
1171 case XFA_LANGID_zh_TW: 1171 case XFA_LANGID_zh_TW:
1172 pLocal = XFA_GetLocaleFromBuffer(g_zhTW_Locale, sizeof(g_zhTW_Locale)); 1172 pLocal = XFA_GetLocaleFromBuffer(g_zhTW_Locale, sizeof(g_zhTW_Locale));
1173 break; 1173 break;
1174 case XFA_LANGID_zh_HK: 1174 case XFA_LANGID_zh_HK:
1175 pLocal = XFA_GetLocaleFromBuffer(g_zhHK_Locale, sizeof(g_zhHK_Locale)); 1175 pLocal = XFA_GetLocaleFromBuffer(g_zhHK_Locale, sizeof(g_zhHK_Locale));
1176 break; 1176 break;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 int32_t iCount = m_LocaleArray.GetSize(); 1219 int32_t iCount = m_LocaleArray.GetSize();
1220 int32_t i = 0; 1220 int32_t i = 0;
1221 for (i = 0; i < iCount; i++) { 1221 for (i = 0; i < iCount; i++) {
1222 IFX_Locale* pLocale = m_LocaleArray[i]; 1222 IFX_Locale* pLocale = m_LocaleArray[i];
1223 if (pLocale->GetName() == wsLocaleName) { 1223 if (pLocale->GetName() == wsLocaleName) {
1224 return pLocale; 1224 return pLocale;
1225 } 1225 }
1226 } 1226 }
1227 int32_t iLen = wsLocaleName.GetLength(); 1227 int32_t iLen = wsLocaleName.GetLength();
1228 if (iLen < 2) { 1228 if (iLen < 2) {
1229 return NULL; 1229 return nullptr;
1230 } 1230 }
1231 iCount = m_XMLLocaleArray.GetSize(); 1231 iCount = m_XMLLocaleArray.GetSize();
1232 for (i = 0; i < iCount; i++) { 1232 for (i = 0; i < iCount; i++) {
1233 IFX_Locale* pLocale = m_XMLLocaleArray[i]; 1233 IFX_Locale* pLocale = m_XMLLocaleArray[i];
1234 if (pLocale->GetName() == wsLocaleName) { 1234 if (pLocale->GetName() == wsLocaleName) {
1235 return pLocale; 1235 return pLocale;
1236 } 1236 }
1237 } 1237 }
1238 uint16_t dwLangueID = XFA_GetLanguage(wsLocaleName); 1238 uint16_t dwLangueID = XFA_GetLanguage(wsLocaleName);
1239 IFX_Locale* pLocale = GetLocale(dwLangueID); 1239 IFX_Locale* pLocale = GetLocale(dwLangueID);
1240 if (pLocale) 1240 if (pLocale)
1241 m_XMLLocaleArray.Add(pLocale); 1241 m_XMLLocaleArray.Add(pLocale);
1242 return pLocale; 1242 return pLocale;
1243 } 1243 }
1244 void CXFA_LocaleMgr::SetDefLocale(IFX_Locale* pLocale) { 1244 void CXFA_LocaleMgr::SetDefLocale(IFX_Locale* pLocale) {
1245 m_pDefLocale = pLocale; 1245 m_pDefLocale = pLocale;
1246 } 1246 }
1247 CFX_WideStringC CXFA_LocaleMgr::GetConfigLocaleName(CXFA_Node* pConfig) { 1247 CFX_WideStringC CXFA_LocaleMgr::GetConfigLocaleName(CXFA_Node* pConfig) {
1248 if (!(m_dwLocaleFlags & 0x01)) { 1248 if (!(m_dwLocaleFlags & 0x01)) {
1249 m_wsConfigLocale.clear(); 1249 m_wsConfigLocale.clear();
1250 if (pConfig) { 1250 if (pConfig) {
1251 CXFA_Node* pChildfConfig = 1251 CXFA_Node* pChildfConfig =
1252 pConfig->GetFirstChildByClass(XFA_Element::Acrobat); 1252 pConfig->GetFirstChildByClass(XFA_Element::Acrobat);
1253 if (!pChildfConfig) { 1253 if (!pChildfConfig) {
1254 pChildfConfig = pConfig->GetFirstChildByClass(XFA_Element::Present); 1254 pChildfConfig = pConfig->GetFirstChildByClass(XFA_Element::Present);
1255 } 1255 }
1256 CXFA_Node* pCommon = 1256 CXFA_Node* pCommon =
1257 pChildfConfig 1257 pChildfConfig
1258 ? pChildfConfig->GetFirstChildByClass(XFA_Element::Common) 1258 ? pChildfConfig->GetFirstChildByClass(XFA_Element::Common)
1259 : NULL; 1259 : nullptr;
1260 CXFA_Node* pLocale = 1260 CXFA_Node* pLocale =
1261 pCommon ? pCommon->GetFirstChildByClass(XFA_Element::Locale) : NULL; 1261 pCommon ? pCommon->GetFirstChildByClass(XFA_Element::Locale)
1262 : nullptr;
1262 if (pLocale) { 1263 if (pLocale) {
1263 pLocale->TryCData(XFA_ATTRIBUTE_Value, m_wsConfigLocale, FALSE); 1264 pLocale->TryCData(XFA_ATTRIBUTE_Value, m_wsConfigLocale, FALSE);
1264 } 1265 }
1265 } 1266 }
1266 m_dwLocaleFlags |= 0x01; 1267 m_dwLocaleFlags |= 0x01;
1267 } 1268 }
1268 return m_wsConfigLocale.AsStringC(); 1269 return m_wsConfigLocale.AsStringC();
1269 } 1270 }
1270 static CXFA_TimeZoneProvider* g_pProvider = NULL; 1271 static CXFA_TimeZoneProvider* g_pProvider = nullptr;
1271 1272
1272 // Static. 1273 // Static.
1273 CXFA_TimeZoneProvider* CXFA_TimeZoneProvider::Create() { 1274 CXFA_TimeZoneProvider* CXFA_TimeZoneProvider::Create() {
1274 ASSERT(!g_pProvider); 1275 ASSERT(!g_pProvider);
1275 g_pProvider = new CXFA_TimeZoneProvider(); 1276 g_pProvider = new CXFA_TimeZoneProvider();
1276 return g_pProvider; 1277 return g_pProvider;
1277 } 1278 }
1278 1279
1279 // Static. 1280 // Static.
1280 CXFA_TimeZoneProvider* CXFA_TimeZoneProvider::Get() { 1281 CXFA_TimeZoneProvider* CXFA_TimeZoneProvider::Get() {
1281 if (!g_pProvider) { 1282 if (!g_pProvider) {
1282 g_pProvider = new CXFA_TimeZoneProvider(); 1283 g_pProvider = new CXFA_TimeZoneProvider();
1283 } 1284 }
1284 return g_pProvider; 1285 return g_pProvider;
1285 } 1286 }
1286 1287
1287 // Static. 1288 // Static.
1288 void CXFA_TimeZoneProvider::Destroy() { 1289 void CXFA_TimeZoneProvider::Destroy() {
1289 delete g_pProvider; 1290 delete g_pProvider;
1290 g_pProvider = NULL; 1291 g_pProvider = nullptr;
1291 } 1292 }
1292 1293
1293 #include <time.h> 1294 #include <time.h>
1294 CXFA_TimeZoneProvider::CXFA_TimeZoneProvider() { 1295 CXFA_TimeZoneProvider::CXFA_TimeZoneProvider() {
1295 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 1296 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
1296 _tzset(); 1297 _tzset();
1297 m_tz.tzHour = (int8_t)(_timezone / 3600 * -1); 1298 m_tz.tzHour = (int8_t)(_timezone / 3600 * -1);
1298 m_tz.tzMinute = (int8_t)((FXSYS_abs(_timezone) % 3600) / 60); 1299 m_tz.tzMinute = (int8_t)((FXSYS_abs(_timezone) % 3600) / 60);
1299 #else 1300 #else
1300 tzset(); 1301 tzset();
1301 m_tz.tzHour = (int8_t)(timezone / 3600 * -1); 1302 m_tz.tzHour = (int8_t)(timezone / 3600 * -1);
1302 m_tz.tzMinute = (int8_t)((FXSYS_abs((int)timezone) % 3600) / 60); 1303 m_tz.tzMinute = (int8_t)((FXSYS_abs((int)timezone) % 3600) / 60);
1303 #endif 1304 #endif
1304 } 1305 }
1305 CXFA_TimeZoneProvider::~CXFA_TimeZoneProvider() {} 1306 CXFA_TimeZoneProvider::~CXFA_TimeZoneProvider() {}
1306 void CXFA_TimeZoneProvider::SetTimeZone(FX_TIMEZONE& tz) { 1307 void CXFA_TimeZoneProvider::SetTimeZone(FX_TIMEZONE& tz) {
1307 m_tz = tz; 1308 m_tz = tz;
1308 } 1309 }
1309 void CXFA_TimeZoneProvider::GetTimeZone(FX_TIMEZONE& tz) { 1310 void CXFA_TimeZoneProvider::GetTimeZone(FX_TIMEZONE& tz) {
1310 tz = m_tz; 1311 tz = m_tz;
1311 } 1312 }
OLDNEW
« no previous file with comments | « xfa/fxfa/parser/xfa_locale.cpp ('k') | xfa/fxfa/parser/xfa_localevalue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698