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

Unified Diff: core/src/fxcrt/fx_basic_wstring.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/src/fxcrt/fx_basic_util.cpp ('k') | core/src/fxcrt/fx_extension.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/src/fxcrt/fx_basic_wstring.cpp
diff --git a/core/src/fxcrt/fx_basic_wstring.cpp b/core/src/fxcrt/fx_basic_wstring.cpp
index a3de140e8bbfcfd7d92aa5b2ba535d2cbd34225c..119de66b84990c421a478d6a43322b204784ca62 100644
--- a/core/src/fxcrt/fx_basic_wstring.cpp
+++ b/core/src/fxcrt/fx_basic_wstring.cpp
@@ -43,7 +43,7 @@ CFX_WideString::~CFX_WideString() {
}
}
CFX_WideString::CFX_WideString(const CFX_WideString& stringSrc) {
- if (stringSrc.m_pData == NULL) {
+ if (!stringSrc.m_pData) {
m_pData = NULL;
return;
}
@@ -101,7 +101,7 @@ CFX_WideString::CFX_WideString(const CFX_WideStringC& str1,
}
}
void CFX_WideString::ReleaseBuffer(FX_STRSIZE nNewLength) {
- if (m_pData == NULL) {
+ if (!m_pData) {
return;
}
CopyBeforeWrite();
@@ -117,7 +117,7 @@ void CFX_WideString::ReleaseBuffer(FX_STRSIZE nNewLength) {
m_pData->m_String[nNewLength] = 0;
}
const CFX_WideString& CFX_WideString::operator=(const FX_WCHAR* lpsz) {
- if (lpsz == NULL || lpsz[0] == 0) {
+ if (!lpsz || lpsz[0] == 0) {
Empty();
} else {
AssignCopy(FXSYS_wcslen(lpsz), lpsz);
@@ -163,7 +163,7 @@ const CFX_WideString& CFX_WideString::operator+=(const FX_WCHAR* lpsz) {
return *this;
}
const CFX_WideString& CFX_WideString::operator+=(const CFX_WideString& string) {
- if (string.m_pData == NULL) {
+ if (!string.m_pData) {
return *this;
}
ConcatInPlace(string.m_pData->m_nDataLength, string.m_pData->m_String);
@@ -188,7 +188,7 @@ bool CFX_WideString::Equal(const wchar_t* ptr) const {
wmemcmp(ptr, m_pData->m_String, m_pData->m_nDataLength) == 0;
}
bool CFX_WideString::Equal(const CFX_WideStringC& str) const {
- if (m_pData == NULL) {
+ if (!m_pData) {
return str.IsEmpty();
}
return str.GetLength() == m_pData->m_nDataLength &&
@@ -213,10 +213,10 @@ void CFX_WideString::Empty() {
}
void CFX_WideString::ConcatInPlace(FX_STRSIZE nSrcLen,
const FX_WCHAR* lpszSrcData) {
- if (nSrcLen == 0 || lpszSrcData == NULL) {
+ if (nSrcLen == 0 || !lpszSrcData) {
return;
}
- if (m_pData == NULL) {
+ if (!m_pData) {
m_pData = StringData::Create(nSrcLen);
if (m_pData) {
FXSYS_memcpy(m_pData->m_String, lpszSrcData, nSrcLen * sizeof(FX_WCHAR));
@@ -251,7 +251,7 @@ void CFX_WideString::ConcatCopy(FX_STRSIZE nSrc1Len,
pOldData->Release();
}
void CFX_WideString::CopyBeforeWrite() {
- if (m_pData == NULL || m_pData->m_nRefs <= 1) {
+ if (!m_pData || m_pData->m_nRefs <= 1) {
return;
}
StringData* pData = m_pData;
@@ -278,16 +278,15 @@ void CFX_WideString::AssignCopy(FX_STRSIZE nSrcLen,
m_pData->m_String[nSrcLen] = 0;
}
int CFX_WideString::Compare(const FX_WCHAR* lpsz) const {
- if (m_pData == NULL) {
- return (lpsz == NULL || lpsz[0] == 0) ? 0 : -1;
- }
- return FXSYS_wcscmp(m_pData->m_String, lpsz);
+ if (m_pData)
+ return FXSYS_wcscmp(m_pData->m_String, lpsz);
+ return (!lpsz || lpsz[0] == 0) ? 0 : -1;
}
CFX_ByteString CFX_WideString::UTF8Encode() const {
return FX_UTF8Encode(*this);
}
CFX_ByteString CFX_WideString::UTF16LE_Encode() const {
- if (m_pData == NULL) {
+ if (!m_pData) {
return CFX_ByteString("\0\0", 2);
}
int len = m_pData->m_nDataLength;
@@ -304,7 +303,7 @@ CFX_ByteString CFX_WideString::UTF16LE_Encode() const {
}
void CFX_WideString::ConvertFrom(const CFX_ByteString& str,
CFX_CharMap* pCharMap) {
- if (pCharMap == NULL) {
+ if (!pCharMap) {
pCharMap = CFX_CharMap::GetDefaultMapper();
}
*this = pCharMap->m_GetWideString(pCharMap, str);
@@ -314,14 +313,14 @@ void CFX_WideString::Reserve(FX_STRSIZE len) {
ReleaseBuffer(GetLength());
}
FX_WCHAR* CFX_WideString::GetBuffer(FX_STRSIZE nMinBufLength) {
- if (m_pData == NULL && nMinBufLength == 0) {
+ if (!m_pData && nMinBufLength == 0) {
return NULL;
}
if (m_pData && m_pData->m_nRefs <= 1 &&
m_pData->m_nAllocLength >= nMinBufLength) {
return m_pData->m_String;
}
- if (m_pData == NULL) {
+ if (!m_pData) {
m_pData = StringData::Create(nMinBufLength);
if (!m_pData) {
return NULL;
@@ -394,7 +393,7 @@ void CFX_WideString::AllocCopy(CFX_WideString& dest,
pdfium::base::CheckedNumeric<FX_STRSIZE> iSize =
static_cast<FX_STRSIZE>(sizeof(FX_WCHAR));
iSize *= nCopyLen;
- ASSERT(dest.m_pData == NULL);
+ ASSERT(!dest.m_pData);
dest.m_pData = StringData::Create(nCopyLen);
if (dest.m_pData) {
FXSYS_memcpy(dest.m_pData->m_String, m_pData->m_String + nCopyIndex,
@@ -402,7 +401,7 @@ void CFX_WideString::AllocCopy(CFX_WideString& dest,
}
}
CFX_WideString CFX_WideString::Left(FX_STRSIZE nCount) const {
- if (m_pData == NULL) {
+ if (!m_pData) {
return CFX_WideString();
}
if (nCount < 0) {
@@ -419,7 +418,7 @@ CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst) const {
return Mid(nFirst, m_pData->m_nDataLength - nFirst);
}
CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const {
- if (m_pData == NULL) {
+ if (!m_pData) {
return CFX_WideString();
}
if (nFirst < 0) {
@@ -442,7 +441,7 @@ CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const {
return dest;
}
CFX_WideString CFX_WideString::Right(FX_STRSIZE nCount) const {
- if (m_pData == NULL) {
+ if (!m_pData) {
return CFX_WideString();
}
if (nCount < 0) {
@@ -456,19 +455,19 @@ CFX_WideString CFX_WideString::Right(FX_STRSIZE nCount) const {
return dest;
}
int CFX_WideString::CompareNoCase(const FX_WCHAR* lpsz) const {
- if (m_pData == NULL) {
- return (lpsz == NULL || lpsz[0] == 0) ? 0 : -1;
+ if (!m_pData) {
+ return (!lpsz || lpsz[0] == 0) ? 0 : -1;
}
return FXSYS_wcsicmp(m_pData->m_String, lpsz);
}
int CFX_WideString::Compare(const CFX_WideString& str) const {
- if (m_pData == NULL) {
- if (str.m_pData == NULL) {
+ if (!m_pData) {
+ if (!str.m_pData) {
return 0;
}
return -1;
}
- if (str.m_pData == NULL) {
+ if (!str.m_pData) {
return 1;
}
int this_len = m_pData->m_nDataLength;
@@ -491,7 +490,7 @@ int CFX_WideString::Compare(const CFX_WideString& str) const {
return 0;
}
void CFX_WideString::SetAt(FX_STRSIZE nIndex, FX_WCHAR ch) {
- if (m_pData == NULL) {
+ if (!m_pData) {
return;
}
ASSERT(nIndex >= 0);
@@ -500,7 +499,7 @@ void CFX_WideString::SetAt(FX_STRSIZE nIndex, FX_WCHAR ch) {
m_pData->m_String[nIndex] = ch;
}
void CFX_WideString::MakeLower() {
- if (m_pData == NULL) {
+ if (!m_pData) {
return;
}
CopyBeforeWrite();
@@ -510,7 +509,7 @@ void CFX_WideString::MakeLower() {
FXSYS_wcslwr(m_pData->m_String);
}
void CFX_WideString::MakeUpper() {
- if (m_pData == NULL) {
+ if (!m_pData) {
return;
}
CopyBeforeWrite();
@@ -526,10 +525,10 @@ FX_STRSIZE CFX_WideString::Find(const FX_WCHAR* lpszSub,
return -1;
}
const FX_WCHAR* lpsz = FXSYS_wcsstr(m_pData->m_String + nStart, lpszSub);
- return (lpsz == NULL) ? -1 : (int)(lpsz - m_pData->m_String);
+ return lpsz ? (int)(lpsz - m_pData->m_String) : -1;
}
FX_STRSIZE CFX_WideString::Find(FX_WCHAR ch, FX_STRSIZE nStart) const {
- if (m_pData == NULL) {
+ if (!m_pData) {
return -1;
}
FX_STRSIZE nLength = m_pData->m_nDataLength;
@@ -537,11 +536,11 @@ FX_STRSIZE CFX_WideString::Find(FX_WCHAR ch, FX_STRSIZE nStart) const {
return -1;
}
const FX_WCHAR* lpsz = FXSYS_wcschr(m_pData->m_String + nStart, ch);
- return (lpsz == NULL) ? -1 : (int)(lpsz - m_pData->m_String);
+ return (lpsz) ? (int)(lpsz - m_pData->m_String) : -1;
}
void CFX_WideString::TrimRight(const FX_WCHAR* lpszTargetList) {
FXSYS_assert(lpszTargetList);
- if (m_pData == NULL || *lpszTargetList == 0) {
+ if (!m_pData || *lpszTargetList == 0) {
return;
}
CopyBeforeWrite();
@@ -551,7 +550,7 @@ void CFX_WideString::TrimRight(const FX_WCHAR* lpszTargetList) {
}
FX_STRSIZE pos = len;
while (pos) {
- if (FXSYS_wcschr(lpszTargetList, m_pData->m_String[pos - 1]) == NULL) {
+ if (!FXSYS_wcschr(lpszTargetList, m_pData->m_String[pos - 1])) {
break;
}
pos--;
@@ -570,7 +569,7 @@ void CFX_WideString::TrimRight() {
}
void CFX_WideString::TrimLeft(const FX_WCHAR* lpszTargets) {
FXSYS_assert(lpszTargets);
- if (m_pData == NULL || *lpszTargets == 0) {
+ if (!m_pData || *lpszTargets == 0) {
return;
}
CopyBeforeWrite();
@@ -579,7 +578,7 @@ void CFX_WideString::TrimLeft(const FX_WCHAR* lpszTargets) {
}
const FX_WCHAR* lpsz = m_pData->m_String;
while (*lpsz != 0) {
- if (FXSYS_wcschr(lpszTargets, *lpsz) == NULL) {
+ if (!FXSYS_wcschr(lpszTargets, *lpsz)) {
break;
}
lpsz++;
@@ -604,7 +603,7 @@ FX_STRSIZE CFX_WideString::Replace(const FX_WCHAR* lpszOld,
if (GetLength() < 1) {
return 0;
}
- if (lpszOld == NULL) {
+ if (!lpszOld) {
return 0;
}
FX_STRSIZE nSourceLen = FXSYS_wcslen(lpszOld);
@@ -671,7 +670,7 @@ FX_STRSIZE CFX_WideString::Insert(FX_STRSIZE nIndex, FX_WCHAR ch) {
nIndex = nNewLength;
}
nNewLength++;
- if (m_pData == NULL || m_pData->m_nAllocLength < nNewLength) {
+ if (!m_pData || m_pData->m_nAllocLength < nNewLength) {
StringData* pOldData = m_pData;
const FX_WCHAR* pstr = m_pData->m_String;
m_pData = StringData::Create(nNewLength);
@@ -711,7 +710,7 @@ FX_STRSIZE CFX_WideString::Delete(FX_STRSIZE nIndex, FX_STRSIZE nCount) {
return m_pData->m_nDataLength;
}
FX_STRSIZE CFX_WideString::Remove(FX_WCHAR chRemove) {
- if (m_pData == NULL) {
+ if (!m_pData) {
return 0;
}
CopyBeforeWrite();
@@ -831,48 +830,48 @@ void CFX_WideString::FormatV(const FX_WCHAR* lpszFormat, va_list argList) {
break;
case 's': {
const FX_WCHAR* pstrNextArg = va_arg(argList, const FX_WCHAR*);
- if (pstrNextArg == NULL) {
- nItemLen = 6;
- } else {
+ if (pstrNextArg) {
nItemLen = FXSYS_wcslen(pstrNextArg);
if (nItemLen < 1) {
nItemLen = 1;
}
+ } else {
+ nItemLen = 6;
}
} break;
case 'S': {
const FX_CHAR* pstrNextArg = va_arg(argList, const FX_CHAR*);
- if (pstrNextArg == NULL) {
- nItemLen = 6;
- } else {
+ if (pstrNextArg) {
nItemLen = FXSYS_strlen(pstrNextArg);
if (nItemLen < 1) {
nItemLen = 1;
}
+ } else {
+ nItemLen = 6;
}
} break;
case 's' | FORCE_ANSI:
case 'S' | FORCE_ANSI: {
const FX_CHAR* pstrNextArg = va_arg(argList, const FX_CHAR*);
- if (pstrNextArg == NULL) {
- nItemLen = 6;
- } else {
+ if (pstrNextArg) {
nItemLen = FXSYS_strlen(pstrNextArg);
if (nItemLen < 1) {
nItemLen = 1;
}
+ } else {
+ nItemLen = 6;
}
} break;
case 's' | FORCE_UNICODE:
case 'S' | FORCE_UNICODE: {
FX_WCHAR* pstrNextArg = va_arg(argList, FX_WCHAR*);
- if (pstrNextArg == NULL) {
- nItemLen = 6;
- } else {
+ if (pstrNextArg) {
nItemLen = FXSYS_wcslen(pstrNextArg);
if (nItemLen < 1) {
nItemLen = 1;
}
+ } else {
+ nItemLen = 6;
}
} break;
}
@@ -987,16 +986,10 @@ FX_FLOAT FX_wtof(const FX_WCHAR* str, int len) {
return bNegative ? -fraction : fraction;
}
int CFX_WideString::GetInteger() const {
- if (m_pData == NULL) {
- return 0;
- }
- return FXSYS_wtoi(m_pData->m_String);
+ return m_pData ? FXSYS_wtoi(m_pData->m_String) : 0;
}
FX_FLOAT CFX_WideString::GetFloat() const {
- if (m_pData == NULL) {
- return 0.0;
- }
- return FX_wtof(m_pData->m_String, m_pData->m_nDataLength);
+ return m_pData ? FX_wtof(m_pData->m_String, m_pData->m_nDataLength) : 0.0;
}
static CFX_ByteString _DefMap_GetByteString(CFX_CharMap* pCharMap,
const CFX_WideString& widestr) {
« no previous file with comments | « core/src/fxcrt/fx_basic_util.cpp ('k') | core/src/fxcrt/fx_extension.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698