• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef CORE_FXCRT_CSS_CFX_CSSSYNTAXPARSER_H_
8 #define CORE_FXCRT_CSS_CFX_CSSSYNTAXPARSER_H_
9 
10 #include <stack>
11 
12 #include "core/fxcrt/css/cfx_cssexttextbuf.h"
13 #include "core/fxcrt/css/cfx_csstextbuf.h"
14 #include "core/fxcrt/fx_string.h"
15 
16 #define CFX_CSSSYNTAXCHECK_AllowCharset 1
17 #define CFX_CSSSYNTAXCHECK_AllowImport 2
18 
19 enum class CFX_CSSSyntaxMode {
20   RuleSet,
21   Comment,
22   UnknownRule,
23   Selector,
24   PropertyName,
25   PropertyValue,
26 };
27 
28 enum class CFX_CSSSyntaxStatus : uint8_t {
29   Error,
30   EOS,
31   None,
32   StyleRule,
33   Selector,
34   DeclOpen,
35   DeclClose,
36   PropertyName,
37   PropertyValue,
38 };
39 
40 class CFX_CSSSyntaxParser {
41  public:
42   CFX_CSSSyntaxParser(const wchar_t* pBuffer, int32_t iBufferSize);
43   CFX_CSSSyntaxParser(const wchar_t* pBuffer,
44                       int32_t iBufferSize,
45                       int32_t iTextDatSize,
46                       bool bOnlyDeclaration);
47   ~CFX_CSSSyntaxParser();
48 
49   CFX_CSSSyntaxStatus DoSyntaxParse();
50   WideStringView GetCurrentString() const;
51 
52  protected:
53   void SwitchMode(CFX_CSSSyntaxMode eMode);
54   int32_t SwitchToComment();
55 
56   bool RestoreMode();
57   bool AppendChar(wchar_t wch);
58   int32_t SaveTextData();
IsCharsetEnabled()59   bool IsCharsetEnabled() const {
60     return (m_dwCheck & CFX_CSSSYNTAXCHECK_AllowCharset) != 0;
61   }
DisableCharset()62   void DisableCharset() { m_dwCheck = CFX_CSSSYNTAXCHECK_AllowImport; }
63   bool IsImportEnabled() const;
DisableImport()64   void DisableImport() { m_dwCheck = 0; }
65 
66   CFX_CSSTextBuf m_TextData;
67   CFX_CSSExtTextBuf m_TextPlane;
68   int32_t m_iTextDataLen;
69   uint32_t m_dwCheck;
70   CFX_CSSSyntaxMode m_eMode;
71   CFX_CSSSyntaxStatus m_eStatus;
72   std::stack<CFX_CSSSyntaxMode> m_ModeStack;
73 };
74 
75 #endif  // CORE_FXCRT_CSS_CFX_CSSSYNTAXPARSER_H_
76