diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-06-20 20:32:04 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-06-20 20:32:04 +0000 |
commit | c62e8489042c5efaa3b666846b38a52da3b91481 (patch) | |
tree | f0a1ef59f861bbd8e9ba81c6fb274f44d69450ea | |
parent | b6b01cb2cbaf6b38736f4dfebb9b6cdc243960f9 (diff) | |
download | pdfium-c62e8489042c5efaa3b666846b38a52da3b91481.tar.xz |
Avoid more .c_str() usage, part 3
Change-Id: I5dfadcb68e640235be6e3eb7c8d57ae3b8013d26
Reviewed-on: https://pdfium-review.googlesource.com/35691
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
-rw-r--r-- | core/fpdfapi/font/cpdf_cmapmanager.cpp | 12 | ||||
-rw-r--r-- | core/fpdfapi/font/cpdf_cmapmanager.h | 3 | ||||
-rw-r--r-- | core/fpdftext/cpdf_textpagefind.cpp | 2 | ||||
-rw-r--r-- | core/fxcrt/css/cfx_cssrulecollection.cpp | 2 | ||||
-rw-r--r-- | core/fxcrt/css/cfx_cssstyleselector.cpp | 2 | ||||
-rw-r--r-- | fxjs/cjs_util.cpp | 4 | ||||
-rw-r--r-- | fxjs/xfa/cjx_packet.cpp | 6 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_fontmgr.cpp | 13 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_fontmgr.h | 2 |
9 files changed, 20 insertions, 26 deletions
diff --git a/core/fpdfapi/font/cpdf_cmapmanager.cpp b/core/fpdfapi/font/cpdf_cmapmanager.cpp index 53183af340..62a2013448 100644 --- a/core/fpdfapi/font/cpdf_cmapmanager.cpp +++ b/core/fpdfapi/font/cpdf_cmapmanager.cpp @@ -29,15 +29,13 @@ RetainPtr<CPDF_CMap> CPDF_CMapManager::GetPredefinedCMap(const ByteString& name, return pCMap; } -RetainPtr<CPDF_CMap> CPDF_CMapManager::LoadPredefinedCMap( - const ByteString& name, - bool bPromptCJK) { - const char* pname = name.c_str(); - if (*pname == '/') - pname++; +RetainPtr<CPDF_CMap> CPDF_CMapManager::LoadPredefinedCMap(ByteString name, + bool bPromptCJK) { + if (!name.IsEmpty() && name[0] == '/') + name = name.Right(name.GetLength() - 1); auto pCMap = pdfium::MakeRetain<CPDF_CMap>(); - pCMap->LoadPredefined(this, pname, bPromptCJK); + pCMap->LoadPredefined(this, name, bPromptCJK); return pCMap; } diff --git a/core/fpdfapi/font/cpdf_cmapmanager.h b/core/fpdfapi/font/cpdf_cmapmanager.h index 089eb3d705..47a0be063f 100644 --- a/core/fpdfapi/font/cpdf_cmapmanager.h +++ b/core/fpdfapi/font/cpdf_cmapmanager.h @@ -24,8 +24,7 @@ class CPDF_CMapManager { CPDF_CID2UnicodeMap* GetCID2UnicodeMap(CIDSet charset, bool bPromptCJK); private: - RetainPtr<CPDF_CMap> LoadPredefinedCMap(const ByteString& name, - bool bPromptCJK); + RetainPtr<CPDF_CMap> LoadPredefinedCMap(ByteString name, bool bPromptCJK); std::unique_ptr<CPDF_CID2UnicodeMap> LoadCID2UnicodeMap(CIDSet charset, bool bPromptCJK); diff --git a/core/fpdftext/cpdf_textpagefind.cpp b/core/fpdftext/cpdf_textpagefind.cpp index 62bc3cb87c..19ae58a8c3 100644 --- a/core/fpdftext/cpdf_textpagefind.cpp +++ b/core/fpdftext/cpdf_textpagefind.cpp @@ -161,7 +161,7 @@ bool CPDF_TextPageFind::FindNext() { } continue; } - nResultPos = m_strText.Find(csWord.c_str(), nStartPos); + nResultPos = m_strText.Find(csWord.AsStringView(), nStartPos); if (!nResultPos.has_value()) { m_IsFind = false; return m_IsFind; diff --git a/core/fxcrt/css/cfx_cssrulecollection.cpp b/core/fxcrt/css/cfx_cssrulecollection.cpp index 2030518b69..f525821522 100644 --- a/core/fxcrt/css/cfx_cssrulecollection.cpp +++ b/core/fxcrt/css/cfx_cssrulecollection.cpp @@ -29,7 +29,7 @@ void CFX_CSSRuleCollection::Clear() { const std::vector<std::unique_ptr<CFX_CSSRuleCollection::Data>>* CFX_CSSRuleCollection::GetTagRuleData(const WideString& tagname) const { - auto it = m_TagRules.find(FX_HashCode_GetW(tagname.c_str(), true)); + auto it = m_TagRules.find(FX_HashCode_GetW(tagname.AsStringView(), true)); return it != m_TagRules.end() ? &it->second : nullptr; } diff --git a/core/fxcrt/css/cfx_cssstyleselector.cpp b/core/fxcrt/css/cfx_cssstyleselector.cpp index 4a47798d31..9b1a2235bc 100644 --- a/core/fxcrt/css/cfx_cssstyleselector.cpp +++ b/core/fxcrt/css/cfx_cssstyleselector.cpp @@ -75,7 +75,7 @@ bool CFX_CSSStyleSelector::MatchSelector(const WideString& tagname, pSel->GetType() == CFX_CSSSelectorType::Descendant) { return false; } - return pSel->GetNameHash() == FX_HashCode_GetW(tagname.c_str(), true); + return pSel->GetNameHash() == FX_HashCode_GetW(tagname.AsStringView(), true); } void CFX_CSSStyleSelector::ComputeStyle( diff --git a/fxjs/cjs_util.cpp b/fxjs/cjs_util.cpp index fec727302d..3889f5ab63 100644 --- a/fxjs/cjs_util.cpp +++ b/fxjs/cjs_util.cpp @@ -183,7 +183,7 @@ CJS_Return CJS_Util::printd(CJS_Runtime* pRuntime, return CJS_Return(JSMessage::kValueError); } - return CJS_Return(pRuntime->NewString(swResult.c_str())); + return CJS_Return(pRuntime->NewString(swResult.AsStringView())); } if (params[0]->IsString()) { @@ -259,7 +259,7 @@ CJS_Return CJS_Util::printx(CJS_Runtime* pRuntime, return CJS_Return( pRuntime->NewString(printx(pRuntime->ToWideString(params[0]), pRuntime->ToWideString(params[1])) - .c_str())); + .AsStringView())); } enum CaseMode { kPreserveCase, kUpperCase, kLowerCase }; diff --git a/fxjs/xfa/cjx_packet.cpp b/fxjs/xfa/cjx_packet.cpp index e4119baf91..b27cfbadfb 100644 --- a/fxjs/xfa/cjx_packet.cpp +++ b/fxjs/xfa/cjx_packet.cpp @@ -38,7 +38,7 @@ CJS_Return CJX_Packet::getAttribute( CFX_XMLNode* pXMLNode = GetXFANode()->GetXMLMappingNode(); if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) { attributeValue = static_cast<CFX_XMLElement*>(pXMLNode)->GetAttribute( - runtime->ToWideString(params[0]).c_str()); + runtime->ToWideString(params[0])); } return CJS_Return( runtime->NewString(attributeValue.UTF8Encode().AsStringView())); @@ -68,8 +68,8 @@ CJS_Return CJX_Packet::removeAttribute( if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) { WideString name = runtime->ToWideString(params[0]); CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode); - if (pXMLElement->HasAttribute(name.c_str())) - pXMLElement->RemoveAttribute(name.c_str()); + if (pXMLElement->HasAttribute(name)) + pXMLElement->RemoveAttribute(name); } return CJS_Return(runtime->NewNull()); } diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp index 59d4563c29..5ab91b3cc6 100644 --- a/xfa/fgas/font/cfgas_fontmgr.cpp +++ b/xfa/fgas/font/cfgas_fontmgr.cpp @@ -690,11 +690,10 @@ int32_t CFGAS_FontMgr::CalcPenalty(CFX_FontDescriptor* pInstalled, } else { nPenalty -= 30000; } - if (30000 == nPenalty && - 0 == IsPartName(pInstalled->m_wsFaceName, FontName)) { + if (nPenalty == 30000 && !IsPartName(pInstalled->m_wsFaceName, FontName)) { size_t i; for (i = 0; i < pInstalled->m_wsFamilyNames.size(); i++) { - if (IsPartName(pInstalled->m_wsFamilyNames[i], FontName) != 0) + if (IsPartName(pInstalled->m_wsFamilyNames[i], FontName)) break; } if (i == pInstalled->m_wsFamilyNames.size()) @@ -884,11 +883,9 @@ void CFGAS_FontMgr::GetUSBCSB(FXFT_Face pFace, uint32_t* USB, uint32_t* CSB) { CSB[1] = pOS2->ulCodePageRange2; } -int32_t CFGAS_FontMgr::IsPartName(const WideString& Name1, - const WideString& Name2) { - if (Name1.Contains(Name2.c_str())) - return 1; - return 0; +bool CFGAS_FontMgr::IsPartName(const WideString& name1, + const WideString& name2) { + return name1.Contains(name2.AsStringView()); } #endif // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h index f082b02dd3..5a1e9babf6 100644 --- a/xfa/fgas/font/cfgas_fontmgr.h +++ b/xfa/fgas/font/cfgas_fontmgr.h @@ -160,7 +160,7 @@ class CFGAS_FontMgr : public Observable<CFGAS_FontMgr> { void GetUSBCSB(FXFT_Face pFace, uint32_t* USB, uint32_t* CSB); uint32_t GetFlags(FXFT_Face pFace); bool VerifyUnicode(CFX_FontDescriptor* pDesc, wchar_t wcUnicode); - int32_t IsPartName(const WideString& Name1, const WideString& Name2); + bool IsPartName(const WideString& name1, const WideString& name2); void MatchFonts(std::vector<CFX_FontDescriptorInfo>* MatchedFonts, uint16_t wCodePage, uint32_t dwFontStyles, |