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

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

Issue 1252613002: FX_BOOL considered harmful. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Manual edits. Created 5 years, 5 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
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 const char PDF_CharType[256] = { 8 const char PDF_CharType[256] = {
9 //NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO S I 9 //NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO S I
10 'W', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'W', 'W', 'R', 'W', 'W', 'R', ' R', 10 'W', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'W', 'W', 'R', 'W', 'W', 'R', ' R',
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 187 }
188 m_dwCurPos ++; 188 m_dwCurPos ++;
189 } 189 }
190 if (m_dwCurPos < m_dwSize) { 190 if (m_dwCurPos < m_dwSize) {
191 m_dwCurPos ++; 191 m_dwCurPos ++;
192 } 192 }
193 return CFX_ByteStringC(pStart, (FX_STRSIZE)(m_dwCurPos - (pStart - m_pDa ta))); 193 return CFX_ByteStringC(pStart, (FX_STRSIZE)(m_dwCurPos - (pStart - m_pDa ta)));
194 } 194 }
195 return CFX_ByteStringC(pStart, dwSize); 195 return CFX_ByteStringC(pStart, dwSize);
196 } 196 }
197 FX_BOOL CPDF_SimpleParser::SearchToken(const CFX_ByteStringC& token) 197 bool CPDF_SimpleParser::SearchToken(const CFX_ByteStringC& token)
198 { 198 {
199 int token_len = token.GetLength(); 199 int token_len = token.GetLength();
200 while (m_dwCurPos < m_dwSize - token_len) { 200 while (m_dwCurPos < m_dwSize - token_len) {
201 if (FXSYS_memcmp(m_pData + m_dwCurPos, token.GetPtr(), token_len) == 0) { 201 if (FXSYS_memcmp(m_pData + m_dwCurPos, token.GetPtr(), token_len) == 0) {
202 break; 202 break;
203 } 203 }
204 m_dwCurPos ++; 204 m_dwCurPos ++;
205 } 205 }
206 if (m_dwCurPos == m_dwSize - token_len) { 206 if (m_dwCurPos == m_dwSize - token_len) {
207 return FALSE; 207 return false;
208 } 208 }
209 m_dwCurPos += token_len; 209 m_dwCurPos += token_len;
210 return TRUE; 210 return true;
211 } 211 }
212 FX_BOOL CPDF_SimpleParser::SkipWord(const CFX_ByteStringC& token) 212 bool CPDF_SimpleParser::SkipWord(const CFX_ByteStringC& token)
213 { 213 {
214 while (1) { 214 while (1) {
215 CFX_ByteStringC word = GetWord(); 215 CFX_ByteStringC word = GetWord();
216 if (word.IsEmpty()) { 216 if (word.IsEmpty()) {
217 return FALSE; 217 return false;
218 } 218 }
219 if (word == token) { 219 if (word == token) {
220 return TRUE; 220 return true;
221 } 221 }
222 } 222 }
223 return FALSE; 223 return false;
224 } 224 }
225 FX_BOOL CPDF_SimpleParser::FindTagPair(const CFX_ByteStringC& start_token, const CFX_ByteStringC& end_token, 225 bool CPDF_SimpleParser::FindTagPair(const CFX_ByteStringC& start_token, const CF X_ByteStringC& end_token,
226 FX_DWORD& start_pos, FX_DWORD& end_pos) 226 FX_DWORD& start_pos, FX_DWORD& end_pos)
227 { 227 {
228 if (!start_token.IsEmpty()) { 228 if (!start_token.IsEmpty()) {
229 if (!SkipWord(start_token)) { 229 if (!SkipWord(start_token)) {
230 return FALSE; 230 return false;
231 } 231 }
232 start_pos = m_dwCurPos; 232 start_pos = m_dwCurPos;
233 } 233 }
234 while (1) { 234 while (1) {
235 end_pos = m_dwCurPos; 235 end_pos = m_dwCurPos;
236 CFX_ByteStringC word = GetWord(); 236 CFX_ByteStringC word = GetWord();
237 if (word.IsEmpty()) { 237 if (word.IsEmpty()) {
238 return FALSE; 238 return false;
239 } 239 }
240 if (word == end_token) { 240 if (word == end_token) {
241 return TRUE; 241 return true;
242 } 242 }
243 } 243 }
244 return FALSE; 244 return false;
245 } 245 }
246 FX_BOOL CPDF_SimpleParser::FindTagParam(const CFX_ByteStringC& token, int nParam s) 246 bool CPDF_SimpleParser::FindTagParam(const CFX_ByteStringC& token, int nParams)
247 { 247 {
248 nParams ++; 248 nParams ++;
249 FX_DWORD* pBuf = FX_Alloc(FX_DWORD, nParams); 249 FX_DWORD* pBuf = FX_Alloc(FX_DWORD, nParams);
250 int buf_index = 0; 250 int buf_index = 0;
251 int buf_count = 0; 251 int buf_count = 0;
252 while (1) { 252 while (1) {
253 pBuf[buf_index++] = m_dwCurPos; 253 pBuf[buf_index++] = m_dwCurPos;
254 if (buf_index == nParams) { 254 if (buf_index == nParams) {
255 buf_index = 0; 255 buf_index = 0;
256 } 256 }
257 buf_count ++; 257 buf_count ++;
258 if (buf_count > nParams) { 258 if (buf_count > nParams) {
259 buf_count = nParams; 259 buf_count = nParams;
260 } 260 }
261 CFX_ByteStringC word = GetWord(); 261 CFX_ByteStringC word = GetWord();
262 if (word.IsEmpty()) { 262 if (word.IsEmpty()) {
263 FX_Free(pBuf); 263 FX_Free(pBuf);
264 return FALSE; 264 return false;
265 } 265 }
266 if (word == token) { 266 if (word == token) {
267 if (buf_count < nParams) { 267 if (buf_count < nParams) {
268 continue; 268 continue;
269 } 269 }
270 m_dwCurPos = pBuf[buf_index]; 270 m_dwCurPos = pBuf[buf_index];
271 FX_Free(pBuf); 271 FX_Free(pBuf);
272 return TRUE; 272 return true;
273 } 273 }
274 } 274 }
275 return FALSE; 275 return false;
276 } 276 }
277 static int _hex2dec(char ch) 277 static int _hex2dec(char ch)
278 { 278 {
279 if (ch >= '0' && ch <= '9') { 279 if (ch >= '0' && ch <= '9') {
280 return ch - '0'; 280 return ch - '0';
281 } 281 }
282 if (ch >= 'a' && ch <= 'f') { 282 if (ch >= 'a' && ch <= 'f') {
283 return ch - 'a' + 10; 283 return ch - 'a' + 10;
284 } 284 }
285 if (ch >= 'A' && ch <= 'F') { 285 if (ch >= 'A' && ch <= 'F') {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 switch (pObj->GetType()) { 360 switch (pObj->GetType()) {
361 case PDFOBJ_NULL: 361 case PDFOBJ_NULL:
362 buf << FX_BSTRC(" null"); 362 buf << FX_BSTRC(" null");
363 break; 363 break;
364 case PDFOBJ_BOOLEAN: 364 case PDFOBJ_BOOLEAN:
365 case PDFOBJ_NUMBER: 365 case PDFOBJ_NUMBER:
366 buf << " " << pObj->GetString(); 366 buf << " " << pObj->GetString();
367 break; 367 break;
368 case PDFOBJ_STRING: { 368 case PDFOBJ_STRING: {
369 CFX_ByteString str = pObj->GetString(); 369 CFX_ByteString str = pObj->GetString();
370 FX_BOOL bHex = ((CPDF_String*)pObj)->IsHex(); 370 bool bHex = ((CPDF_String*)pObj)->IsHex();
371 buf << PDF_EncodeString(str, bHex); 371 buf << PDF_EncodeString(str, bHex);
372 break; 372 break;
373 } 373 }
374 case PDFOBJ_NAME: { 374 case PDFOBJ_NAME: {
375 CFX_ByteString str = pObj->GetString(); 375 CFX_ByteString str = pObj->GetString();
376 buf << FX_BSTRC("/") << PDF_NameEncode(str); 376 buf << FX_BSTRC("/") << PDF_NameEncode(str);
377 break; 377 break;
378 } 378 }
379 case PDFOBJ_REFERENCE: { 379 case PDFOBJ_REFERENCE: {
380 CPDF_Reference* p = (CPDF_Reference*)pObj; 380 CPDF_Reference* p = (CPDF_Reference*)pObj;
(...skipping 28 matching lines...) Expand all
409 buf << pValue; 409 buf << pValue;
410 } 410 }
411 } 411 }
412 buf << FX_BSTRC(">>"); 412 buf << FX_BSTRC(">>");
413 break; 413 break;
414 } 414 }
415 case PDFOBJ_STREAM: { 415 case PDFOBJ_STREAM: {
416 CPDF_Stream* p = (CPDF_Stream*)pObj; 416 CPDF_Stream* p = (CPDF_Stream*)pObj;
417 buf << p->GetDict() << FX_BSTRC("stream\r\n"); 417 buf << p->GetDict() << FX_BSTRC("stream\r\n");
418 CPDF_StreamAcc acc; 418 CPDF_StreamAcc acc;
419 acc.LoadAllData(p, TRUE); 419 acc.LoadAllData(p, true);
420 buf.AppendBlock(acc.GetData(), acc.GetSize()); 420 buf.AppendBlock(acc.GetData(), acc.GetSize());
421 buf << FX_BSTRC("\r\nendstream"); 421 buf << FX_BSTRC("\r\nendstream");
422 break; 422 break;
423 } 423 }
424 default: 424 default:
425 ASSERT(FALSE); 425 ASSERT(false);
426 break; 426 break;
427 } 427 }
428 return buf; 428 return buf;
429 } 429 }
430 FX_FLOAT PDF_ClipFloat(FX_FLOAT f) 430 FX_FLOAT PDF_ClipFloat(FX_FLOAT f)
431 { 431 {
432 if (f < 0) { 432 if (f < 0) {
433 return 0; 433 return 0;
434 } 434 }
435 if (f > 1.0f) { 435 if (f > 1.0f) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 if (pFound) { 470 if (pFound) {
471 return pFound; 471 return pFound;
472 } 472 }
473 } 473 }
474 return NULL; 474 return NULL;
475 } 475 }
476 CPDF_Object* CPDF_NumberTree::LookupValue(int num) 476 CPDF_Object* CPDF_NumberTree::LookupValue(int num)
477 { 477 {
478 return SearchNumberNode(m_pRoot, num); 478 return SearchNumberNode(m_pRoot, num);
479 } 479 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp ('k') | core/src/fpdfapi/fpdf_render/fpdf_render.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698