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

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp

Issue 1431683008: Revert "Revert "Revert "Cleanup some numeric code.""" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 1 month 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/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp ('k') | core/src/fpdftext/fpdf_text.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 "../../../include/fpdfapi/fpdf_parser.h" 7 #include "../../../include/fpdfapi/fpdf_parser.h"
8 #include "../../../include/fxcrt/fx_ext.h"
9 8
10 // Indexed by 8-bit character code, contains either: 9 // Indexed by 8-bit character code, contains either:
11 // 'W' - for whitespace: NUL, TAB, CR, LF, FF, 0x80, 0xff 10 // 'W' - for whitespace: NUL, TAB, CR, LF, FF, 0x80, 0xff
12 // 'N' - for numeric: 0123456789+-. 11 // 'N' - for numeric: 0123456789+-.
13 // 'D' - for delimiter: %()/<>[]{} 12 // 'D' - for delimiter: %()/<>[]{}
14 // 'R' - otherwise. 13 // 'R' - otherwise.
15 const char PDF_CharType[256] = { 14 const char PDF_CharType[256] = {
16 // NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO 15 // NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO
17 // SI 16 // SI
18 'W', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'W', 'W', 'R', 'W', 'W', 'R', 17 'W', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'W', 'W', 'R', 'W', 'W', 'R',
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 if (buf_count < nParams) { 272 if (buf_count < nParams) {
274 continue; 273 continue;
275 } 274 }
276 m_dwCurPos = pBuf[buf_index]; 275 m_dwCurPos = pBuf[buf_index];
277 FX_Free(pBuf); 276 FX_Free(pBuf);
278 return TRUE; 277 return TRUE;
279 } 278 }
280 } 279 }
281 return FALSE; 280 return FALSE;
282 } 281 }
283 282 static int _hex2dec(char ch) {
283 if (ch >= '0' && ch <= '9') {
284 return ch - '0';
285 }
286 if (ch >= 'a' && ch <= 'f') {
287 return ch - 'a' + 10;
288 }
289 if (ch >= 'A' && ch <= 'F') {
290 return ch - 'A' + 10;
291 }
292 return 0;
293 }
284 CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& bstr) { 294 CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& bstr) {
285 int size = bstr.GetLength(); 295 int size = bstr.GetLength();
286 const FX_CHAR* pSrc = bstr.GetCStr(); 296 const FX_CHAR* pSrc = bstr.GetCStr();
287 if (FXSYS_memchr(pSrc, '#', size) == NULL) { 297 if (FXSYS_memchr(pSrc, '#', size) == NULL) {
288 return bstr; 298 return bstr;
289 } 299 }
290 CFX_ByteString result; 300 CFX_ByteString result;
291 FX_CHAR* pDestStart = result.GetBuffer(size); 301 FX_CHAR* pDestStart = result.GetBuffer(size);
292 FX_CHAR* pDest = pDestStart; 302 FX_CHAR* pDest = pDestStart;
293 for (int i = 0; i < size; i++) { 303 for (int i = 0; i < size; i++) {
294 if (pSrc[i] == '#' && i < size - 2) { 304 if (pSrc[i] == '#' && i < size - 2) {
295 *pDest++ = 305 *pDest++ = _hex2dec(pSrc[i + 1]) * 16 + _hex2dec(pSrc[i + 2]);
296 FXSYS_toHexDigit(pSrc[i + 1]) * 16 + FXSYS_toHexDigit(pSrc[i + 2]);
297 i += 2; 306 i += 2;
298 } else { 307 } else {
299 *pDest++ = pSrc[i]; 308 *pDest++ = pSrc[i];
300 } 309 }
301 } 310 }
302 result.ReleaseBuffer((FX_STRSIZE)(pDest - pDestStart)); 311 result.ReleaseBuffer((FX_STRSIZE)(pDest - pDestStart));
303 return result; 312 return result;
304 } 313 }
305 CFX_ByteString PDF_NameDecode(const CFX_ByteString& orig) { 314 CFX_ByteString PDF_NameDecode(const CFX_ByteString& orig) {
306 if (FXSYS_memchr(orig.c_str(), '#', orig.GetLength()) == NULL) { 315 if (FXSYS_memchr(orig.c_str(), '#', orig.GetLength()) == NULL) {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 CPDF_Object* pFound = SearchNumberNode(pKid, num); 464 CPDF_Object* pFound = SearchNumberNode(pKid, num);
456 if (pFound) { 465 if (pFound) {
457 return pFound; 466 return pFound;
458 } 467 }
459 } 468 }
460 return NULL; 469 return NULL;
461 } 470 }
462 CPDF_Object* CPDF_NumberTree::LookupValue(int num) { 471 CPDF_Object* CPDF_NumberTree::LookupValue(int num) {
463 return SearchNumberNode(m_pRoot, num); 472 return SearchNumberNode(m_pRoot, num);
464 } 473 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp ('k') | core/src/fpdftext/fpdf_text.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698