From cfb77ccb1c057d6beb73f0043e42eee8c4822f84 Mon Sep 17 00:00:00 2001 From: thestig Date: Fri, 10 Jun 2016 12:21:53 -0700 Subject: Get rid of NULLs in xfa/fde/ Review-Url: https://codereview.chromium.org/2039923004 --- xfa/fde/css/fde_cssdatatable.cpp | 29 ++- xfa/fde/css/fde_cssdatatable.h | 6 +- xfa/fde/css/fde_cssdeclaration.cpp | 330 ++++++++++++++++------------------- xfa/fde/css/fde_cssstyleselector.cpp | 65 ++++--- xfa/fde/css/fde_cssstyleselector.h | 6 +- xfa/fde/css/fde_cssstylesheet.cpp | 121 ++++++------- xfa/fde/css/fde_cssstylesheet.h | 2 +- xfa/fde/css/fde_csssyntax.cpp | 52 +++--- 8 files changed, 285 insertions(+), 326 deletions(-) (limited to 'xfa/fde/css') diff --git a/xfa/fde/css/fde_cssdatatable.cpp b/xfa/fde/css/fde_cssdatatable.cpp index 1af0059cb6..ac8c466932 100644 --- a/xfa/fde/css/fde_cssdatatable.cpp +++ b/xfa/fde/css/fde_cssdatatable.cpp @@ -37,13 +37,12 @@ CFX_FloatRect FDE_CSSBoundaryToRect(IFDE_CSSBoundaryStyle* pBoundStyle, FX_BOOL bPadding, FX_BOOL bBorder, FX_BOOL bMargin) { - ASSERT(pBoundStyle != NULL); FX_FLOAT fResult; const FDE_CSSRECT* pRect; CFX_FloatRect rect(0, 0, 0, 0); if (bPadding) { pRect = pBoundStyle->GetPaddingWidth(); - if (pRect != NULL) { + if (pRect) { if (FDE_CSSLengthToFloat(pRect->left, fContainerWidth, fResult)) { rect.left += fResult; } @@ -60,7 +59,7 @@ CFX_FloatRect FDE_CSSBoundaryToRect(IFDE_CSSBoundaryStyle* pBoundStyle, } if (bBorder) { pRect = pBoundStyle->GetBorderWidth(); - if (pRect != NULL) { + if (pRect) { if (FDE_CSSLengthToFloat(pRect->left, fContainerWidth, fResult)) { rect.left += fResult; } @@ -77,7 +76,7 @@ CFX_FloatRect FDE_CSSBoundaryToRect(IFDE_CSSBoundaryStyle* pBoundStyle, } if (bMargin) { pRect = pBoundStyle->GetMarginWidth(); - if (pRect != NULL) { + if (pRect) { if (FDE_CSSLengthToFloat(pRect->left, fContainerWidth, fResult)) { rect.left += fResult; } @@ -95,7 +94,6 @@ CFX_FloatRect FDE_CSSBoundaryToRect(IFDE_CSSBoundaryStyle* pBoundStyle, return rect; } uint32_t FDE_CSSFontStyleToFDE(IFDE_CSSFontStyle* pFontStyle) { - ASSERT(pFontStyle != NULL); uint32_t dwFontStyle = FX_FONTSTYLE_Normal; if (pFontStyle->GetFontStyle() == FDE_CSSFONTSTYLE_Italic) { dwFontStyle |= FX_FONTSTYLE_Italic; @@ -562,7 +560,7 @@ static const FDE_CSSPERSUDOTABLE g_FDE_CSSPersudoType[] = { }; FDE_LPCCSSPERSUDOTABLE FDE_GetCSSPersudoByEnum(FDE_CSSPERSUDO ePersudo) { return (ePersudo < FDE_CSSPERSUDO_NONE) ? (g_FDE_CSSPersudoType + ePersudo) - : NULL; + : nullptr; } const FDE_CSSPROPERTYTABLE* FDE_GetCSSPropertyByName( const CFX_WideStringC& wsName) { @@ -582,10 +580,11 @@ const FDE_CSSPROPERTYTABLE* FDE_GetCSSPropertyByName( iEnd = iMid - 1; } } while (iStart <= iEnd); - return NULL; + return nullptr; } const FDE_CSSPROPERTYTABLE* FDE_GetCSSPropertyByEnum(FDE_CSSPROPERTY eName) { - return (eName < FDE_CSSPROPERTY_MAX) ? (g_FDE_CSSProperties + eName) : NULL; + return (eName < FDE_CSSPROPERTY_MAX) ? (g_FDE_CSSProperties + eName) + : nullptr; } const FDE_CSSPROPERTYVALUETABLE* FDE_GetCSSPropertyValueByName( const CFX_WideStringC& wsName) { @@ -605,12 +604,12 @@ const FDE_CSSPROPERTYVALUETABLE* FDE_GetCSSPropertyValueByName( iEnd = iMid - 1; } } while (iStart <= iEnd); - return NULL; + return nullptr; } const FDE_CSSPROPERTYVALUETABLE* FDE_GetCSSPropertyValueByEnum( FDE_CSSPROPERTYVALUE eName) { return (eName < FDE_CSSPROPERTYVALUE_MAX) ? (g_FDE_CSSPropertyValues + eName) - : NULL; + : nullptr; } FDE_LPCCSSMEDIATYPETABLE FDE_GetCSSMediaTypeByName( const CFX_WideStringC& wsName) { @@ -631,7 +630,7 @@ FDE_LPCCSSMEDIATYPETABLE FDE_GetCSSMediaTypeByName( iEnd = iMid - 1; } } while (iStart <= iEnd); - return NULL; + return nullptr; } FDE_LPCCSSLENGTHUNITTABLE FDE_GetCSSLengthUnitByName( const CFX_WideStringC& wsName) { @@ -652,7 +651,7 @@ FDE_LPCCSSLENGTHUNITTABLE FDE_GetCSSLengthUnitByName( iEnd = iMid - 1; } } while (iStart <= iEnd); - return NULL; + return nullptr; } FDE_LPCCSSCOLORTABLE FDE_GetCSSColorByName(const CFX_WideStringC& wsName) { ASSERT(!wsName.IsEmpty()); @@ -671,7 +670,7 @@ FDE_LPCCSSCOLORTABLE FDE_GetCSSColorByName(const CFX_WideStringC& wsName) { iEnd = iMid - 1; } } while (iStart <= iEnd); - return NULL; + return nullptr; } FX_BOOL FDE_ParseCSSNumber(const FX_WCHAR* pszValue, @@ -702,7 +701,7 @@ FX_BOOL FDE_ParseCSSString(const FX_WCHAR* pszValue, int32_t iValueLen, int32_t& iOffset, int32_t& iLength) { - ASSERT(pszValue != NULL && iValueLen > 0); + ASSERT(pszValue && iValueLen > 0); iOffset = 0; iLength = iValueLen; if (iValueLen >= 2) { @@ -718,7 +717,7 @@ FX_BOOL FDE_ParseCSSURI(const FX_WCHAR* pszValue, int32_t iValueLen, int32_t& iOffset, int32_t& iLength) { - ASSERT(pszValue != NULL && iValueLen > 0); + ASSERT(pszValue && iValueLen > 0); if (iValueLen < 6 || pszValue[iValueLen - 1] != ')' || FX_wcsnicmp(L"url(", pszValue, 4)) { return FALSE; diff --git a/xfa/fde/css/fde_cssdatatable.h b/xfa/fde/css/fde_cssdatatable.h index 2cc6c48fde..d61ff09ae7 100644 --- a/xfa/fde/css/fde_cssdatatable.h +++ b/xfa/fde/css/fde_cssdatatable.h @@ -15,7 +15,7 @@ class CFDE_CSSFunction : public CFX_Target { public: CFDE_CSSFunction(const FX_WCHAR* pszFuncName, IFDE_CSSValueList* pArgList) : m_pArgList(pArgList), m_pszFuncName(pszFuncName) { - ASSERT(pArgList != NULL); + ASSERT(pArgList); } int32_t CountArgs() const { return m_pArgList->CountValues(); } IFDE_CSSValue* GetArgs(int32_t index) const { @@ -39,7 +39,7 @@ class CFDE_CSSPrimitiveValue : public IFDE_CSSPrimitiveValue, : m_eType(eType), m_fNumber(fValue) {} CFDE_CSSPrimitiveValue(FDE_CSSPRIMITIVETYPE eType, const FX_WCHAR* pValue) : m_eType(eType), m_pString(pValue) { - ASSERT(m_pString != NULL); + ASSERT(m_pString); } CFDE_CSSPrimitiveValue(CFDE_CSSFunction* pFunction) : m_eType(FDE_CSSPRIMITIVETYPE_Function), m_pFunction(pFunction) {} @@ -106,7 +106,7 @@ class CFDE_CSSValueListParser : public CFX_Target { public: CFDE_CSSValueListParser(const FX_WCHAR* psz, int32_t iLen, FX_WCHAR separator) : m_Separator(separator), m_pCur(psz), m_pEnd(psz + iLen) { - ASSERT(psz != NULL && iLen > 0); + ASSERT(psz && iLen > 0); } FX_BOOL NextValue(FDE_CSSPRIMITIVETYPE& eType, const FX_WCHAR*& pStart, diff --git a/xfa/fde/css/fde_cssdeclaration.cpp b/xfa/fde/css/fde_cssdeclaration.cpp index 570b60c670..da1f42fabd 100644 --- a/xfa/fde/css/fde_cssdeclaration.cpp +++ b/xfa/fde/css/fde_cssdeclaration.cpp @@ -18,7 +18,7 @@ IFDE_CSSValue* CFDE_CSSDeclaration::GetProperty(FDE_CSSPROPERTY eProperty, return pHolder->pValue; } } - return NULL; + return nullptr; } FX_POSITION CFDE_CSSDeclaration::GetStartPosition() const { return (FX_POSITION)m_pFirstProperty; @@ -28,7 +28,6 @@ void CFDE_CSSDeclaration::GetNextProperty(FX_POSITION& pos, IFDE_CSSValue*& pValue, FX_BOOL& bImportant) const { const FDE_CSSPropertyHolder* pHolder = (const FDE_CSSPropertyHolder*)pos; - ASSERT(pHolder != NULL); bImportant = pHolder->bImportant; eProperty = (FDE_CSSPROPERTY)pHolder->eProperty; pValue = pHolder->pValue; @@ -41,9 +40,9 @@ void CFDE_CSSDeclaration::GetNextCustom(FX_POSITION& pos, CFX_WideString& wsName, CFX_WideString& wsValue) const { const FDE_CSSCustomProperty* pProperty = (const FDE_CSSCustomProperty*)pos; - if (pProperty == NULL) { + if (!pProperty) return; - } + wsName = pProperty->pwsName; wsValue = pProperty->pwsValue; pos = (FX_POSITION)pProperty->pNext; @@ -94,13 +93,12 @@ void CFDE_CSSDeclaration::AddPropertyHolder(IFX_MemoryAllocator* pStaticStore, pHolder->bImportant = bImportant; pHolder->eProperty = eProperty; pHolder->pValue = pValue; - pHolder->pNext = NULL; - if (m_pLastProperty == NULL) { - m_pLastProperty = m_pFirstProperty = pHolder; - } else { + pHolder->pNext = nullptr; + if (m_pLastProperty) m_pLastProperty->pNext = pHolder; - m_pLastProperty = pHolder; - } + else + m_pFirstProperty = pHolder; + m_pLastProperty = pHolder; } FX_BOOL CFDE_CSSDeclaration::AddProperty(const FDE_CSSPROPERTYARGS* pArgs, const FX_WCHAR* pszValue, @@ -129,7 +127,7 @@ FX_BOOL CFDE_CSSDeclaration::AddProperty(const FDE_CSSPROPERTYARGS* pArgs, if (dwMatch == 0) { continue; } - IFDE_CSSValue* pCSSValue = NULL; + IFDE_CSSValue* pCSSValue = nullptr; switch (dwMatch) { case FDE_CSSVALUETYPE_MaybeFunction: pCSSValue = ParseFunction(pArgs, pszValue, iValueLen); @@ -152,7 +150,7 @@ FX_BOOL CFDE_CSSDeclaration::AddProperty(const FDE_CSSPROPERTYARGS* pArgs, default: break; } - if (pCSSValue != NULL) { + if (pCSSValue) { AddPropertyHolder(pArgs->pStaticStore, pArgs->pProperty->eName, pCSSValue, bImportant); return TRUE; @@ -269,13 +267,12 @@ FX_BOOL CFDE_CSSDeclaration::AddProperty(const FDE_CSSPROPERTYARGS* pArgs, FXTARGET_NewWith(pArgs->pStaticStore) FDE_CSSCustomProperty; pProperty->pwsName = CopyToLocal(pArgs, pszName, iNameLen); pProperty->pwsValue = CopyToLocal(pArgs, pszValue, iValueLen); - pProperty->pNext = NULL; - if (m_pLastCustom == NULL) { - m_pLastCustom = m_pFirstCustom = pProperty; - } else { + pProperty->pNext = nullptr; + if (m_pLastCustom) m_pLastCustom->pNext = pProperty; - m_pLastCustom = pProperty; - } + else + m_pFirstCustom = pProperty; + m_pLastCustom = pProperty; return TRUE; } IFDE_CSSValue* CFDE_CSSDeclaration::ParseNumber( @@ -285,7 +282,7 @@ IFDE_CSSValue* CFDE_CSSDeclaration::ParseNumber( FX_FLOAT fValue; FDE_CSSPRIMITIVETYPE eUnit; if (!FDE_ParseCSSNumber(pszValue, iValueLen, fValue, eUnit)) { - return NULL; + return nullptr; } return NewNumberValue(pArgs->pStaticStore, eUnit, fValue); } @@ -294,14 +291,14 @@ IFDE_CSSValue* CFDE_CSSDeclaration::ParseEnum(const FDE_CSSPROPERTYARGS* pArgs, int32_t iValueLen) { const FDE_CSSPROPERTYVALUETABLE* pValue = FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); - return pValue ? NewEnumValue(pArgs->pStaticStore, pValue->eName) : NULL; + return pValue ? NewEnumValue(pArgs->pStaticStore, pValue->eName) : nullptr; } IFDE_CSSValue* CFDE_CSSDeclaration::ParseColor(const FDE_CSSPROPERTYARGS* pArgs, const FX_WCHAR* pszValue, int32_t iValueLen) { FX_ARGB dwColor; if (!FDE_ParseCSSColor(pszValue, iValueLen, dwColor)) { - return NULL; + return nullptr; } return FXTARGET_NewWith(pArgs->pStaticStore) CFDE_CSSPrimitiveValue(dwColor); } @@ -310,16 +307,16 @@ IFDE_CSSValue* CFDE_CSSDeclaration::ParseURI(const FDE_CSSPROPERTYARGS* pArgs, int32_t iValueLen) { int32_t iOffset; if (!FDE_ParseCSSURI(pszValue, iValueLen, iOffset, iValueLen)) { - return NULL; + return nullptr; } if (iValueLen <= 0) { - return NULL; + return nullptr; } pszValue = CopyToLocal(pArgs, pszValue + iOffset, iValueLen); return pszValue ? FXTARGET_NewWith(pArgs->pStaticStore) CFDE_CSSPrimitiveValue(FDE_CSSPRIMITIVETYPE_URI, pszValue) - : NULL; + : nullptr; } IFDE_CSSValue* CFDE_CSSDeclaration::ParseString( const FDE_CSSPROPERTYARGS* pArgs, @@ -327,34 +324,34 @@ IFDE_CSSValue* CFDE_CSSDeclaration::ParseString( int32_t iValueLen) { int32_t iOffset; if (!FDE_ParseCSSString(pszValue, iValueLen, iOffset, iValueLen)) { - return NULL; + return nullptr; } if (iValueLen <= 0) { - return NULL; + return nullptr; } pszValue = CopyToLocal(pArgs, pszValue + iOffset, iValueLen); return pszValue ? FXTARGET_NewWith(pArgs->pStaticStore) CFDE_CSSPrimitiveValue(FDE_CSSPRIMITIVETYPE_String, pszValue) - : NULL; + : nullptr; } IFDE_CSSValue* CFDE_CSSDeclaration::ParseFunction( const FDE_CSSPROPERTYARGS* pArgs, const FX_WCHAR* pszValue, int32_t iValueLen) { if (pszValue[iValueLen - 1] != ')') { - return NULL; + return nullptr; } int32_t iStartBracket = 0; while (pszValue[iStartBracket] != '(') { if (iStartBracket < iValueLen) { iStartBracket++; } else { - return NULL; + return nullptr; } } if (iStartBracket == 0) { - return NULL; + return nullptr; } const FX_WCHAR* pszFuncName = CopyToLocal(pArgs, pszValue, iStartBracket); pszValue += (iStartBracket + 1); @@ -367,14 +364,14 @@ IFDE_CSSValue* CFDE_CSSDeclaration::ParseFunction( case FDE_CSSPRIMITIVETYPE_String: { const FDE_CSSPROPERTYVALUETABLE* pPropertyValue = FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); - if (pPropertyValue != NULL) { + if (pPropertyValue) { argumentArr.Add( NewEnumValue(pArgs->pStaticStore, pPropertyValue->eName)); continue; } IFDE_CSSValue* pFunctionValue = ParseFunction(pArgs, pszValue, iValueLen); - if (pFunctionValue != NULL) { + if (pFunctionValue) { argumentArr.Add(pFunctionValue); continue; } @@ -425,7 +422,7 @@ FX_BOOL CFDE_CSSDeclaration::ParseContentProperty( case FDE_CSSPRIMITIVETYPE_String: { const FDE_CSSPROPERTYVALUETABLE* pValue = FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); - if (pValue != NULL) { + if (pValue) { switch (pValue->eName) { case FDE_CSSPROPERTYVALUE_Normal: case FDE_CSSPROPERTYVALUE_None: { @@ -447,7 +444,7 @@ FX_BOOL CFDE_CSSDeclaration::ParseContentProperty( continue; } IFDE_CSSValue* pFunction = ParseFunction(pArgs, pszValue, iValueLen); - if (pFunction != NULL) { + if (pFunction) { list.Add(pFunction); continue; } @@ -560,7 +557,7 @@ FX_BOOL CFDE_CSSDeclaration::ParseValueListProperty( const FDE_CSSPROPERTYVALUETABLE* pValue = FDE_GetCSSPropertyValueByName( CFX_WideStringC(pszValue, iValueLen)); - if (pValue != NULL) { + if (pValue) { list.Add(NewEnumValue(pStaticStore, pValue->eName)); continue; } @@ -668,13 +665,13 @@ FX_BOOL CFDE_CSSDeclaration::ParseBorderPropoerty( IFDE_CSSValue*& pColor, IFDE_CSSValue*& pStyle, IFDE_CSSValue*& pWidth) const { - pColor = pStyle = pWidth = NULL; + pColor = pStyle = pWidth = nullptr; CFDE_CSSValueListParser parser(pszValue, iValueLen, ' '); FDE_CSSPRIMITIVETYPE eType; while (parser.NextValue(eType, pszValue, iValueLen)) { switch (eType) { case FDE_CSSPRIMITIVETYPE_Number: - if (pWidth == NULL) { + if (!pWidth) { FX_FLOAT fValue; if (FDE_ParseCSSNumber(pszValue, iValueLen, fValue, eType)) { pWidth = NewNumberValue(pStaticStore, eType, fValue); @@ -682,7 +679,7 @@ FX_BOOL CFDE_CSSDeclaration::ParseBorderPropoerty( } break; case FDE_CSSPRIMITIVETYPE_RGB: - if (pColor == NULL) { + if (!pColor) { FX_ARGB dwColor; if (FDE_ParseCSSColor(pszValue, iValueLen, dwColor)) { pColor = @@ -693,8 +690,8 @@ FX_BOOL CFDE_CSSDeclaration::ParseBorderPropoerty( case FDE_CSSPRIMITIVETYPE_String: { const FDE_CSSCOLORTABLE* pColorItem = FDE_GetCSSColorByName(CFX_WideStringC(pszValue, iValueLen)); - if (pColorItem != NULL) { - if (pColor == NULL) { + if (pColorItem) { + if (!pColor) { pColor = FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue(pColorItem->dwValue); } @@ -702,12 +699,12 @@ FX_BOOL CFDE_CSSDeclaration::ParseBorderPropoerty( } const FDE_CSSPROPERTYVALUETABLE* pValue = FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); - if (pValue == NULL) { + if (!pValue) continue; - } + switch (pValue->eName) { case FDE_CSSPROPERTYVALUE_Transparent: - if (pColor == NULL) { + if (!pColor) { pColor = FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue((FX_ARGB)0); } @@ -715,9 +712,8 @@ FX_BOOL CFDE_CSSDeclaration::ParseBorderPropoerty( case FDE_CSSPROPERTYVALUE_Thin: case FDE_CSSPROPERTYVALUE_Thick: case FDE_CSSPROPERTYVALUE_Medium: - if (pWidth == NULL) { + if (!pWidth) pWidth = NewEnumValue(pStaticStore, pValue->eName); - } break; case FDE_CSSPROPERTYVALUE_None: case FDE_CSSPROPERTYVALUE_Hidden: @@ -729,9 +725,8 @@ FX_BOOL CFDE_CSSDeclaration::ParseBorderPropoerty( case FDE_CSSPROPERTYVALUE_Ridge: case FDE_CSSPROPERTYVALUE_Inset: case FDE_CSSPROPERTYVALUE_Outset: - if (pStyle == NULL) { + if (!pStyle) pStyle = NewEnumValue(pStaticStore, pValue->eName); - } break; default: break; @@ -741,15 +736,12 @@ FX_BOOL CFDE_CSSDeclaration::ParseBorderPropoerty( break; } } - if (pColor == NULL) { + if (!pColor) pColor = FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue((FX_ARGB)0); - } - if (pStyle == NULL) { + if (!pStyle) pStyle = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_None); - } - if (pWidth == NULL) { + if (!pWidth) pWidth = NewNumberValue(pStaticStore, FDE_CSSPRIMITIVETYPE_Number, 0.0f); - } return TRUE; } void CFDE_CSSDeclaration::AddBorderProperty(IFX_MemoryAllocator* pStaticStore, @@ -771,12 +763,14 @@ FX_BOOL CFDE_CSSDeclaration::ParseListStyleProperty( FX_BOOL bImportant) { IFX_MemoryAllocator* pStaticStore = pArgs->pStaticStore; CFDE_CSSValueListParser parser(pszValue, iValueLen, ' '); - IFDE_CSSPrimitiveValue *pType = NULL, *pImage = NULL, *pPosition = NULL; + IFDE_CSSPrimitiveValue* pType = nullptr; + IFDE_CSSPrimitiveValue* pImage = nullptr; + IFDE_CSSPrimitiveValue* pPosition = nullptr; FDE_CSSPRIMITIVETYPE eType; while (parser.NextValue(eType, pszValue, iValueLen)) { switch (eType) { case FDE_CSSPRIMITIVETYPE_URI: - if (pImage == NULL) { + if (!pImage) { pImage = FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue( eType, CopyToLocal(pArgs, pszValue, iValueLen)); } @@ -784,22 +778,20 @@ FX_BOOL CFDE_CSSDeclaration::ParseListStyleProperty( case FDE_CSSPRIMITIVETYPE_String: { const FDE_CSSPROPERTYVALUETABLE* pValue = FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); - if (pValue == NULL) { + if (!pValue) break; - } + switch (pValue->eName) { case FDE_CSSPROPERTYVALUE_None: - if (pImage == NULL) { + if (!pImage) pImage = NewEnumValue(pStaticStore, pValue->eName); - } else if (pType == NULL) { + else if (!pType) pImage = NewEnumValue(pStaticStore, pValue->eName); - } break; case FDE_CSSPROPERTYVALUE_Inside: case FDE_CSSPROPERTYVALUE_Outside: - if (pPosition == NULL) { + if (!pPosition) pPosition = NewEnumValue(pStaticStore, pValue->eName); - } break; case FDE_CSSPROPERTYVALUE_Disc: case FDE_CSSPROPERTYVALUE_Circle: @@ -815,9 +807,8 @@ FX_BOOL CFDE_CSSDeclaration::ParseListStyleProperty( case FDE_CSSPROPERTYVALUE_Georgian: case FDE_CSSPROPERTYVALUE_LowerAlpha: case FDE_CSSPROPERTYVALUE_UpperAlpha: - if (pType == NULL) { + if (!pType) pType = NewEnumValue(pStaticStore, pValue->eName); - } break; default: break; @@ -827,15 +818,12 @@ FX_BOOL CFDE_CSSDeclaration::ParseListStyleProperty( break; } } - if (pPosition == NULL) { + if (!pPosition) pPosition = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Outside); - } - if (pImage == NULL) { + if (!pImage) pImage = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_None); - } - if (pType == NULL) { + if (!pType) pType = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_None); - } AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_ListStylePosition, pPosition, bImportant); AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_ListStyleImage, pImage, @@ -851,13 +839,17 @@ FX_BOOL CFDE_CSSDeclaration::ParseBackgroundProperty( FX_BOOL bImportant) { IFX_MemoryAllocator* pStaticStore = pArgs->pStaticStore; CFDE_CSSValueListParser parser(pszValue, iValueLen, ' '); - IFDE_CSSPrimitiveValue *pColor = NULL, *pImage = NULL, *pRepeat = NULL; - IFDE_CSSPrimitiveValue *pPosX = NULL, *pPosY = NULL, *pAttachment = NULL; + IFDE_CSSPrimitiveValue* pColor = nullptr; + IFDE_CSSPrimitiveValue* pImage = nullptr; + IFDE_CSSPrimitiveValue* pRepeat = nullptr; + IFDE_CSSPrimitiveValue* pPosX = nullptr; + IFDE_CSSPrimitiveValue* pPosY = nullptr; + IFDE_CSSPrimitiveValue* pAttachment = nullptr; FDE_CSSPRIMITIVETYPE eType; while (parser.NextValue(eType, pszValue, iValueLen)) { switch (eType) { case FDE_CSSPRIMITIVETYPE_URI: - if (pImage == NULL) { + if (!pImage) { pImage = FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue( eType, CopyToLocal(pArgs, pszValue, iValueLen)); } @@ -867,60 +859,53 @@ FX_BOOL CFDE_CSSDeclaration::ParseBackgroundProperty( if (!FDE_ParseCSSNumber(pszValue, iValueLen, fValue, eType)) { break; } - if (pPosX == NULL) { + if (!pPosX) pPosX = NewNumberValue(pStaticStore, eType, fValue); - } else if (pPosY == NULL) { + else if (!pPosY) pPosY = NewNumberValue(pStaticStore, eType, fValue); - } } break; case FDE_CSSPRIMITIVETYPE_String: { const FDE_CSSPROPERTYVALUETABLE* pValue = FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); - if (pValue != NULL) { + if (pValue) { switch (pValue->eName) { case FDE_CSSPROPERTYVALUE_None: - if (pImage == NULL) { + if (!pImage) pImage = NewEnumValue(pStaticStore, pValue->eName); - } break; case FDE_CSSPROPERTYVALUE_Transparent: - if (pColor == NULL) { + if (!pColor) { pColor = FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue((FX_ARGB)0); } break; case FDE_CSSPROPERTYVALUE_Fixed: case FDE_CSSPROPERTYVALUE_Scroll: - if (pAttachment == NULL) { + if (!pAttachment) pAttachment = NewEnumValue(pStaticStore, pValue->eName); - } break; case FDE_CSSPROPERTYVALUE_Repeat: case FDE_CSSPROPERTYVALUE_RepeatX: case FDE_CSSPROPERTYVALUE_RepeatY: case FDE_CSSPROPERTYVALUE_NoRepeat: - if (pRepeat == NULL) { + if (!pRepeat) pRepeat = NewEnumValue(pStaticStore, pValue->eName); - } break; case FDE_CSSPROPERTYVALUE_Left: case FDE_CSSPROPERTYVALUE_Right: - if (pPosX == NULL) { + if (!pPosX) pPosX = NewEnumValue(pStaticStore, pValue->eName); - } break; case FDE_CSSPROPERTYVALUE_Top: case FDE_CSSPROPERTYVALUE_Bottom: - if (pPosY == NULL) { + if (!pPosY) pPosX = NewEnumValue(pStaticStore, pValue->eName); - } break; case FDE_CSSPROPERTYVALUE_Center: - if (pPosX == NULL) { + if (!pPosX) pPosX = NewEnumValue(pStaticStore, pValue->eName); - } else if (pPosY == NULL) { + else if (!pPosY) pPosX = NewEnumValue(pStaticStore, pValue->eName); - } break; default: break; @@ -929,15 +914,15 @@ FX_BOOL CFDE_CSSDeclaration::ParseBackgroundProperty( } const FDE_CSSCOLORTABLE* pColorItem = FDE_GetCSSColorByName(CFX_WideStringC(pszValue, iValueLen)); - if (pColorItem != NULL) { - if (pColor == NULL) { + if (pColorItem) { + if (!pColor) { pColor = FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue(pColorItem->dwValue); } } } break; case FDE_CSSPRIMITIVETYPE_RGB: - if (pColor == NULL) { + if (!pColor) { FX_ARGB dwColor; if (FDE_ParseCSSColor(pszValue, iValueLen, dwColor)) { pColor = @@ -949,22 +934,22 @@ FX_BOOL CFDE_CSSDeclaration::ParseBackgroundProperty( break; } } - if (pColor == NULL) { + if (!pColor) { pColor = FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue((FX_ARGB)0); } - if (pImage == NULL) { + if (!pImage) pImage = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_None); - } - if (pRepeat == NULL) { + + if (!pRepeat) pRepeat = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Repeat); - } - if (pAttachment == NULL) { + + if (!pAttachment) pAttachment = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Scroll); - } - if (pPosX == NULL) { + + if (!pPosX) { pPosX = NewNumberValue(pStaticStore, FDE_CSSPRIMITIVETYPE_Number, 0.0f); pPosY = NewNumberValue(pStaticStore, FDE_CSSPRIMITIVETYPE_Number, 0.0f); - } else if (pPosY == NULL) { + } else if (!pPosY) { pPosY = NewNumberValue(pStaticStore, FDE_CSSPRIMITIVETYPE_Number, 0.0f); } CFDE_CSSValueArray position; @@ -990,8 +975,11 @@ FX_BOOL CFDE_CSSDeclaration::ParseFontProperty(const FDE_CSSPROPERTYARGS* pArgs, FX_BOOL bImportant) { IFX_MemoryAllocator* pStaticStore = pArgs->pStaticStore; CFDE_CSSValueListParser parser(pszValue, iValueLen, '/'); - IFDE_CSSPrimitiveValue *pStyle = NULL, *pVariant = NULL, *pWeight = NULL; - IFDE_CSSPrimitiveValue *pFontSize = NULL, *pLineHeight = NULL; + IFDE_CSSPrimitiveValue* pStyle = nullptr; + IFDE_CSSPrimitiveValue* pVariant = nullptr; + IFDE_CSSPrimitiveValue* pWeight = nullptr; + IFDE_CSSPrimitiveValue* pFontSize = nullptr; + IFDE_CSSPrimitiveValue* pLineHeight = nullptr; CFDE_CSSValueArray familyList; FDE_CSSPRIMITIVETYPE eType; while (parser.NextValue(eType, pszValue, iValueLen)) { @@ -999,7 +987,7 @@ FX_BOOL CFDE_CSSDeclaration::ParseFontProperty(const FDE_CSSPROPERTYARGS* pArgs, case FDE_CSSPRIMITIVETYPE_String: { const FDE_CSSPROPERTYVALUETABLE* pValue = FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); - if (pValue != NULL) { + if (pValue) { switch (pValue->eName) { case FDE_CSSPROPERTYVALUE_XxSmall: case FDE_CSSPROPERTYVALUE_XSmall: @@ -1010,46 +998,41 @@ FX_BOOL CFDE_CSSDeclaration::ParseFontProperty(const FDE_CSSPROPERTYARGS* pArgs, case FDE_CSSPROPERTYVALUE_XxLarge: case FDE_CSSPROPERTYVALUE_Smaller: case FDE_CSSPROPERTYVALUE_Larger: - if (pFontSize == NULL) { + if (!pFontSize) pFontSize = NewEnumValue(pStaticStore, pValue->eName); - } continue; case FDE_CSSPROPERTYVALUE_Bold: case FDE_CSSPROPERTYVALUE_Bolder: case FDE_CSSPROPERTYVALUE_Lighter: - if (pWeight == NULL) { + if (!pWeight) pWeight = NewEnumValue(pStaticStore, pValue->eName); - } continue; case FDE_CSSPROPERTYVALUE_Italic: case FDE_CSSPROPERTYVALUE_Oblique: - if (pStyle == NULL) { + if (!pStyle) pStyle = NewEnumValue(pStaticStore, pValue->eName); - } continue; case FDE_CSSPROPERTYVALUE_SmallCaps: - if (pVariant == NULL) { + if (!pVariant) pVariant = NewEnumValue(pStaticStore, pValue->eName); - } continue; case FDE_CSSPROPERTYVALUE_Normal: - if (pStyle == NULL) { + if (!pStyle) pStyle = NewEnumValue(pStaticStore, pValue->eName); - } else if (pVariant == NULL) { + else if (!pVariant) pVariant = NewEnumValue(pStaticStore, pValue->eName); - } else if (pWeight == NULL) { + else if (!pWeight) pWeight = NewEnumValue(pStaticStore, pValue->eName); - } else if (pFontSize == NULL) { + else if (!pFontSize) pFontSize = NewEnumValue(pStaticStore, pValue->eName); - } else if (pLineHeight == NULL) { + else if (!pLineHeight) pLineHeight = NewEnumValue(pStaticStore, pValue->eName); - } continue; default: break; } } - if (pFontSize != NULL) { + if (pFontSize) { familyList.Add(FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue( eType, CopyToLocal(pArgs, pszValue, iValueLen))); } @@ -1071,38 +1054,33 @@ FX_BOOL CFDE_CSSDeclaration::ParseFontProperty(const FDE_CSSPROPERTYARGS* pArgs, case 700: case 800: case 900: - if (pWeight == NULL) { + if (!pWeight) { pWeight = NewNumberValue(pStaticStore, FDE_CSSPRIMITIVETYPE_Number, fValue); } continue; } } - if (pFontSize == NULL) { + if (!pFontSize) pFontSize = NewNumberValue(pStaticStore, eType, fValue); - } else if (pLineHeight == NULL) { + else if (!pLineHeight) pLineHeight = NewNumberValue(pStaticStore, eType, fValue); - } } break; default: break; } } - if (pStyle == NULL) { + if (!pStyle) pStyle = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Normal); - } - if (pVariant == NULL) { + if (!pVariant) pVariant = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Normal); - } - if (pWeight == NULL) { + if (!pWeight) pWeight = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Normal); - } - if (pFontSize == NULL) { + if (!pFontSize) pFontSize = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Medium); - } - if (pLineHeight == NULL) { + if (!pLineHeight) pLineHeight = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Normal); - } + AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_FontStyle, pStyle, bImportant); AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_FontVariant, pVariant, @@ -1128,16 +1106,16 @@ FX_BOOL CFDE_CSSDeclaration::ParseColumnRuleProperty( FX_BOOL bImportant) { IFX_MemoryAllocator* pStaticStore = pArgs->pStaticStore; CFDE_CSSValueListParser parser(pszValue, iValueLen, ' '); - IFDE_CSSPrimitiveValue* pColumnRuleWidth = NULL; - IFDE_CSSPrimitiveValue* pColumnRuleStyle = NULL; - IFDE_CSSPrimitiveValue* pColumnRuleColor = NULL; + IFDE_CSSPrimitiveValue* pColumnRuleWidth = nullptr; + IFDE_CSSPrimitiveValue* pColumnRuleStyle = nullptr; + IFDE_CSSPrimitiveValue* pColumnRuleColor = nullptr; FDE_CSSPRIMITIVETYPE eType; while (parser.NextValue(eType, pszValue, iValueLen)) { switch (eType) { case FDE_CSSPRIMITIVETYPE_String: { const FDE_CSSPROPERTYVALUETABLE* pValue = FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); - if (pValue != NULL) { + if (pValue) { switch (pValue->eName) { case FDE_CSSPROPERTYVALUE_None: case FDE_CSSPROPERTYVALUE_Hidden: @@ -1149,21 +1127,18 @@ FX_BOOL CFDE_CSSDeclaration::ParseColumnRuleProperty( case FDE_CSSPROPERTYVALUE_Ridge: case FDE_CSSPROPERTYVALUE_Inset: case FDE_CSSPROPERTYVALUE_Outset: - if (pColumnRuleStyle == NULL) { + if (!pColumnRuleStyle) pColumnRuleStyle = NewEnumValue(pStaticStore, pValue->eName); - } break; case FDE_CSSPROPERTYVALUE_Transparent: - if (pColumnRuleColor == NULL) { + if (!pColumnRuleColor) pColumnRuleColor = NewEnumValue(pStaticStore, pValue->eName); - } break; case FDE_CSSPROPERTYVALUE_Thin: case FDE_CSSPROPERTYVALUE_Medium: case FDE_CSSPROPERTYVALUE_Thick: - if (pColumnRuleWidth == NULL) { + if (!pColumnRuleWidth) pColumnRuleWidth = NewEnumValue(pStaticStore, pValue->eName); - } break; default: break; @@ -1172,7 +1147,7 @@ FX_BOOL CFDE_CSSDeclaration::ParseColumnRuleProperty( } FX_ARGB dwColor; if (FDE_ParseCSSColor(pszValue, iValueLen, dwColor) && - pColumnRuleColor == NULL) { + !pColumnRuleColor) { pColumnRuleColor = FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue((FX_ARGB)dwColor); continue; @@ -1181,13 +1156,13 @@ FX_BOOL CFDE_CSSDeclaration::ParseColumnRuleProperty( case FDE_CSSPRIMITIVETYPE_Number: { FX_FLOAT fValue; if (FDE_ParseCSSNumber(pszValue, iValueLen, fValue, eType) && - pColumnRuleWidth == NULL) { + !pColumnRuleWidth) { pColumnRuleWidth = NewNumberValue(pStaticStore, eType, fValue); } } break; case FDE_CSSPRIMITIVETYPE_RGB: { FX_ARGB dwColor; - if (pColumnRuleColor == NULL && + if (!pColumnRuleColor && FDE_ParseCSSColor(pszValue, iValueLen, dwColor)) { pColumnRuleColor = FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue((FX_ARGB)dwColor); @@ -1197,17 +1172,14 @@ FX_BOOL CFDE_CSSDeclaration::ParseColumnRuleProperty( break; } } - if (pColumnRuleColor == NULL && pColumnRuleStyle == NULL && - pColumnRuleWidth == NULL) { + if (!pColumnRuleColor && !pColumnRuleStyle && !pColumnRuleWidth) return FALSE; - } - if (pColumnRuleStyle == NULL) { + + if (!pColumnRuleStyle) pColumnRuleStyle = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_None); - } - if (pColumnRuleWidth == NULL) { + if (!pColumnRuleWidth) pColumnRuleWidth = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Medium); - } - if (pColumnRuleColor == NULL) { + if (!pColumnRuleColor) { pColumnRuleColor = FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue((FX_ARGB)0); } @@ -1228,13 +1200,13 @@ FX_BOOL CFDE_CSSDeclaration::ParseTextEmphasisProperty( CFDE_CSSValueListParser parser(pszValue, iValueLen, ' '); CFDE_CSSValueArray arrEmphasisStyle; FDE_CSSPRIMITIVETYPE eType; - IFDE_CSSPrimitiveValue* pEmphasisColor = NULL; + IFDE_CSSPrimitiveValue* pEmphasisColor = nullptr; while (parser.NextValue(eType, pszValue, iValueLen)) { switch (eType) { case FDE_CSSPRIMITIVETYPE_String: { const FDE_CSSPROPERTYVALUETABLE* pValue = FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); - if (pValue != NULL) { + if (pValue) { arrEmphasisStyle.Add(NewEnumValue(pStaticStore, pValue->eName)); continue; } @@ -1266,7 +1238,7 @@ FX_BOOL CFDE_CSSDeclaration::ParseTextEmphasisProperty( CFDE_CSSValueList(pStaticStore, arrEmphasisStyle), bImportant); } - if (pEmphasisColor != NULL) { + if (pEmphasisColor) { AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_TextEmphasisColor, pEmphasisColor, bImportant); } @@ -1279,15 +1251,15 @@ FX_BOOL CFDE_CSSDeclaration::ParseColumnsProperty( FX_BOOL bImportant) { IFX_MemoryAllocator* pStaticStore = pArgs->pStaticStore; CFDE_CSSValueListParser parser(pszValue, iValueLen, ' '); - IFDE_CSSPrimitiveValue* pColumnWidth = NULL; - IFDE_CSSPrimitiveValue* pColumnCount = NULL; + IFDE_CSSPrimitiveValue* pColumnWidth = nullptr; + IFDE_CSSPrimitiveValue* pColumnCount = nullptr; FDE_CSSPRIMITIVETYPE eType; while (parser.NextValue(eType, pszValue, iValueLen)) { switch (eType) { case FDE_CSSPRIMITIVETYPE_String: { const FDE_CSSPROPERTYVALUETABLE* pValue = FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); - if (pValue == NULL && pValue->eName == FDE_CSSPROPERTYVALUE_Auto) { + if (!pValue && pValue->eName == FDE_CSSPROPERTYVALUE_Auto) { pColumnWidth = NewEnumValue(pStaticStore, pValue->eName); } } break; @@ -1296,14 +1268,12 @@ FX_BOOL CFDE_CSSDeclaration::ParseColumnsProperty( if (FDE_ParseCSSNumber(pszValue, iValueLen, fValue, eType)) { switch (eType) { case FDE_CSSPRIMITIVETYPE_Number: - if (pColumnCount == NULL) { + if (!pColumnCount) pColumnCount = NewNumberValue(pStaticStore, eType, fValue); - } break; default: - if (pColumnWidth == NULL) { + if (!pColumnWidth) pColumnWidth = NewNumberValue(pStaticStore, eType, fValue); - } break; } } @@ -1312,13 +1282,14 @@ FX_BOOL CFDE_CSSDeclaration::ParseColumnsProperty( break; } } - if (pColumnWidth == NULL && pColumnCount == NULL) { + if (!pColumnWidth && !pColumnCount) return FALSE; - } else if (pColumnWidth == NULL) { + + if (!pColumnWidth) pColumnWidth = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Auto); - } else if (pColumnCount == NULL) { + else if (!pColumnCount) pColumnCount = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Auto); - } + AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_ColumnWidth, pColumnWidth, bImportant); AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_ColumnCount, pColumnCount, @@ -1332,14 +1303,14 @@ FX_BOOL CFDE_CSSDeclaration::ParseOverflowProperty( FX_BOOL bImportant) { IFX_MemoryAllocator* pStaticStore = pArgs->pStaticStore; CFDE_CSSValueListParser parser(pszValue, iValueLen, ' '); - IFDE_CSSPrimitiveValue* pOverflowX = NULL; - IFDE_CSSPrimitiveValue* pOverflowY = NULL; + IFDE_CSSPrimitiveValue* pOverflowX = nullptr; + IFDE_CSSPrimitiveValue* pOverflowY = nullptr; FDE_CSSPRIMITIVETYPE eType; while (parser.NextValue(eType, pszValue, iValueLen)) { if (eType == FDE_CSSPRIMITIVETYPE_String) { const FDE_CSSPROPERTYVALUETABLE* pValue = FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); - if (pValue != NULL) { + if (pValue) { switch (pValue->eName) { case FDE_CSSOVERFLOW_Visible: case FDE_CSSOVERFLOW_Hidden: @@ -1347,11 +1318,11 @@ FX_BOOL CFDE_CSSDeclaration::ParseOverflowProperty( case FDE_CSSOVERFLOW_Auto: case FDE_CSSOVERFLOW_NoDisplay: case FDE_CSSOVERFLOW_NoContent: - if (pOverflowX != NULL && pOverflowY != NULL) { + if (pOverflowX && pOverflowY) return FALSE; - } else if (pOverflowX == NULL) { + if (!pOverflowX) { pOverflowX = NewEnumValue(pStaticStore, pValue->eName); - } else if (pOverflowY == NULL) { + } else if (!pOverflowY) { pOverflowY = NewEnumValue(pStaticStore, pValue->eName); } break; @@ -1361,11 +1332,12 @@ FX_BOOL CFDE_CSSDeclaration::ParseOverflowProperty( } } } - if (pOverflowX == NULL && pOverflowY == NULL) { + if (!pOverflowX && !pOverflowY) return FALSE; - } else if (pOverflowY == NULL) { + + if (!pOverflowY) pOverflowY = NewEnumValue(pStaticStore, pOverflowX->GetEnum()); - } + AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_OverflowX, pOverflowX, bImportant); AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_OverflowY, pOverflowY, diff --git a/xfa/fde/css/fde_cssstyleselector.cpp b/xfa/fde/css/fde_cssstyleselector.cpp index 12f6bc9879..007657d154 100644 --- a/xfa/fde/css/fde_cssstyleselector.cpp +++ b/xfa/fde/css/fde_cssstyleselector.cpp @@ -28,9 +28,9 @@ int32_t CFDE_CSSCounterStyle::FindIndex(const FX_WCHAR* pszIdentifier) { return -1; } void CFDE_CSSCounterStyle::DoUpdateIndex(IFDE_CSSValueList* pList) { - if (pList == NULL) { + if (!pList) return; - } + int32_t iCount = pList->CountValues(); FX_FLOAT fDefValue = 1.0; FX_BOOL bDefIncrement = TRUE; @@ -87,10 +87,10 @@ void CFDE_CSSCounterStyle::UpdateIndex() { FDE_CSSRuleData::FDE_CSSRuleData(CFDE_CSSSelector* pSel, CFDE_CSSDeclaration* pDecl, uint32_t dwPos) - : pSelector(pSel), pDeclaration(pDecl), dwPriority(dwPos), pNext(NULL) { + : pSelector(pSel), pDeclaration(pDecl), dwPriority(dwPos), pNext(nullptr) { static const uint32_t s_Specific[5] = {0x00010000, 0x00010000, 0x00100000, 0x00100000, 0x01000000}; - for (; pSel != NULL; pSel = pSel->GetNextSelector()) { + for (; pSel; pSel = pSel->GetNextSelector()) { FDE_CSSSELECTORTYPE eType = pSel->GetType(); if (eType > FDE_CSSSELECTORTYPE_Descendant || pSel->GetNameHash() != FDE_CSSUNIVERSALHASH) { @@ -102,8 +102,8 @@ void CFDE_CSSRuleCollection::Clear() { m_IDRules.RemoveAll(); m_TagRules.RemoveAll(); m_ClassRules.RemoveAll(); - m_pUniversalRules = NULL; - m_pStaticStore = NULL; + m_pUniversalRules = nullptr; + m_pStaticStore = nullptr; m_iSelectors = 0; } void CFDE_CSSRuleCollection::AddRulesFrom(const CFDE_CSSStyleSheetArray& sheets, @@ -185,7 +185,7 @@ void CFDE_CSSRuleCollection::AddRuleTo(CFX_MapPtrToPtr& map, CFDE_CSSDeclaration* pDecl) { void* pKey = (void*)(uintptr_t)dwKey; FDE_CSSRuleData* pData = NewRuleData(pSel, pDecl); - FDE_CSSRuleData* pList = NULL; + FDE_CSSRuleData* pList = nullptr; if (!map.Lookup(pKey, (void*&)pList)) { map.SetAt(pKey, pData); } else if (AddRuleTo(pList, pData)) { @@ -213,12 +213,12 @@ FDE_CSSRuleData* CFDE_CSSRuleCollection::NewRuleData( } CFDE_CSSStyleSelector::CFDE_CSSStyleSelector() - : m_pFontMgr(NULL), + : m_pFontMgr(nullptr), m_fDefFontSize(12.0f), - m_pRuleDataStore(NULL), - m_pInlineStyleStore(NULL), - m_pFixedStyleStore(NULL), - m_pAccelerator(NULL) { + m_pRuleDataStore(nullptr), + m_pInlineStyleStore(nullptr), + m_pFixedStyleStore(nullptr), + m_pAccelerator(nullptr) { m_ePriorities[FDE_CSSSTYLESHEETPRIORITY_High] = FDE_CSSSTYLESHEETGROUP_Author; m_ePriorities[FDE_CSSSTYLESHEETPRIORITY_Mid] = FDE_CSSSTYLESHEETGROUP_User; m_ePriorities[FDE_CSSSTYLESHEETPRIORITY_Low] = @@ -269,9 +269,8 @@ FX_BOOL CFDE_CSSStyleSelector::SetStyleSheet(FDE_CSSSTYLESHEETGROUP eType, ASSERT(eType < FDE_CSSSTYLESHEETGROUP_MAX); CFDE_CSSStyleSheetArray& dest = m_SheetGroups[eType]; dest.RemoveAt(0, dest.GetSize()); - if (pSheet != NULL) { + if (pSheet) dest.Add(pSheet); - } return TRUE; } FX_BOOL CFDE_CSSStyleSelector::SetStyleSheets( @@ -279,11 +278,10 @@ FX_BOOL CFDE_CSSStyleSelector::SetStyleSheets( const CFDE_CSSStyleSheetArray* pArray) { ASSERT(eType < FDE_CSSSTYLESHEETGROUP_MAX); CFDE_CSSStyleSheetArray& dest = m_SheetGroups[eType]; - if (pArray == NULL) { - dest.RemoveAt(0, dest.GetSize()); - } else { + if (pArray) dest.Copy(*pArray); - } + else + dest.RemoveAt(0, dest.GetSize()); return TRUE; } void CFDE_CSSStyleSelector::SetStylePriority( @@ -365,11 +363,11 @@ FX_BOOL CFDE_CSSStyleSelector::MatchSelector(FDE_CSSTagCache* pCache, CFDE_CSSSelector* pSel, FDE_CSSPERSUDO ePersudoType) { uint32_t dwHash; - while (pSel != NULL && pCache != NULL) { + while (pSel && pCache) { switch (pSel->GetType()) { case FDE_CSSSELECTORTYPE_Descendant: dwHash = pSel->GetNameHash(); - while ((pCache = pCache->GetParent()) != NULL) { + while ((pCache = pCache->GetParent()) != nullptr) { if (dwHash != FDE_CSSUNIVERSALHASH && dwHash != pCache->HashTag()) { continue; } @@ -408,7 +406,7 @@ FX_BOOL CFDE_CSSStyleSelector::MatchSelector(FDE_CSSTagCache* pCache, } pSel = pSel->GetNextSelector(); } - return pSel == NULL && pCache != NULL; + return !pSel && pCache; } void CFDE_CSSStyleSelector::ComputeStyle( @@ -484,16 +482,17 @@ void CFDE_CSSStyleSelector::ApplyDeclarations( FX_BOOL bImportant; int32_t i; if (bPriority) { - IFDE_CSSValue *pLastest = NULL, *pImportant = NULL; + IFDE_CSSValue* pLastest = nullptr; + IFDE_CSSValue* pImportant = nullptr; for (i = 0; i < iDeclCount; ++i) { pVal = ppDeclArray[i]->GetProperty(FDE_CSSPROPERTY_FontSize, bImportant); - if (pVal == NULL) { + if (!pVal) continue; - } else if (bImportant) { + + if (bImportant) pImportant = pVal; - } else { + else pLastest = pVal; - } } if (pImportant) { ApplyProperty(FDE_CSSPROPERTY_FontSize, pImportant, pComputedStyle); @@ -508,7 +507,7 @@ void CFDE_CSSStyleSelector::ApplyDeclarations( for (i = 0; i < iDeclCount; ++i) { pDecl = ppDeclArray[i]; pos = pDecl->GetStartPosition(); - while (pos != NULL) { + while (pos) { pDecl->GetNextProperty(pos, eProp, pVal, bImportant); if (eProp == FDE_CSSPROPERTY_FontSize) { continue; @@ -524,7 +523,7 @@ void CFDE_CSSStyleSelector::ApplyDeclarations( for (i = 0; i < iDeclCount; ++i) { pDecl = importants[i]; pos = pDecl->GetStartPosition(); - while (pos != NULL) { + while (pos) { pDecl->GetNextProperty(pos, eProp, pVal, bImportant); if (bImportant && eProp != FDE_CSSPROPERTY_FontSize) { ApplyProperty(eProp, pVal, pComputedStyle); @@ -960,7 +959,7 @@ void CFDE_CSSStyleSelector::ApplyProperty( break; case FDE_CSSPROPERTY_BackgroundImage: if (eType == FDE_CSSPRIMITIVETYPE_Enum) { - FDE_CSSNONINHERITS.m_pszBKGImage = NULL; + FDE_CSSNONINHERITS.m_pszBKGImage = nullptr; } else if (eType == FDE_CSSPRIMITIVETYPE_URI) { int32_t iLength; FDE_CSSNONINHERITS.m_pszBKGImage = pPrimitive->GetString(iLength); @@ -989,7 +988,7 @@ void CFDE_CSSStyleSelector::ApplyProperty( break; case FDE_CSSPROPERTY_ListStyleImage: if (eType == FDE_CSSPRIMITIVETYPE_Enum) { - FDE_CSSINHERITS.m_pszListStyleImage = NULL; + FDE_CSSINHERITS.m_pszListStyleImage = nullptr; } else if (eType == FDE_CSSPRIMITIVETYPE_URI) { int32_t iLength; FDE_CSSINHERITS.m_pszListStyleImage = pPrimitive->GetString(iLength); @@ -1046,15 +1045,13 @@ void CFDE_CSSStyleSelector::ApplyProperty( FDE_CSSNONINHERITS.m_dwTextDecoration = ToTextDecoration(pList); break; case FDE_CSSPROPERTY_CounterIncrement: { - if (FDE_CSSNONINHERITS.m_pCounterStyle == NULL) { + if (!FDE_CSSNONINHERITS.m_pCounterStyle) FDE_CSSNONINHERITS.m_pCounterStyle = new CFDE_CSSCounterStyle; - } FDE_CSSNONINHERITS.m_pCounterStyle->SetCounterIncrementList(pList); } break; case FDE_CSSPROPERTY_CounterReset: { - if (FDE_CSSNONINHERITS.m_pCounterStyle == NULL) { + if (!FDE_CSSNONINHERITS.m_pCounterStyle) FDE_CSSNONINHERITS.m_pCounterStyle = new CFDE_CSSCounterStyle; - } FDE_CSSNONINHERITS.m_pCounterStyle->SetCounterResetList(pList); } break; case FDE_CSSPROPERTY_Content: diff --git a/xfa/fde/css/fde_cssstyleselector.h b/xfa/fde/css/fde_cssstyleselector.h index 1b6d10c9f7..3af75a7b9e 100644 --- a/xfa/fde/css/fde_cssstyleselector.h +++ b/xfa/fde/css/fde_cssstyleselector.h @@ -51,19 +51,19 @@ class CFDE_CSSRuleCollection : public CFX_Target { void* pData; return m_IDRules.Lookup((void*)(uintptr_t)dwIDHash, pData) ? (FDE_CSSRuleData*)pData - : NULL; + : nullptr; } FDE_CSSRuleData* GetTagRuleData(uint32_t dwTagHasn) { void* pData; return m_TagRules.Lookup((void*)(uintptr_t)dwTagHasn, pData) ? (FDE_CSSRuleData*)pData - : NULL; + : nullptr; } FDE_CSSRuleData* GetClassRuleData(uint32_t dwIDHash) { void* pData; return m_ClassRules.Lookup((void*)(uintptr_t)dwIDHash, pData) ? (FDE_CSSRuleData*)pData - : NULL; + : nullptr; } FDE_CSSRuleData* GetUniversalRuleData() { return m_pUniversalRules; } FDE_CSSRuleData* GetPersudoRuleData() { return m_pPersudoRules; } diff --git a/xfa/fde/css/fde_cssstylesheet.cpp b/xfa/fde/css/fde_cssstylesheet.cpp index 1ea8d8061d..6708ca2e72 100644 --- a/xfa/fde/css/fde_cssstylesheet.cpp +++ b/xfa/fde/css/fde_cssstylesheet.cpp @@ -55,7 +55,7 @@ IFDE_CSSStyleSheet* IFDE_CSSStyleSheet::LoadFromStream( CFDE_CSSStyleSheet* pStyleSheet = new CFDE_CSSStyleSheet(dwMediaList); if (!pStyleSheet->LoadFromStream(szUrl, pStream, wCodePage)) { pStyleSheet->Release(); - pStyleSheet = NULL; + pStyleSheet = nullptr; } return pStyleSheet; } @@ -68,7 +68,7 @@ IFDE_CSSStyleSheet* IFDE_CSSStyleSheet::LoadFromBuffer( CFDE_CSSStyleSheet* pStyleSheet = new CFDE_CSSStyleSheet(dwMediaList); if (!pStyleSheet->LoadFromBuffer(szUrl, pBuffer, iBufSize, wCodePage)) { pStyleSheet->Release(); - pStyleSheet = NULL; + pStyleSheet = nullptr; } return pStyleSheet; } @@ -76,7 +76,7 @@ CFDE_CSSStyleSheet::CFDE_CSSStyleSheet(uint32_t dwMediaList) : m_wCodePage(FX_CODEPAGE_UTF8), m_wRefCount(1), m_dwMediaList(dwMediaList), - m_pAllocator(NULL) { + m_pAllocator(nullptr) { ASSERT(m_dwMediaList > 0); } CFDE_CSSStyleSheet::~CFDE_CSSStyleSheet() { @@ -181,7 +181,7 @@ FX_BOOL CFDE_CSSStyleSheet::LoadFromSyntax(CFDE_CSSSyntaxParser* pSyntax) { FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadMediaRule( CFDE_CSSSyntaxParser* pSyntax) { uint32_t dwMediaList = 0; - CFDE_CSSMediaRule* pMediaRule = NULL; + CFDE_CSSMediaRule* pMediaRule = nullptr; for (;;) { switch (pSyntax->DoSyntaxParse()) { case FDE_CSSSYNTAXSTATUS_MediaType: { @@ -189,23 +189,22 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadMediaRule( const FX_WCHAR* psz = pSyntax->GetCurrentString(iLen); FDE_LPCCSSMEDIATYPETABLE pMediaType = FDE_GetCSSMediaTypeByName(CFX_WideStringC(psz, iLen)); - if (pMediaType != NULL) { + if (pMediaType) dwMediaList |= pMediaType->wValue; - } } break; case FDE_CSSSYNTAXSTATUS_StyleRule: - if (pMediaRule == NULL) { - SkipRuleSet(pSyntax); - } else { + if (pMediaRule) { FDE_CSSSYNTAXSTATUS eStatus = LoadStyleRule(pSyntax, pMediaRule->GetArray()); if (eStatus < FDE_CSSSYNTAXSTATUS_None) { return eStatus; } + } else { + SkipRuleSet(pSyntax); } break; case FDE_CSSSYNTAXSTATUS_DeclOpen: - if ((dwMediaList & m_dwMediaList) > 0 && pMediaRule == NULL) { + if ((dwMediaList & m_dwMediaList) > 0 && !pMediaRule) { pMediaRule = FXTARGET_NewWith(m_pAllocator) CFDE_CSSMediaRule(dwMediaList); m_RuleArray.Add(pMediaRule); @@ -221,13 +220,13 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadStyleRule( CFDE_CSSSyntaxParser* pSyntax, CFDE_CSSRuleArray& ruleArray) { m_Selectors.RemoveAt(0, m_Selectors.GetSize()); - CFDE_CSSStyleRule* pStyleRule = NULL; - const FX_WCHAR* pszValue = NULL; + CFDE_CSSStyleRule* pStyleRule = nullptr; + const FX_WCHAR* pszValue = nullptr; int32_t iValueLen = 0; FDE_CSSPROPERTYARGS propertyArgs; propertyArgs.pStaticStore = m_pAllocator; propertyArgs.pStringCache = &m_StringCache; - propertyArgs.pProperty = NULL; + propertyArgs.pProperty = nullptr; CFX_WideString wsName; for (;;) { switch (pSyntax->DoSyntaxParse()) { @@ -235,20 +234,18 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadStyleRule( pszValue = pSyntax->GetCurrentString(iValueLen); CFDE_CSSSelector* pSelector = CFDE_CSSSelector::FromString(m_pAllocator, pszValue, iValueLen); - if (pSelector != NULL) { + if (pSelector) m_Selectors.Add(pSelector); - } } break; case FDE_CSSSYNTAXSTATUS_PropertyName: pszValue = pSyntax->GetCurrentString(iValueLen); propertyArgs.pProperty = FDE_GetCSSPropertyByName(CFX_WideStringC(pszValue, iValueLen)); - if (propertyArgs.pProperty == NULL) { + if (!propertyArgs.pProperty) wsName = CFX_WideStringC(pszValue, iValueLen); - } break; case FDE_CSSSYNTAXSTATUS_PropertyValue: - if (propertyArgs.pProperty != NULL) { + if (propertyArgs.pProperty) { pszValue = pSyntax->GetCurrentString(iValueLen); if (iValueLen > 0) { pStyleRule->GetDeclImp().AddProperty(&propertyArgs, pszValue, @@ -264,7 +261,7 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadStyleRule( } break; case FDE_CSSSYNTAXSTATUS_DeclOpen: - if (pStyleRule == NULL && m_Selectors.GetSize() > 0) { + if (!pStyleRule && m_Selectors.GetSize() > 0) { pStyleRule = FXTARGET_NewWith(m_pAllocator) CFDE_CSSStyleRule; pStyleRule->SetSelector(m_pAllocator, m_Selectors); ruleArray.Add(pStyleRule); @@ -274,8 +271,7 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadStyleRule( } break; case FDE_CSSSYNTAXSTATUS_DeclClose: - if (pStyleRule != NULL && - pStyleRule->GetDeclImp().GetStartPosition() == NULL) { + if (pStyleRule && !pStyleRule->GetDeclImp().GetStartPosition()) { pStyleRule->~CFDE_CSSStyleRule(); ruleArray.RemoveLast(1); } @@ -287,13 +283,13 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadStyleRule( FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadFontFaceRule( CFDE_CSSSyntaxParser* pSyntax, CFDE_CSSRuleArray& ruleArray) { - CFDE_CSSFontFaceRule* pFontFaceRule = NULL; - const FX_WCHAR* pszValue = NULL; + CFDE_CSSFontFaceRule* pFontFaceRule = nullptr; + const FX_WCHAR* pszValue = nullptr; int32_t iValueLen = 0; FDE_CSSPROPERTYARGS propertyArgs; propertyArgs.pStaticStore = m_pAllocator; propertyArgs.pStringCache = &m_StringCache; - propertyArgs.pProperty = NULL; + propertyArgs.pProperty = nullptr; for (;;) { switch (pSyntax->DoSyntaxParse()) { case FDE_CSSSYNTAXSTATUS_PropertyName: @@ -302,7 +298,7 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadFontFaceRule( FDE_GetCSSPropertyByName(CFX_WideStringC(pszValue, iValueLen)); break; case FDE_CSSSYNTAXSTATUS_PropertyValue: - if (propertyArgs.pProperty != NULL) { + if (propertyArgs.pProperty) { pszValue = pSyntax->GetCurrentString(iValueLen); if (iValueLen > 0) { pFontFaceRule->GetDeclImp().AddProperty(&propertyArgs, pszValue, @@ -311,7 +307,7 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadFontFaceRule( } break; case FDE_CSSSYNTAXSTATUS_DeclOpen: - if (pFontFaceRule == NULL) { + if (!pFontFaceRule) { pFontFaceRule = FXTARGET_NewWith(m_pAllocator) CFDE_CSSFontFaceRule; ruleArray.Add(pFontFaceRule); } @@ -355,7 +351,7 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::SkipRuleSet( } void CFDE_CSSStyleRule::SetSelector(IFX_MemoryAllocator* pStaticStore, const CFDE_CSSSelectorArray& list) { - ASSERT(m_ppSelector == NULL); + ASSERT(!m_ppSelector); m_iSelectors = list.GetSize(); m_ppSelector = static_cast( pStaticStore->Alloc(m_iSelectors * sizeof(CFDE_CSSSelector*))); @@ -409,7 +405,7 @@ CFDE_CSSSelector* CFDE_CSSSelector::FromString( IFX_MemoryAllocator* pStaticStore, const FX_WCHAR* psz, int32_t iLen) { - ASSERT(pStaticStore != NULL && psz != NULL && iLen > 0); + ASSERT(pStaticStore && psz && iLen > 0); const FX_WCHAR* pStart = psz; const FX_WCHAR* pEnd = psz + iLen; for (; psz < pEnd; ++psz) { @@ -417,38 +413,40 @@ CFDE_CSSSelector* CFDE_CSSSelector::FromString( case '>': case '[': case '+': - return NULL; + return nullptr; } } - CFDE_CSSSelector *pFirst = NULL, *pLast = NULL; - CFDE_CSSSelector *pPersudoFirst = NULL, *pPersudoLast = NULL; + CFDE_CSSSelector* pFirst = nullptr; + CFDE_CSSSelector* pLast = nullptr; + CFDE_CSSSelector* pPersudoFirst = nullptr; + CFDE_CSSSelector* pPersudoLast = nullptr; for (psz = pStart; psz < pEnd;) { FX_WCHAR wch = *psz; if (wch == '.' || wch == '#') { if (psz == pStart || psz[-1] == ' ') { CFDE_CSSSelector* p = FXTARGET_NewWith(pStaticStore) CFDE_CSSSelector(FDE_CSSSELECTORTYPE_Element, L"*", 1, true); - if (p == NULL) { - return NULL; - } - if (pFirst != NULL) { + if (!p) + return nullptr; + + if (pFirst) { pFirst->SetType(FDE_CSSSELECTORTYPE_Descendant); p->SetNext(pFirst); } pFirst = pLast = p; } - ASSERT(pLast != NULL); + ASSERT(pLast); int32_t iNameLen = FDE_GetCSSNameLen(++psz, pEnd); if (iNameLen == 0) { - return NULL; + return nullptr; } FDE_CSSSELECTORTYPE eType = wch == '.' ? FDE_CSSSELECTORTYPE_Class : FDE_CSSSELECTORTYPE_ID; CFDE_CSSSelector* p = FXTARGET_NewWith(pStaticStore) CFDE_CSSSelector(eType, psz, iNameLen, false); - if (p == NULL) { - return NULL; - } + if (!p) + return nullptr; + p->SetNext(pLast->GetNextSelector()); pLast->SetNext(p); pLast = p; @@ -456,48 +454,45 @@ CFDE_CSSSelector* CFDE_CSSSelector::FromString( } else if (FDE_IsCSSChar(wch) || wch == '*') { int32_t iNameLen = wch == '*' ? 1 : FDE_GetCSSNameLen(psz, pEnd); if (iNameLen == 0) { - return NULL; + return nullptr; } CFDE_CSSSelector* p = FXTARGET_NewWith(pStaticStore) CFDE_CSSSelector(FDE_CSSSELECTORTYPE_Element, psz, iNameLen, true); - if (p == NULL) { - return NULL; - } - if (pFirst == NULL) { - pFirst = pLast = p; - } else { + if (!p) + return nullptr; + + if (pFirst) { pFirst->SetType(FDE_CSSSELECTORTYPE_Descendant); p->SetNext(pFirst); - pFirst = pLast = p; } + pFirst = p; + pLast = p; psz += iNameLen; } else if (wch == ':') { int32_t iNameLen = FDE_GetCSSPersudoLen(psz, pEnd); if (iNameLen == 0) { - return NULL; + return nullptr; } CFDE_CSSSelector* p = FXTARGET_NewWith(pStaticStore) CFDE_CSSSelector(FDE_CSSSELECTORTYPE_Persudo, psz, iNameLen, true); - if (p == NULL) { - return NULL; - } - if (pPersudoFirst == NULL) { - pPersudoFirst = pPersudoLast = p; - } else { + if (!p) + return nullptr; + + if (pPersudoFirst) pPersudoLast->SetNext(p); - pPersudoLast = p; - } + else + pPersudoFirst = p; + pPersudoLast = p; psz += iNameLen; } else if (wch == ' ') { psz++; } else { - return NULL; + return nullptr; } } - if (pPersudoFirst == NULL) { + if (!pPersudoFirst) return pFirst; - } else { - pPersudoLast->SetNext(pFirst); - return pPersudoFirst; - } + + pPersudoLast->SetNext(pFirst); + return pPersudoFirst; } diff --git a/xfa/fde/css/fde_cssstylesheet.h b/xfa/fde/css/fde_cssstylesheet.h index 76eddda4a3..4c51579661 100644 --- a/xfa/fde/css/fde_cssstylesheet.h +++ b/xfa/fde/css/fde_cssstylesheet.h @@ -48,7 +48,7 @@ typedef CFX_ArrayTemplate CFDE_CSSSelectorArray; class CFDE_CSSStyleRule : public IFDE_CSSStyleRule, public CFX_Target { public: - CFDE_CSSStyleRule() : m_ppSelector(NULL), m_iSelectors(0) {} + CFDE_CSSStyleRule() : m_ppSelector(nullptr), m_iSelectors(0) {} int32_t CountSelectorLists() const override { return m_iSelectors; } CFDE_CSSSelector* GetSelectorList(int32_t index) const override { return m_ppSelector[index]; diff --git a/xfa/fde/css/fde_csssyntax.cpp b/xfa/fde/css/fde_csssyntax.cpp index 4583595686..4595396c13 100644 --- a/xfa/fde/css/fde_csssyntax.cpp +++ b/xfa/fde/css/fde_csssyntax.cpp @@ -9,21 +9,17 @@ #include "xfa/fde/css/fde_cssdatatable.h" #include "xfa/fgas/crt/fgas_codepage.h" -#ifdef _cplusplus -extern "C" { -#endif +namespace { -inline FX_BOOL FDE_IsSelectorStart(FX_WCHAR wch) { +bool FDE_IsSelectorStart(FX_WCHAR wch) { return wch == '.' || wch == '#' || wch == '*' || (wch >= 'a' && wch <= 'z') || (wch >= 'A' && wch <= 'Z'); } -#ifdef _cplusplus -}; -#endif +} // namespace CFDE_CSSSyntaxParser::CFDE_CSSSyntaxParser() - : m_pStream(NULL), + : m_pStream(nullptr), m_iStreamPos(0), m_iPlaneSize(0), m_iTextDatLen(0), @@ -38,7 +34,7 @@ FX_BOOL CFDE_CSSSyntaxParser::Init(IFX_Stream* pStream, int32_t iCSSPlaneSize, int32_t iTextDataSize, FX_BOOL bOnlyDeclaration) { - ASSERT(pStream != NULL && iCSSPlaneSize > 0 && iTextDataSize > 0); + ASSERT(pStream && iCSSPlaneSize > 0 && iTextDataSize > 0); Reset(bOnlyDeclaration); if (!m_TextData.EstimateSize(iTextDataSize)) { return FALSE; @@ -53,7 +49,7 @@ FX_BOOL CFDE_CSSSyntaxParser::Init(const FX_WCHAR* pBuffer, int32_t iBufferSize, int32_t iTextDatSize, FX_BOOL bOnlyDeclaration) { - ASSERT(pBuffer != NULL && iBufferSize > 0 && iTextDatSize > 0); + ASSERT(pBuffer && iBufferSize > 0 && iTextDatSize > 0); Reset(bOnlyDeclaration); if (!m_TextData.EstimateSize(iTextDatSize)) { return FALSE; @@ -63,7 +59,7 @@ FX_BOOL CFDE_CSSSyntaxParser::Init(const FX_WCHAR* pBuffer, void CFDE_CSSSyntaxParser::Reset(FX_BOOL bOnlyDeclaration) { m_TextPlane.Reset(); m_TextData.Reset(); - m_pStream = NULL; + m_pStream = nullptr; m_iStreamPos = 0; m_iTextDatLen = 0; m_dwCheck = (uint32_t)-1; @@ -74,7 +70,7 @@ void CFDE_CSSSyntaxParser::Reset(FX_BOOL bOnlyDeclaration) { FDE_CSSSYNTAXSTATUS CFDE_CSSSyntaxParser::DoSyntaxParse() { while (m_eStatus >= FDE_CSSSYNTAXSTATUS_None) { if (m_TextPlane.IsEOF()) { - if (m_pStream == NULL) { + if (!m_pStream) { if (m_eMode == FDE_CSSSYNTAXMODE_PropertyValue && m_TextData.GetLength() > 0) { SaveTextData(); @@ -228,9 +224,9 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSSyntaxParser::DoSyntaxParse() { break; case '{': { FDE_CSSSYNTAXMODE* pMode = m_ModeStack.GetTopElement(); - if (pMode == NULL || *pMode != FDE_CSSSYNTAXMODE_MediaRule) { + if (!pMode || *pMode != FDE_CSSSYNTAXMODE_MediaRule) return m_eStatus = FDE_CSSSYNTAXSTATUS_Error; - } + if (m_TextData.GetLength() > 0) { SaveTextData(); return FDE_CSSSYNTAXSTATUS_MediaType; @@ -243,9 +239,9 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSSyntaxParser::DoSyntaxParse() { } break; case ';': { FDE_CSSSYNTAXMODE* pMode = m_ModeStack.GetTopElement(); - if (pMode == NULL || *pMode != FDE_CSSSYNTAXMODE_Import) { + if (!pMode || *pMode != FDE_CSSSYNTAXMODE_Import) return m_eStatus = FDE_CSSSYNTAXSTATUS_Error; - } + if (m_TextData.GetLength() > 0) { SaveTextData(); if (IsImportEnabled()) { @@ -276,9 +272,9 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSSyntaxParser::DoSyntaxParse() { break; case FDE_CSSSYNTAXMODE_URI: { FDE_CSSSYNTAXMODE* pMode = m_ModeStack.GetTopElement(); - if (pMode == NULL || *pMode != FDE_CSSSYNTAXMODE_Import) { + if (!pMode || *pMode != FDE_CSSSYNTAXMODE_Import) return m_eStatus = FDE_CSSSYNTAXSTATUS_Error; - } + if (wch <= ' ' || wch == ';') { int32_t iURIStart, iURILength = m_TextData.GetLength(); if (iURILength > 0 && @@ -333,7 +329,7 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSSyntaxParser::DoSyntaxParse() { if (IsCharsetEnabled()) { DisableCharset(); if (m_iTextDatLen > 0) { - if (m_pStream != NULL) { + if (m_pStream) { uint16_t wCodePage = FX_GetCodePageFromStringW( m_TextData.GetBuffer(), m_iTextDatLen); if (wCodePage < 0xFFFF && @@ -371,7 +367,7 @@ FX_BOOL CFDE_CSSSyntaxParser::IsImportEnabled() const { } return TRUE; } -inline FX_BOOL CFDE_CSSSyntaxParser::AppendChar(FX_WCHAR wch) { +FX_BOOL CFDE_CSSSyntaxParser::AppendChar(FX_WCHAR wch) { m_TextPlane.MoveNext(); if (m_TextData.GetLength() > 0 || wch > ' ') { m_TextData.AppendChar(wch); @@ -379,26 +375,26 @@ inline FX_BOOL CFDE_CSSSyntaxParser::AppendChar(FX_WCHAR wch) { } return FALSE; } -inline int32_t CFDE_CSSSyntaxParser::SaveTextData() { +int32_t CFDE_CSSSyntaxParser::SaveTextData() { m_iTextDatLen = m_TextData.TrimEnd(); m_TextData.Clear(); return m_iTextDatLen; } -inline void CFDE_CSSSyntaxParser::SwitchMode(FDE_CSSSYNTAXMODE eMode) { +void CFDE_CSSSyntaxParser::SwitchMode(FDE_CSSSYNTAXMODE eMode) { m_eMode = eMode; SaveTextData(); } -inline int32_t CFDE_CSSSyntaxParser::SwitchToComment() { +int32_t CFDE_CSSSyntaxParser::SwitchToComment() { int32_t iLength = m_TextData.GetLength(); m_ModeStack.Push(m_eMode); SwitchMode(FDE_CSSSYNTAXMODE_Comment); return iLength; } -inline FX_BOOL CFDE_CSSSyntaxParser::RestoreMode() { +FX_BOOL CFDE_CSSSyntaxParser::RestoreMode() { FDE_CSSSYNTAXMODE* pMode = m_ModeStack.GetTopElement(); - if (pMode == NULL) { + if (!pMode) return FALSE; - } + SwitchMode(*pMode); m_ModeStack.Pop(); return TRUE; @@ -409,7 +405,7 @@ const FX_WCHAR* CFDE_CSSSyntaxParser::GetCurrentString(int32_t& iLength) const { } CFDE_CSSTextBuf::CFDE_CSSTextBuf() : m_bExtBuf(FALSE), - m_pBuffer(NULL), + m_pBuffer(nullptr), m_iBufLen(0), m_iDatLen(0), m_iDatPos(0) {} @@ -419,7 +415,7 @@ CFDE_CSSTextBuf::~CFDE_CSSTextBuf() { void CFDE_CSSTextBuf::Reset() { if (!m_bExtBuf) { FX_Free(m_pBuffer); - m_pBuffer = NULL; + m_pBuffer = nullptr; } m_iDatPos = m_iDatLen = m_iBufLen; } -- cgit v1.2.3