1 // Copyright 2017 The PDFium Authors 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_cssinputtextbuf.h" 13 #include "core/fxcrt/css/cfx_cssoutputtextbuf.h" 14 #include "core/fxcrt/widestring.h" 15 16 class CFX_CSSSyntaxParser { 17 public: 18 enum class Status : uint8_t { 19 kError, 20 kEOS, 21 kNone, 22 kStyleRule, 23 kSelector, 24 kDeclOpen, 25 kDeclClose, 26 kPropertyName, 27 kPropertyValue, 28 }; 29 30 explicit CFX_CSSSyntaxParser(WideStringView str); 31 ~CFX_CSSSyntaxParser(); 32 33 void SetParseOnlyDeclarations(); 34 Status DoSyntaxParse(); 35 WideStringView GetCurrentString() const; 36 37 private: 38 enum class Mode : uint8_t { 39 kRuleSet, 40 kComment, 41 kSelector, 42 kPropertyName, 43 kPropertyValue, 44 }; 45 46 void SaveMode(Mode eMode); 47 bool RestoreMode(); 48 49 bool m_bHasError = false; 50 Mode m_eMode = Mode::kRuleSet; 51 CFX_CSSOutputTextBuf m_Output; 52 CFX_CSSInputTextBuf m_Input; 53 std::stack<Mode> m_ModeStack; 54 }; 55 56 #endif // CORE_FXCRT_CSS_CFX_CSSSYNTAXPARSER_H_ 57