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