Chromium Code Reviews| Index: core/fpdfdoc/doc_basic.cpp |
| diff --git a/core/fpdfdoc/doc_basic.cpp b/core/fpdfdoc/doc_basic.cpp |
| index a0c6b2babc4494562af14b35178778dbebb6c01b..e3fe2f2aa9904aae5ce59a152ccf4e7c0be028ed 100644 |
| --- a/core/fpdfdoc/doc_basic.cpp |
| +++ b/core/fpdfdoc/doc_basic.cpp |
| @@ -500,30 +500,28 @@ 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) { |
| + |
| + int nPage = FXSYS_atoi(CFX_ByteString(bsLabel).c_str()); // NUL terminate. |
| + if (nPage > 0 && nPage <= nPages) |
|
Lei Zhang
2016/05/13 23:49:55
Ternary operator instead?
Tom Sepez
2016/05/14 00:28:46
Done.
|
| return nPage; |
| - } |
| + |
| return -1; |
| } |
| + |
| int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const { |
| return GetPageByLabel(PDF_EncodeText(wsLabel.c_str()).AsStringC()); |
| } |