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

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

Issue 1418073006: Add PDFCharIsLineEnding helper (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master 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
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 <limits.h> 7 #include <limits.h>
8 #include "../../../include/fpdfapi/fpdf_parser.h" 8 #include "../../../include/fpdfapi/fpdf_parser.h"
9 #include "../../../include/fpdfapi/fpdf_module.h" 9 #include "../../../include/fpdfapi/fpdf_module.h"
10 #include "../../../include/fxcodec/fx_codec.h" 10 #include "../../../include/fxcodec/fx_codec.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 73 }
74 if (zcount * 4 > UINT_MAX - (pos - zcount)) { 74 if (zcount * 4 > UINT_MAX - (pos - zcount)) {
75 return (FX_DWORD)-1; 75 return (FX_DWORD)-1;
76 } 76 }
77 dest_buf = FX_Alloc(uint8_t, zcount * 4 + (pos - zcount)); 77 dest_buf = FX_Alloc(uint8_t, zcount * 4 + (pos - zcount));
78 int state = 0; 78 int state = 0;
79 uint32_t res = 0; 79 uint32_t res = 0;
80 pos = dest_size = 0; 80 pos = dest_size = 0;
81 while (pos < src_size) { 81 while (pos < src_size) {
82 uint8_t ch = src_buf[pos++]; 82 uint8_t ch = src_buf[pos++];
83 if (ch == '\n' || ch == '\r' || ch == ' ' || ch == '\t') { 83 if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t')
84 continue; 84 continue;
85 } 85
86 if (ch == 'z') { 86 if (ch == 'z') {
87 FXSYS_memset(dest_buf + dest_size, 0, 4); 87 FXSYS_memset(dest_buf + dest_size, 0, 4);
88 state = 0; 88 state = 0;
89 res = 0; 89 res = 0;
90 dest_size += 4; 90 dest_size += 4;
91 } else { 91 } else {
92 if (ch < '!' || ch > 'u') { 92 if (ch < '!' || ch > 'u') {
93 break; 93 break;
94 } 94 }
95 res = res * 85 + ch - 33; 95 res = res * 85 + ch - 33;
(...skipping 28 matching lines...) Expand all
124 FX_DWORD i; 124 FX_DWORD i;
125 for (i = 0; i < src_size; i++) 125 for (i = 0; i < src_size; i++)
126 if (src_buf[i] == '>') { 126 if (src_buf[i] == '>') {
127 break; 127 break;
128 } 128 }
129 dest_buf = FX_Alloc(uint8_t, i / 2 + 1); 129 dest_buf = FX_Alloc(uint8_t, i / 2 + 1);
130 dest_size = 0; 130 dest_size = 0;
131 FX_BOOL bFirstDigit = TRUE; 131 FX_BOOL bFirstDigit = TRUE;
132 for (i = 0; i < src_size; i++) { 132 for (i = 0; i < src_size; i++) {
133 uint8_t ch = src_buf[i]; 133 uint8_t ch = src_buf[i];
134 if (ch == ' ' || ch == '\n' || ch == '\t' || ch == '\r') { 134 if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t')
135 continue; 135 continue;
136 } 136
137 int digit; 137 int digit;
138 if (ch <= '9' && ch >= '0') { 138 if (ch <= '9' && ch >= '0') {
139 digit = ch - '0'; 139 digit = ch - '0';
140 } else if (ch <= 'f' && ch >= 'a') { 140 } else if (ch <= 'f' && ch >= 'a') {
141 digit = ch - 'a' + 10; 141 digit = ch - 'a' + 10;
142 } else if (ch <= 'F' && ch >= 'A') { 142 } else if (ch <= 'F' && ch >= 'A') {
143 digit = ch - 'A' + 10; 143 digit = ch - 'A' + 10;
144 } else if (ch == '>') { 144 } else if (ch == '>') {
145 i++; 145 i++;
146 break; 146 break;
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 FX_DWORD src_size, 573 FX_DWORD src_size,
574 uint8_t*& dest_buf, 574 uint8_t*& dest_buf,
575 FX_DWORD& dest_size) { 575 FX_DWORD& dest_size) {
576 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); 576 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule();
577 if (pEncoders) { 577 if (pEncoders) {
578 return pEncoders->GetFlateModule()->FlateOrLZWDecode( 578 return pEncoders->GetFlateModule()->FlateOrLZWDecode(
579 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); 579 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size);
580 } 580 }
581 return 0; 581 return 0;
582 } 582 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698