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

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: rebase 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
« no previous file with comments | « core/src/fpdfdoc/doc_ap.cpp ('k') | core/src/fpdfdoc/doc_form.cpp » ('j') | 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 "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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 } else if (bsStyle == "A") { 461 } else if (bsStyle == "A") {
462 wsNumPortion = _MakeLetters(num); 462 wsNumPortion = _MakeLetters(num);
463 wsNumPortion.MakeUpper(); 463 wsNumPortion.MakeUpper();
464 } else if (bsStyle == "a") { 464 } else if (bsStyle == "a") {
465 wsNumPortion = _MakeLetters(num); 465 wsNumPortion = _MakeLetters(num);
466 } 466 }
467 return wsNumPortion; 467 return wsNumPortion;
468 } 468 }
469 CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const { 469 CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const {
470 CFX_WideString wsLabel; 470 CFX_WideString wsLabel;
471 if (m_pDocument == NULL) { 471 if (!m_pDocument) {
472 return wsLabel; 472 return wsLabel;
473 } 473 }
474 CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot(); 474 CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot();
475 if (pPDFRoot == NULL) { 475 if (!pPDFRoot) {
476 return wsLabel; 476 return wsLabel;
477 } 477 }
478 CPDF_Dictionary* pLabels = pPDFRoot->GetDict("PageLabels"); 478 CPDF_Dictionary* pLabels = pPDFRoot->GetDict("PageLabels");
479 CPDF_NumberTree numberTree(pLabels); 479 CPDF_NumberTree numberTree(pLabels);
480 CPDF_Object* pValue = NULL; 480 CPDF_Object* pValue = NULL;
481 int n = nPage; 481 int n = nPage;
482 while (n >= 0) { 482 while (n >= 0) {
483 pValue = numberTree.LookupValue(n); 483 pValue = numberTree.LookupValue(n);
484 if (pValue) { 484 if (pValue) {
485 break; 485 break;
(...skipping 11 matching lines...) Expand all
497 CFX_WideString wsNumPortion = 497 CFX_WideString wsNumPortion =
498 _GetLabelNumPortion(nLabelNum, bsNumberingStyle); 498 _GetLabelNumPortion(nLabelNum, bsNumberingStyle);
499 wsLabel += wsNumPortion; 499 wsLabel += wsNumPortion;
500 return wsLabel; 500 return wsLabel;
501 } 501 }
502 } 502 }
503 wsLabel.Format(L"%d", nPage + 1); 503 wsLabel.Format(L"%d", nPage + 1);
504 return wsLabel; 504 return wsLabel;
505 } 505 }
506 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_ByteStringC& bsLabel) const { 506 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_ByteStringC& bsLabel) const {
507 if (m_pDocument == NULL) { 507 if (!m_pDocument) {
508 return -1; 508 return -1;
509 } 509 }
510 CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot(); 510 CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot();
511 if (pPDFRoot == NULL) { 511 if (!pPDFRoot) {
512 return -1; 512 return -1;
513 } 513 }
514 int nPages = m_pDocument->GetPageCount(); 514 int nPages = m_pDocument->GetPageCount();
515 CFX_ByteString bsLbl; 515 CFX_ByteString bsLbl;
516 CFX_ByteString bsOrig = bsLabel; 516 CFX_ByteString bsOrig = bsLabel;
517 for (int i = 0; i < nPages; i++) { 517 for (int i = 0; i < nPages; i++) {
518 bsLbl = PDF_EncodeText(GetLabel(i)); 518 bsLbl = PDF_EncodeText(GetLabel(i));
519 if (!bsLbl.Compare(bsOrig)) { 519 if (!bsLbl.Compare(bsOrig)) {
520 return i; 520 return i;
521 } 521 }
522 } 522 }
523 bsLbl = bsOrig; 523 bsLbl = bsOrig;
524 int nPage = FXSYS_atoi(bsLbl); 524 int nPage = FXSYS_atoi(bsLbl);
525 if (nPage > 0 && nPage <= nPages) { 525 if (nPage > 0 && nPage <= nPages) {
526 return nPage; 526 return nPage;
527 } 527 }
528 return -1; 528 return -1;
529 } 529 }
530 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const { 530 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const {
531 CFX_ByteString bsLabel = PDF_EncodeText(wsLabel.GetPtr()); 531 CFX_ByteString bsLabel = PDF_EncodeText(wsLabel.GetPtr());
532 return GetPageByLabel(bsLabel); 532 return GetPageByLabel(bsLabel);
533 } 533 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_ap.cpp ('k') | core/src/fpdfdoc/doc_form.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698