summaryrefslogtreecommitdiff
path: root/core/fpdfdoc/doc_basic.cpp
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-05-13 17:51:27 -0700
committerCommit bot <commit-bot@chromium.org>2016-05-13 17:51:27 -0700
commit71a452f8ce12e31cc4e0d8c7878567b0c7fc63c2 (patch)
treea0ee545eb67b14f9398df98196d88e5150893ce8 /core/fpdfdoc/doc_basic.cpp
parentafe94306e3c542f0d499e7f7706ee5dec4028d8a (diff)
downloadpdfium-71a452f8ce12e31cc4e0d8c7878567b0c7fc63c2.tar.xz
Make CFX_ByteString(const CFX_ByteStringC&) explicit.
Add missing helper function to CFX_ByteTextBuf to avoid the anti-pattern CFX_ByteString(sBuf.AsStringC()), using the name "Make" to indicate there's an allocation going on in this case. Change some method arguments to take pre-existing ByteStrings where possible. Review-Url: https://codereview.chromium.org/1977093002
Diffstat (limited to 'core/fpdfdoc/doc_basic.cpp')
-rw-r--r--core/fpdfdoc/doc_basic.cpp25
1 files changed, 10 insertions, 15 deletions
diff --git a/core/fpdfdoc/doc_basic.cpp b/core/fpdfdoc/doc_basic.cpp
index 76639efac6..ab99cff772 100644
--- a/core/fpdfdoc/doc_basic.cpp
+++ b/core/fpdfdoc/doc_basic.cpp
@@ -500,30 +500,25 @@ CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const {
wsLabel.Format(L"%d", nPage + 1);
return wsLabel;
}
+
int32_t CPDF_PageLabel::GetPageByLabel(const CFX_ByteStringC& bsLabel) const {
- if (!m_pDocument) {
+ if (!m_pDocument)
return -1;
- }
+
CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot();
- if (!pPDFRoot) {
+ if (!pPDFRoot)
return -1;
- }
+
int nPages = m_pDocument->GetPageCount();
- CFX_ByteString bsLbl;
- CFX_ByteString bsOrig = bsLabel;
for (int i = 0; i < nPages; i++) {
- bsLbl = PDF_EncodeText(GetLabel(i));
- if (!bsLbl.Compare(bsOrig.AsStringC())) {
+ if (PDF_EncodeText(GetLabel(i)).Compare(bsLabel))
return i;
- }
- }
- bsLbl = bsOrig;
- int nPage = FXSYS_atoi(bsLbl.c_str());
- if (nPage > 0 && nPage <= nPages) {
- return nPage;
}
- return -1;
+
+ int nPage = FXSYS_atoi(CFX_ByteString(bsLabel).c_str()); // NUL terminate.
+ return nPage > 0 && nPage <= nPages ? nPage : -1;
}
+
int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const {
return GetPageByLabel(PDF_EncodeText(wsLabel.c_str()).AsStringC());
}