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

Side by Side Diff: core/src/fpdfdoc/doc_basic.cpp

Issue 1520063002: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bstr_isnull
Patch Set: Created 5 years 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 "core/include/fpdfdoc/fpdf_doc.h" 7 #include "core/include/fpdfdoc/fpdf_doc.h"
8 8
9 const int nMaxRecursion = 32; 9 const int nMaxRecursion = 32;
10 int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) { 10 int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } else { 105 } else {
106 break; 106 break;
107 } 107 }
108 nIndex += i; 108 nIndex += i;
109 return pNames->GetElementValue(i * 2 + 1); 109 return pNames->GetElementValue(i * 2 + 1);
110 } 110 }
111 nIndex += dwCount; 111 nIndex += dwCount;
112 return NULL; 112 return NULL;
113 } 113 }
114 CPDF_Array* pKids = pNode->GetArray("Kids"); 114 CPDF_Array* pKids = pNode->GetArray("Kids");
115 if (pKids == NULL) { 115 if (!pKids) {
116 return NULL; 116 return NULL;
117 } 117 }
118 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { 118 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) {
119 CPDF_Dictionary* pKid = pKids->GetDict(i); 119 CPDF_Dictionary* pKid = pKids->GetDict(i);
120 if (pKid == NULL) { 120 if (!pKid) {
121 continue; 121 continue;
122 } 122 }
123 CPDF_Object* pFound = 123 CPDF_Object* pFound =
124 SearchNameNode(pKid, csName, nIndex, ppFind, nLevel + 1); 124 SearchNameNode(pKid, csName, nIndex, ppFind, nLevel + 1);
125 if (pFound) { 125 if (pFound) {
126 return pFound; 126 return pFound;
127 } 127 }
128 } 128 }
129 return NULL; 129 return NULL;
130 } 130 }
(...skipping 13 matching lines...) Expand all
144 nCurIndex += nCount; 144 nCurIndex += nCount;
145 return NULL; 145 return NULL;
146 } 146 }
147 if (ppFind) { 147 if (ppFind) {
148 *ppFind = pNames; 148 *ppFind = pNames;
149 } 149 }
150 csName = pNames->GetString((nIndex - nCurIndex) * 2); 150 csName = pNames->GetString((nIndex - nCurIndex) * 2);
151 return pNames->GetElementValue((nIndex - nCurIndex) * 2 + 1); 151 return pNames->GetElementValue((nIndex - nCurIndex) * 2 + 1);
152 } 152 }
153 CPDF_Array* pKids = pNode->GetArray("Kids"); 153 CPDF_Array* pKids = pNode->GetArray("Kids");
154 if (pKids == NULL) { 154 if (!pKids) {
155 return NULL; 155 return NULL;
156 } 156 }
157 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { 157 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) {
158 CPDF_Dictionary* pKid = pKids->GetDict(i); 158 CPDF_Dictionary* pKid = pKids->GetDict(i);
159 if (pKid == NULL) { 159 if (!pKid) {
160 continue; 160 continue;
161 } 161 }
162 CPDF_Object* pFound = 162 CPDF_Object* pFound =
163 SearchNameNode(pKid, nIndex, nCurIndex, csName, ppFind, nLevel + 1); 163 SearchNameNode(pKid, nIndex, nCurIndex, csName, ppFind, nLevel + 1);
164 if (pFound) { 164 if (pFound) {
165 return pFound; 165 return pFound;
166 } 166 }
167 } 167 }
168 return NULL; 168 return NULL;
169 } 169 }
170 static int CountNames(CPDF_Dictionary* pNode, int nLevel = 0) { 170 static int CountNames(CPDF_Dictionary* pNode, int nLevel = 0) {
171 if (nLevel > nMaxRecursion) { 171 if (nLevel > nMaxRecursion) {
172 return 0; 172 return 0;
173 } 173 }
174 CPDF_Array* pNames = pNode->GetArray("Names"); 174 CPDF_Array* pNames = pNode->GetArray("Names");
175 if (pNames) { 175 if (pNames) {
176 return pNames->GetCount() / 2; 176 return pNames->GetCount() / 2;
177 } 177 }
178 CPDF_Array* pKids = pNode->GetArray("Kids"); 178 CPDF_Array* pKids = pNode->GetArray("Kids");
179 if (pKids == NULL) { 179 if (!pKids) {
180 return 0; 180 return 0;
181 } 181 }
182 int nCount = 0; 182 int nCount = 0;
183 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { 183 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) {
184 CPDF_Dictionary* pKid = pKids->GetDict(i); 184 CPDF_Dictionary* pKid = pKids->GetDict(i);
185 if (pKid == NULL) { 185 if (!pKid) {
186 continue; 186 continue;
187 } 187 }
188 nCount += CountNames(pKid, nLevel + 1); 188 nCount += CountNames(pKid, nLevel + 1);
189 } 189 }
190 return nCount; 190 return nCount;
191 } 191 }
192 int CPDF_NameTree::GetCount() const { 192 int CPDF_NameTree::GetCount() const {
193 if (m_pRoot == NULL) { 193 if (!m_pRoot) {
194 return 0; 194 return 0;
195 } 195 }
196 return ::CountNames(m_pRoot); 196 return ::CountNames(m_pRoot);
197 } 197 }
198 int CPDF_NameTree::GetIndex(const CFX_ByteString& csName) const { 198 int CPDF_NameTree::GetIndex(const CFX_ByteString& csName) const {
199 if (m_pRoot == NULL) { 199 if (!m_pRoot) {
200 return -1; 200 return -1;
201 } 201 }
202 int nIndex = 0; 202 int nIndex = 0;
203 if (SearchNameNode(m_pRoot, csName, nIndex, NULL) == NULL) { 203 if (!SearchNameNode(m_pRoot, csName, nIndex, NULL)) {
204 return -1; 204 return -1;
205 } 205 }
206 return nIndex; 206 return nIndex;
207 } 207 }
208 CPDF_Object* CPDF_NameTree::LookupValue(int nIndex, 208 CPDF_Object* CPDF_NameTree::LookupValue(int nIndex,
209 CFX_ByteString& csName) const { 209 CFX_ByteString& csName) const {
210 if (m_pRoot == NULL) { 210 if (!m_pRoot) {
211 return NULL; 211 return NULL;
212 } 212 }
213 int nCurIndex = 0; 213 int nCurIndex = 0;
214 return SearchNameNode(m_pRoot, nIndex, nCurIndex, csName, NULL); 214 return SearchNameNode(m_pRoot, nIndex, nCurIndex, csName, NULL);
215 } 215 }
216 CPDF_Object* CPDF_NameTree::LookupValue(const CFX_ByteString& csName) const { 216 CPDF_Object* CPDF_NameTree::LookupValue(const CFX_ByteString& csName) const {
217 if (m_pRoot == NULL) { 217 if (!m_pRoot) {
218 return NULL; 218 return NULL;
219 } 219 }
220 int nIndex = 0; 220 int nIndex = 0;
221 return SearchNameNode(m_pRoot, csName, nIndex, NULL); 221 return SearchNameNode(m_pRoot, csName, nIndex, NULL);
222 } 222 }
223 CPDF_Array* CPDF_NameTree::LookupNamedDest(CPDF_Document* pDoc, 223 CPDF_Array* CPDF_NameTree::LookupNamedDest(CPDF_Document* pDoc,
224 const CFX_ByteStringC& sName) { 224 const CFX_ByteStringC& sName) {
225 CPDF_Object* pValue = LookupValue(sName); 225 CPDF_Object* pValue = LookupValue(sName);
226 if (!pValue) { 226 if (!pValue) {
227 CPDF_Dictionary* pDests = pDoc->GetRoot()->GetDict("Dests"); 227 CPDF_Dictionary* pDests = pDoc->GetRoot()->GetDict("Dests");
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 } else if (bsStyle == "A") { 463 } else if (bsStyle == "A") {
464 wsNumPortion = _MakeLetters(num); 464 wsNumPortion = _MakeLetters(num);
465 wsNumPortion.MakeUpper(); 465 wsNumPortion.MakeUpper();
466 } else if (bsStyle == "a") { 466 } else if (bsStyle == "a") {
467 wsNumPortion = _MakeLetters(num); 467 wsNumPortion = _MakeLetters(num);
468 } 468 }
469 return wsNumPortion; 469 return wsNumPortion;
470 } 470 }
471 CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const { 471 CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const {
472 CFX_WideString wsLabel; 472 CFX_WideString wsLabel;
473 if (m_pDocument == NULL) { 473 if (!m_pDocument) {
474 return wsLabel; 474 return wsLabel;
475 } 475 }
476 CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot(); 476 CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot();
477 if (pPDFRoot == NULL) { 477 if (!pPDFRoot) {
478 return wsLabel; 478 return wsLabel;
479 } 479 }
480 CPDF_Dictionary* pLabels = pPDFRoot->GetDict("PageLabels"); 480 CPDF_Dictionary* pLabels = pPDFRoot->GetDict("PageLabels");
481 CPDF_NumberTree numberTree(pLabels); 481 CPDF_NumberTree numberTree(pLabels);
482 CPDF_Object* pValue = NULL; 482 CPDF_Object* pValue = NULL;
483 int n = nPage; 483 int n = nPage;
484 while (n >= 0) { 484 while (n >= 0) {
485 pValue = numberTree.LookupValue(n); 485 pValue = numberTree.LookupValue(n);
486 if (pValue) { 486 if (pValue) {
487 break; 487 break;
(...skipping 11 matching lines...) Expand all
499 CFX_WideString wsNumPortion = 499 CFX_WideString wsNumPortion =
500 _GetLabelNumPortion(nLabelNum, bsNumberingStyle); 500 _GetLabelNumPortion(nLabelNum, bsNumberingStyle);
501 wsLabel += wsNumPortion; 501 wsLabel += wsNumPortion;
502 return wsLabel; 502 return wsLabel;
503 } 503 }
504 } 504 }
505 wsLabel.Format(L"%d", nPage + 1); 505 wsLabel.Format(L"%d", nPage + 1);
506 return wsLabel; 506 return wsLabel;
507 } 507 }
508 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_ByteStringC& bsLabel) const { 508 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_ByteStringC& bsLabel) const {
509 if (m_pDocument == NULL) { 509 if (!m_pDocument) {
510 return -1; 510 return -1;
511 } 511 }
512 CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot(); 512 CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot();
513 if (pPDFRoot == NULL) { 513 if (!pPDFRoot) {
514 return -1; 514 return -1;
515 } 515 }
516 int nPages = m_pDocument->GetPageCount(); 516 int nPages = m_pDocument->GetPageCount();
517 CFX_ByteString bsLbl; 517 CFX_ByteString bsLbl;
518 CFX_ByteString bsOrig = bsLabel; 518 CFX_ByteString bsOrig = bsLabel;
519 for (int i = 0; i < nPages; i++) { 519 for (int i = 0; i < nPages; i++) {
520 bsLbl = PDF_EncodeText(GetLabel(i)); 520 bsLbl = PDF_EncodeText(GetLabel(i));
521 if (!bsLbl.Compare(bsOrig)) { 521 if (!bsLbl.Compare(bsOrig)) {
522 return i; 522 return i;
523 } 523 }
524 } 524 }
525 bsLbl = bsOrig; 525 bsLbl = bsOrig;
526 int nPage = FXSYS_atoi(bsLbl); 526 int nPage = FXSYS_atoi(bsLbl);
527 if (nPage > 0 && nPage <= nPages) { 527 if (nPage > 0 && nPage <= nPages) {
528 return nPage; 528 return nPage;
529 } 529 }
530 return -1; 530 return -1;
531 } 531 }
532 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const { 532 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const {
533 CFX_ByteString bsLabel = PDF_EncodeText(wsLabel.GetPtr()); 533 CFX_ByteString bsLabel = PDF_EncodeText(wsLabel.GetPtr());
534 return GetPageByLabel(bsLabel); 534 return GetPageByLabel(bsLabel);
535 } 535 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698