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

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

Issue 880663003: Kill scattered extern _PDF_CharType declarations. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Fix typo in 'N' in fpdf_parser.h comment. Created 5 years, 10 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
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp ('k') | no next file » | 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 extern const FX_LPCSTR _PDF_CharType = 8 const char PDF_CharType[256] = {
9 "WRRRRRRRRWWRWWRRRRRRRRRRRRRRRRRR" 9 //NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO S I
10 "WRRRRDRRDDRNRNNDNNNNNNNNNNRRDRDR" 10 'W', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'W', 'W', 'R', 'W', 'W', 'R', ' R',
11 "RRRRRRRRRRRRRRRRRRRRRRRRRRRDRDRR" 11
12 "RRRRRRRRRRRRRRRRRRRRRRRRRRRDRDRR" 12 //DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS U S
13 "WRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR" 13 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', ' R',
14 "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR" 14
15 "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR" 15 //SP ! " # $ % & ยด ( ) * + , - . /
16 "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRW"; 16 'W', 'R', 'R', 'R', 'R', 'D', 'R', 'R', 'D', 'D', 'R', 'N', 'R', 'N', 'N', ' D',
17
18 // 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
19 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'R', 'R', 'D', 'R', 'D', ' R',
20
21 // @ A B C D E F G H I J K L M N O
22 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', ' R',
23
24 // P Q R S T U V W X Y Z [ \ ] ^ _
25 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'D', 'R', 'D', 'R', ' R',
26
27 // ` a b c d e f g h i j k l m n o
28 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', ' R',
29
30 // p q r s t u v w x y z { | } ~ D EL
31 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'D', 'R', 'D', 'R', ' R',
32
33 'W', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', ' R',
34 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', ' R',
35 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', ' R',
36 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', ' R',
37 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', ' R',
38 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', ' R',
39 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', ' R',
40 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', ' W'
41 };
42
17 #ifndef MAX_PATH 43 #ifndef MAX_PATH
18 #define MAX_PATH 4096 44 #define MAX_PATH 4096
19 #endif 45 #endif
20 CPDF_SimpleParser::CPDF_SimpleParser(FX_LPCBYTE pData, FX_DWORD dwSize) 46 CPDF_SimpleParser::CPDF_SimpleParser(FX_LPCBYTE pData, FX_DWORD dwSize)
21 { 47 {
22 m_pData = pData; 48 m_pData = pData;
23 m_dwSize = dwSize; 49 m_dwSize = dwSize;
24 m_dwCurPos = 0; 50 m_dwCurPos = 0;
25 } 51 }
26 CPDF_SimpleParser::CPDF_SimpleParser(FX_BSTR str) 52 CPDF_SimpleParser::CPDF_SimpleParser(FX_BSTR str)
27 { 53 {
28 m_pData = str; 54 m_pData = str;
29 m_dwSize = str.GetLength(); 55 m_dwSize = str.GetLength();
30 m_dwCurPos = 0; 56 m_dwCurPos = 0;
31 } 57 }
32 void CPDF_SimpleParser::ParseWord(FX_LPCBYTE& pStart, FX_DWORD& dwSize, int& typ e) 58 void CPDF_SimpleParser::ParseWord(FX_LPCBYTE& pStart, FX_DWORD& dwSize, int& typ e)
33 { 59 {
34 pStart = NULL; 60 pStart = NULL;
35 dwSize = 0; 61 dwSize = 0;
36 type = PDFWORD_EOF; 62 type = PDFWORD_EOF;
37 FX_BYTE ch; 63 FX_BYTE ch;
38 char chartype; 64 char chartype;
39 while (1) { 65 while (1) {
40 if (m_dwSize <= m_dwCurPos) { 66 if (m_dwSize <= m_dwCurPos) {
41 return; 67 return;
42 } 68 }
43 ch = m_pData[m_dwCurPos++]; 69 ch = m_pData[m_dwCurPos++];
44 chartype = _PDF_CharType[ch]; 70 chartype = PDF_CharType[ch];
45 while (chartype == 'W') { 71 while (chartype == 'W') {
46 if (m_dwSize <= m_dwCurPos) { 72 if (m_dwSize <= m_dwCurPos) {
47 return; 73 return;
48 } 74 }
49 ch = m_pData[m_dwCurPos++]; 75 ch = m_pData[m_dwCurPos++];
50 chartype = _PDF_CharType[ch]; 76 chartype = PDF_CharType[ch];
51 } 77 }
52 if (ch != '%') { 78 if (ch != '%') {
53 break; 79 break;
54 } 80 }
55 while (1) { 81 while (1) {
56 if (m_dwSize <= m_dwCurPos) { 82 if (m_dwSize <= m_dwCurPos) {
57 return; 83 return;
58 } 84 }
59 ch = m_pData[m_dwCurPos++]; 85 ch = m_pData[m_dwCurPos++];
60 if (ch == '\r' || ch == '\n') { 86 if (ch == '\r' || ch == '\n') {
61 break; 87 break;
62 } 88 }
63 } 89 }
64 chartype = _PDF_CharType[ch]; 90 chartype = PDF_CharType[ch];
65 } 91 }
66 FX_DWORD start_pos = m_dwCurPos - 1; 92 FX_DWORD start_pos = m_dwCurPos - 1;
67 pStart = m_pData + start_pos; 93 pStart = m_pData + start_pos;
68 if (chartype == 'D') { 94 if (chartype == 'D') {
69 if (ch == '/') { 95 if (ch == '/') {
70 while (1) { 96 while (1) {
71 if (m_dwSize <= m_dwCurPos) { 97 if (m_dwSize <= m_dwCurPos) {
72 return; 98 return;
73 } 99 }
74 ch = m_pData[m_dwCurPos++]; 100 ch = m_pData[m_dwCurPos++];
75 chartype = _PDF_CharType[ch]; 101 chartype = PDF_CharType[ch];
76 if (chartype != 'R' && chartype != 'N') { 102 if (chartype != 'R' && chartype != 'N') {
77 m_dwCurPos --; 103 m_dwCurPos --;
78 dwSize = m_dwCurPos - start_pos; 104 dwSize = m_dwCurPos - start_pos;
79 type = PDFWORD_NAME; 105 type = PDFWORD_NAME;
80 return; 106 return;
81 } 107 }
82 } 108 }
83 } else { 109 } else {
84 type = PDFWORD_DELIMITER; 110 type = PDFWORD_DELIMITER;
85 dwSize = 1; 111 dwSize = 1;
(...skipping 24 matching lines...) Expand all
110 type = PDFWORD_NUMBER; 136 type = PDFWORD_NUMBER;
111 dwSize = 1; 137 dwSize = 1;
112 while (1) { 138 while (1) {
113 if (chartype != 'N') { 139 if (chartype != 'N') {
114 type = PDFWORD_TEXT; 140 type = PDFWORD_TEXT;
115 } 141 }
116 if (m_dwSize <= m_dwCurPos) { 142 if (m_dwSize <= m_dwCurPos) {
117 return; 143 return;
118 } 144 }
119 ch = m_pData[m_dwCurPos++]; 145 ch = m_pData[m_dwCurPos++];
120 chartype = _PDF_CharType[ch]; 146 chartype = PDF_CharType[ch];
121 if (chartype == 'D' || chartype == 'W') { 147 if (chartype == 'D' || chartype == 'W') {
122 m_dwCurPos --; 148 m_dwCurPos --;
123 break; 149 break;
124 } 150 }
125 dwSize ++; 151 dwSize ++;
126 } 152 }
127 } 153 }
128 CFX_ByteStringC CPDF_SimpleParser::GetWord() 154 CFX_ByteStringC CPDF_SimpleParser::GetWord()
129 { 155 {
130 FX_LPCBYTE pStart; 156 FX_LPCBYTE pStart;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 return PDF_NameDecode(CFX_ByteStringC(orig)); 316 return PDF_NameDecode(CFX_ByteStringC(orig));
291 } 317 }
292 CFX_ByteString PDF_NameEncode(const CFX_ByteString& orig) 318 CFX_ByteString PDF_NameEncode(const CFX_ByteString& orig)
293 { 319 {
294 FX_LPBYTE src_buf = (FX_LPBYTE)orig.c_str(); 320 FX_LPBYTE src_buf = (FX_LPBYTE)orig.c_str();
295 int src_len = orig.GetLength(); 321 int src_len = orig.GetLength();
296 int dest_len = 0; 322 int dest_len = 0;
297 int i; 323 int i;
298 for (i = 0; i < src_len; i ++) { 324 for (i = 0; i < src_len; i ++) {
299 FX_BYTE ch = src_buf[i]; 325 FX_BYTE ch = src_buf[i];
300 if (ch >= 0x80 || _PDF_CharType[ch] == 'W' || ch == '#' || 326 if (ch >= 0x80 || PDF_CharType[ch] == 'W' || ch == '#' ||
301 _PDF_CharType[ch] == 'D') { 327 PDF_CharType[ch] == 'D') {
302 dest_len += 3; 328 dest_len += 3;
303 } else { 329 } else {
304 dest_len ++; 330 dest_len ++;
305 } 331 }
306 } 332 }
307 if (dest_len == src_len) { 333 if (dest_len == src_len) {
308 return orig; 334 return orig;
309 } 335 }
310 CFX_ByteString res; 336 CFX_ByteString res;
311 FX_LPSTR dest_buf = res.GetBuffer(dest_len); 337 FX_LPSTR dest_buf = res.GetBuffer(dest_len);
312 dest_len = 0; 338 dest_len = 0;
313 for (i = 0; i < src_len; i ++) { 339 for (i = 0; i < src_len; i ++) {
314 FX_BYTE ch = src_buf[i]; 340 FX_BYTE ch = src_buf[i];
315 if (ch >= 0x80 || _PDF_CharType[ch] == 'W' || ch == '#' || 341 if (ch >= 0x80 || PDF_CharType[ch] == 'W' || ch == '#' ||
316 _PDF_CharType[ch] == 'D') { 342 PDF_CharType[ch] == 'D') {
317 dest_buf[dest_len++] = '#'; 343 dest_buf[dest_len++] = '#';
318 dest_buf[dest_len++] = "0123456789ABCDEF"[ch / 16]; 344 dest_buf[dest_len++] = "0123456789ABCDEF"[ch / 16];
319 dest_buf[dest_len++] = "0123456789ABCDEF"[ch % 16]; 345 dest_buf[dest_len++] = "0123456789ABCDEF"[ch % 16];
320 } else { 346 } else {
321 dest_buf[dest_len++] = ch; 347 dest_buf[dest_len++] = ch;
322 } 348 }
323 } 349 }
324 dest_buf[dest_len] = 0; 350 dest_buf[dest_len] = 0;
325 res.ReleaseBuffer(); 351 res.ReleaseBuffer();
326 return res; 352 return res;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 if (pFound) { 470 if (pFound) {
445 return pFound; 471 return pFound;
446 } 472 }
447 } 473 }
448 return NULL; 474 return NULL;
449 } 475 }
450 CPDF_Object* CPDF_NumberTree::LookupValue(int num) 476 CPDF_Object* CPDF_NumberTree::LookupValue(int num)
451 { 477 {
452 return SearchNumberNode(m_pRoot, num); 478 return SearchNumberNode(m_pRoot, num);
453 } 479 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698