diff options
Diffstat (limited to 'xfa/fde/css/fde_cssstylesheet.cpp')
-rw-r--r-- | xfa/fde/css/fde_cssstylesheet.cpp | 121 |
1 files changed, 58 insertions, 63 deletions
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<CFDE_CSSSelector**>( 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; } |