| 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 #include "core/include/fxcrt/fx_ext.h" |
| 9 | 9 |
| 10 // Indexed by 8-bit character code, contains either: | 10 // Indexed by 8-bit character code, contains either: |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 FX_Free(pBuf); | 277 FX_Free(pBuf); |
| 278 return TRUE; | 278 return TRUE; |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 return FALSE; | 281 return FALSE; |
| 282 } | 282 } |
| 283 | 283 |
| 284 CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& bstr) { | 284 CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& bstr) { |
| 285 int size = bstr.GetLength(); | 285 int size = bstr.GetLength(); |
| 286 const FX_CHAR* pSrc = bstr.GetCStr(); | 286 const FX_CHAR* pSrc = bstr.GetCStr(); |
| 287 if (FXSYS_memchr(pSrc, '#', size) == NULL) { | 287 if (!FXSYS_memchr(pSrc, '#', size)) { |
| 288 return bstr; | 288 return bstr; |
| 289 } | 289 } |
| 290 CFX_ByteString result; | 290 CFX_ByteString result; |
| 291 FX_CHAR* pDestStart = result.GetBuffer(size); | 291 FX_CHAR* pDestStart = result.GetBuffer(size); |
| 292 FX_CHAR* pDest = pDestStart; | 292 FX_CHAR* pDest = pDestStart; |
| 293 for (int i = 0; i < size; i++) { | 293 for (int i = 0; i < size; i++) { |
| 294 if (pSrc[i] == '#' && i < size - 2) { | 294 if (pSrc[i] == '#' && i < size - 2) { |
| 295 *pDest++ = | 295 *pDest++ = |
| 296 FXSYS_toHexDigit(pSrc[i + 1]) * 16 + FXSYS_toHexDigit(pSrc[i + 2]); | 296 FXSYS_toHexDigit(pSrc[i + 1]) * 16 + FXSYS_toHexDigit(pSrc[i + 2]); |
| 297 i += 2; | 297 i += 2; |
| 298 } else { | 298 } else { |
| 299 *pDest++ = pSrc[i]; | 299 *pDest++ = pSrc[i]; |
| 300 } | 300 } |
| 301 } | 301 } |
| 302 result.ReleaseBuffer((FX_STRSIZE)(pDest - pDestStart)); | 302 result.ReleaseBuffer((FX_STRSIZE)(pDest - pDestStart)); |
| 303 return result; | 303 return result; |
| 304 } | 304 } |
| 305 CFX_ByteString PDF_NameDecode(const CFX_ByteString& orig) { | 305 CFX_ByteString PDF_NameDecode(const CFX_ByteString& orig) { |
| 306 if (FXSYS_memchr(orig.c_str(), '#', orig.GetLength()) == NULL) { | 306 if (!FXSYS_memchr(orig.c_str(), '#', orig.GetLength())) { |
| 307 return orig; | 307 return orig; |
| 308 } | 308 } |
| 309 return PDF_NameDecode(CFX_ByteStringC(orig)); | 309 return PDF_NameDecode(CFX_ByteStringC(orig)); |
| 310 } | 310 } |
| 311 CFX_ByteString PDF_NameEncode(const CFX_ByteString& orig) { | 311 CFX_ByteString PDF_NameEncode(const CFX_ByteString& orig) { |
| 312 uint8_t* src_buf = (uint8_t*)orig.c_str(); | 312 uint8_t* src_buf = (uint8_t*)orig.c_str(); |
| 313 int src_len = orig.GetLength(); | 313 int src_len = orig.GetLength(); |
| 314 int dest_len = 0; | 314 int dest_len = 0; |
| 315 int i; | 315 int i; |
| 316 for (i = 0; i < src_len; i++) { | 316 for (i = 0; i < src_len; i++) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 337 dest_buf[dest_len++] = "0123456789ABCDEF"[ch % 16]; | 337 dest_buf[dest_len++] = "0123456789ABCDEF"[ch % 16]; |
| 338 } else { | 338 } else { |
| 339 dest_buf[dest_len++] = ch; | 339 dest_buf[dest_len++] = ch; |
| 340 } | 340 } |
| 341 } | 341 } |
| 342 dest_buf[dest_len] = 0; | 342 dest_buf[dest_len] = 0; |
| 343 res.ReleaseBuffer(); | 343 res.ReleaseBuffer(); |
| 344 return res; | 344 return res; |
| 345 } | 345 } |
| 346 CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) { | 346 CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) { |
| 347 if (pObj == NULL) { | 347 if (!pObj) { |
| 348 buf << " null"; | 348 buf << " null"; |
| 349 return buf; | 349 return buf; |
| 350 } | 350 } |
| 351 switch (pObj->GetType()) { | 351 switch (pObj->GetType()) { |
| 352 case PDFOBJ_NULL: | 352 case PDFOBJ_NULL: |
| 353 buf << " null"; | 353 buf << " null"; |
| 354 break; | 354 break; |
| 355 case PDFOBJ_BOOLEAN: | 355 case PDFOBJ_BOOLEAN: |
| 356 case PDFOBJ_NUMBER: | 356 case PDFOBJ_NUMBER: |
| 357 buf << " " << pObj->GetString(); | 357 buf << " " << pObj->GetString(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 if (num == index) { | 437 if (num == index) { |
| 438 return pNumbers->GetElementValue(i * 2 + 1); | 438 return pNumbers->GetElementValue(i * 2 + 1); |
| 439 } | 439 } |
| 440 if (index > num) { | 440 if (index > num) { |
| 441 break; | 441 break; |
| 442 } | 442 } |
| 443 } | 443 } |
| 444 return NULL; | 444 return NULL; |
| 445 } | 445 } |
| 446 CPDF_Array* pKids = pNode->GetArray("Kids"); | 446 CPDF_Array* pKids = pNode->GetArray("Kids"); |
| 447 if (pKids == NULL) { | 447 if (!pKids) { |
| 448 return NULL; | 448 return NULL; |
| 449 } | 449 } |
| 450 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { | 450 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { |
| 451 CPDF_Dictionary* pKid = pKids->GetDict(i); | 451 CPDF_Dictionary* pKid = pKids->GetDict(i); |
| 452 if (pKid == NULL) { | 452 if (!pKid) { |
| 453 continue; | 453 continue; |
| 454 } | 454 } |
| 455 CPDF_Object* pFound = SearchNumberNode(pKid, num); | 455 CPDF_Object* pFound = SearchNumberNode(pKid, num); |
| 456 if (pFound) { | 456 if (pFound) { |
| 457 return pFound; | 457 return pFound; |
| 458 } | 458 } |
| 459 } | 459 } |
| 460 return NULL; | 460 return NULL; |
| 461 } | 461 } |
| 462 CPDF_Object* CPDF_NumberTree::LookupValue(int num) { | 462 CPDF_Object* CPDF_NumberTree::LookupValue(int num) { |
| 463 return SearchNumberNode(m_pRoot, num); | 463 return SearchNumberNode(m_pRoot, num); |
| 464 } | 464 } |
| OLD | NEW |