summaryrefslogtreecommitdiff
path: root/core/fxcrt
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/fxcrt
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/fxcrt')
-rw-r--r--core/fxcrt/fx_basic_bstring.cpp2
-rw-r--r--core/fxcrt/fx_basic_buffer.cpp4
-rw-r--r--core/fxcrt/fx_basic_utf.cpp11
-rw-r--r--core/fxcrt/fx_xml_parser.cpp49
-rw-r--r--core/fxcrt/include/fx_basic.h9
-rw-r--r--core/fxcrt/include/fx_string.h3
-rw-r--r--core/fxcrt/include/fx_xml.h14
7 files changed, 48 insertions, 44 deletions
diff --git a/core/fxcrt/fx_basic_bstring.cpp b/core/fxcrt/fx_basic_bstring.cpp
index c774e80cb7..379f1ee882 100644
--- a/core/fxcrt/fx_basic_bstring.cpp
+++ b/core/fxcrt/fx_basic_bstring.cpp
@@ -408,7 +408,7 @@ void CFX_ByteString::AllocCopy(CFX_ByteString& dest,
CFX_ByteString CFX_ByteString::FormatInteger(int i, uint32_t flags) {
char buf[32];
- return CFX_ByteStringC(buf, Buffer_itoa(buf, i, flags));
+ return CFX_ByteString(buf, Buffer_itoa(buf, i, flags));
}
void CFX_ByteString::FormatV(const FX_CHAR* pFormat, va_list argList) {
diff --git a/core/fxcrt/fx_basic_buffer.cpp b/core/fxcrt/fx_basic_buffer.cpp
index 6008a00b40..2762497e5c 100644
--- a/core/fxcrt/fx_basic_buffer.cpp
+++ b/core/fxcrt/fx_basic_buffer.cpp
@@ -100,10 +100,6 @@ void CFX_BinaryBuf::InsertBlock(FX_STRSIZE pos,
m_DataSize += size;
}
-CFX_ByteStringC CFX_ByteTextBuf::AsStringC() const {
- return CFX_ByteStringC(m_pBuffer.get(), m_DataSize);
-}
-
CFX_ByteTextBuf& CFX_ByteTextBuf::operator<<(const CFX_ByteStringC& lpsz) {
AppendBlock(lpsz.raw_str(), lpsz.GetLength());
return *this;
diff --git a/core/fxcrt/fx_basic_utf.cpp b/core/fxcrt/fx_basic_utf.cpp
index 61b200fab4..de219b40fd 100644
--- a/core/fxcrt/fx_basic_utf.cpp
+++ b/core/fxcrt/fx_basic_utf.cpp
@@ -74,13 +74,12 @@ void CFX_UTF8Encoder::Input(FX_WCHAR unicode) {
}
}
CFX_ByteString FX_UTF8Encode(const FX_WCHAR* pwsStr, FX_STRSIZE len) {
- ASSERT(pwsStr);
- if (len < 0) {
+ if (len < 0)
len = FXSYS_wcslen(pwsStr);
- }
+
CFX_UTF8Encoder encoder;
- while (len-- > 0) {
+ while (len-- > 0)
encoder.Input(*pwsStr++);
- }
- return encoder.GetResult();
+
+ return CFX_ByteString(encoder.GetResult());
}
diff --git a/core/fxcrt/fx_xml_parser.cpp b/core/fxcrt/fx_xml_parser.cpp
index a5e351fe56..6017bd8fda 100644
--- a/core/fxcrt/fx_xml_parser.cpp
+++ b/core/fxcrt/fx_xml_parser.cpp
@@ -397,8 +397,7 @@ CXML_Element* CXML_Parser::ParseElement(CXML_Element* pParent,
}
CFX_WideString attr_value;
GetAttrValue(attr_value);
- pElement->m_AttrMap.SetAt(attr_space.AsStringC(), attr_name.AsStringC(),
- attr_value.AsStringC());
+ pElement->m_AttrMap.SetAt(attr_space, attr_name, attr_value);
}
m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
if (m_dwIndex < m_dwBufferSize || IsEOF()) {
@@ -597,14 +596,13 @@ CFX_ByteString CXML_Element::GetTagName(FX_BOOL bQualified) const {
bsTag += m_TagName;
return bsTag;
}
+
CFX_ByteString CXML_Element::GetNamespace(FX_BOOL bQualified) const {
- if (bQualified) {
- return m_QSpaceName;
- }
- return GetNamespaceURI(m_QSpaceName.AsStringC());
+ return bQualified ? m_QSpaceName : GetNamespaceURI(m_QSpaceName);
}
+
CFX_ByteString CXML_Element::GetNamespaceURI(
- const CFX_ByteStringC& qName) const {
+ const CFX_ByteString& qName) const {
const CFX_WideString* pwsSpace;
const CXML_Element* pElement = this;
do {
@@ -633,20 +631,23 @@ void CXML_Element::GetAttrByIndex(int index,
value = item.m_Value;
}
FX_BOOL CXML_Element::HasAttr(const CFX_ByteStringC& name) const {
- CFX_ByteStringC bsSpace, bsName;
+ CFX_ByteStringC bsSpace;
+ CFX_ByteStringC bsName;
FX_XML_SplitQualifiedName(name, bsSpace, bsName);
- return !!m_AttrMap.Lookup(bsSpace, bsName);
+ return !!m_AttrMap.Lookup(CFX_ByteString(bsSpace), CFX_ByteString(bsName));
}
FX_BOOL CXML_Element::GetAttrValue(const CFX_ByteStringC& name,
CFX_WideString& attribute) const {
- CFX_ByteStringC bsSpace, bsName;
+ CFX_ByteStringC bsSpace;
+ CFX_ByteStringC bsName;
FX_XML_SplitQualifiedName(name, bsSpace, bsName);
return GetAttrValue(bsSpace, bsName, attribute);
}
FX_BOOL CXML_Element::GetAttrValue(const CFX_ByteStringC& space,
const CFX_ByteStringC& name,
CFX_WideString& attribute) const {
- const CFX_WideString* pValue = m_AttrMap.Lookup(space, name);
+ const CFX_WideString* pValue =
+ m_AttrMap.Lookup(CFX_ByteString(space), CFX_ByteString(name));
if (pValue) {
attribute = *pValue;
return TRUE;
@@ -655,9 +656,11 @@ FX_BOOL CXML_Element::GetAttrValue(const CFX_ByteStringC& space,
}
FX_BOOL CXML_Element::GetAttrInteger(const CFX_ByteStringC& name,
int& attribute) const {
- CFX_ByteStringC bsSpace, bsName;
+ CFX_ByteStringC bsSpace;
+ CFX_ByteStringC bsName;
FX_XML_SplitQualifiedName(name, bsSpace, bsName);
- const CFX_WideString* pwsValue = m_AttrMap.Lookup(bsSpace, bsName);
+ const CFX_WideString* pwsValue =
+ m_AttrMap.Lookup(CFX_ByteString(bsSpace), CFX_ByteString(bsName));
if (pwsValue) {
attribute = pwsValue->GetInteger();
return TRUE;
@@ -667,7 +670,8 @@ FX_BOOL CXML_Element::GetAttrInteger(const CFX_ByteStringC& name,
FX_BOOL CXML_Element::GetAttrInteger(const CFX_ByteStringC& space,
const CFX_ByteStringC& name,
int& attribute) const {
- const CFX_WideString* pwsValue = m_AttrMap.Lookup(space, name);
+ const CFX_WideString* pwsValue =
+ m_AttrMap.Lookup(CFX_ByteString(space), CFX_ByteString(name));
if (pwsValue) {
attribute = pwsValue->GetInteger();
return TRUE;
@@ -683,7 +687,8 @@ FX_BOOL CXML_Element::GetAttrFloat(const CFX_ByteStringC& name,
FX_BOOL CXML_Element::GetAttrFloat(const CFX_ByteStringC& space,
const CFX_ByteStringC& name,
FX_FLOAT& attribute) const {
- const CFX_WideString* pValue = m_AttrMap.Lookup(space, name);
+ const CFX_WideString* pValue =
+ m_AttrMap.Lookup(CFX_ByteString(space), CFX_ByteString(name));
if (pValue) {
attribute = pValue->GetFloat();
return TRUE;
@@ -754,13 +759,13 @@ uint32_t CXML_Element::FindElement(CXML_Element* pChild) const {
return (uint32_t)-1;
}
-bool CXML_AttrItem::Matches(const CFX_ByteStringC& space,
- const CFX_ByteStringC& name) const {
+bool CXML_AttrItem::Matches(const CFX_ByteString& space,
+ const CFX_ByteString& name) const {
return (space.IsEmpty() || m_QSpaceName == space) && m_AttrName == name;
}
-const CFX_WideString* CXML_AttrMap::Lookup(const CFX_ByteStringC& space,
- const CFX_ByteStringC& name) const {
+const CFX_WideString* CXML_AttrMap::Lookup(const CFX_ByteString& space,
+ const CFX_ByteString& name) const {
if (!m_pMap)
return nullptr;
@@ -771,9 +776,9 @@ const CFX_WideString* CXML_AttrMap::Lookup(const CFX_ByteStringC& space,
return nullptr;
}
-void CXML_AttrMap::SetAt(const CFX_ByteStringC& space,
- const CFX_ByteStringC& name,
- const CFX_WideStringC& value) {
+void CXML_AttrMap::SetAt(const CFX_ByteString& space,
+ const CFX_ByteString& name,
+ const CFX_WideString& value) {
if (!m_pMap)
m_pMap.reset(new std::vector<CXML_AttrItem>);
diff --git a/core/fxcrt/include/fx_basic.h b/core/fxcrt/include/fx_basic.h
index 48999c4f19..7121ffcd0b 100644
--- a/core/fxcrt/include/fx_basic.h
+++ b/core/fxcrt/include/fx_basic.h
@@ -56,10 +56,15 @@ class CFX_BinaryBuf {
class CFX_ByteTextBuf : public CFX_BinaryBuf {
public:
- void AppendChar(int ch) { AppendByte((uint8_t)ch); }
FX_STRSIZE GetLength() const { return m_DataSize; }
- CFX_ByteStringC AsStringC() const;
+ CFX_ByteString MakeString() const {
+ return CFX_ByteString(m_pBuffer.get(), m_DataSize);
+ }
+ CFX_ByteStringC AsStringC() const {
+ return CFX_ByteStringC(m_pBuffer.get(), m_DataSize);
+ }
+ void AppendChar(int ch) { AppendByte(static_cast<uint8_t>(ch)); }
CFX_ByteTextBuf& operator<<(int i);
CFX_ByteTextBuf& operator<<(uint32_t i);
CFX_ByteTextBuf& operator<<(double f);
diff --git a/core/fxcrt/include/fx_string.h b/core/fxcrt/include/fx_string.h
index df8afb386f..142f9372d0 100644
--- a/core/fxcrt/include/fx_string.h
+++ b/core/fxcrt/include/fx_string.h
@@ -46,8 +46,7 @@ class CFX_ByteString {
CFX_ByteString(const FX_CHAR* ptr, FX_STRSIZE len);
CFX_ByteString(const uint8_t* ptr, FX_STRSIZE len);
- // TODO(tsepez): mark constructor as explicit.
- CFX_ByteString(const CFX_ByteStringC& bstrc);
+ explicit CFX_ByteString(const CFX_ByteStringC& bstrc);
CFX_ByteString(const CFX_ByteStringC& bstrc1, const CFX_ByteStringC& bstrc2);
~CFX_ByteString();
diff --git a/core/fxcrt/include/fx_xml.h b/core/fxcrt/include/fx_xml.h
index 3e22883c7f..8816e2eae1 100644
--- a/core/fxcrt/include/fx_xml.h
+++ b/core/fxcrt/include/fx_xml.h
@@ -14,7 +14,7 @@
class CXML_AttrItem {
public:
- bool Matches(const CFX_ByteStringC& space, const CFX_ByteStringC& name) const;
+ bool Matches(const CFX_ByteString& space, const CFX_ByteString& name) const;
CFX_ByteString m_QSpaceName;
CFX_ByteString m_AttrName;
@@ -23,11 +23,11 @@ class CXML_AttrItem {
class CXML_AttrMap {
public:
- const CFX_WideString* Lookup(const CFX_ByteStringC& space,
- const CFX_ByteStringC& name) const;
- void SetAt(const CFX_ByteStringC& space,
- const CFX_ByteStringC& name,
- const CFX_WideStringC& value);
+ const CFX_WideString* Lookup(const CFX_ByteString& space,
+ const CFX_ByteString& name) const;
+ void SetAt(const CFX_ByteString& space,
+ const CFX_ByteString& name,
+ const CFX_WideString& value);
int GetSize() const;
CXML_AttrItem& GetAt(int index) const;
@@ -69,7 +69,7 @@ class CXML_Element {
void Empty();
CFX_ByteString GetTagName(FX_BOOL bQualified = FALSE) const;
CFX_ByteString GetNamespace(FX_BOOL bQualified = FALSE) const;
- CFX_ByteString GetNamespaceURI(const CFX_ByteStringC& qName) const;
+ CFX_ByteString GetNamespaceURI(const CFX_ByteString& qName) const;
CXML_Element* GetParent() const { return m_pParent; }
uint32_t CountAttrs() const { return m_AttrMap.GetSize(); }
void GetAttrByIndex(int index,