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_CSSVALUELISTPARSER_H_ 8 #define CORE_FXCRT_CSS_CFX_CSSVALUELISTPARSER_H_ 9 10 #include <stdint.h> 11 12 #include <optional> 13 14 #include "core/fxcrt/css/cfx_cssvalue.h" 15 #include "core/fxcrt/widestring.h" 16 17 class CFX_CSSValueListParser { 18 public: 19 struct Result { 20 CFX_CSSValue::PrimitiveType type = CFX_CSSValue::PrimitiveType::kUnknown; 21 WideStringView string_view; 22 }; 23 24 CFX_CSSValueListParser(WideStringView list, wchar_t separator); 25 ~CFX_CSSValueListParser(); 26 27 std::optional<Result> NextValue(); UseCommaSeparator()28 void UseCommaSeparator() { m_Separator = ','; } 29 30 private: CharsRemain()31 bool CharsRemain() const { return !m_Cur.IsEmpty(); } 32 33 // Safe to call even when input exhausted, stays unchanged. Advance()34 void Advance() { m_Cur = m_Cur.Substr(1); } 35 36 // Safe to call even when input exhausted, returns NUL. CurrentChar()37 wchar_t CurrentChar() const { return static_cast<wchar_t>(m_Cur.Front()); } 38 39 size_t SkipToChar(wchar_t wch); 40 size_t SkipToCharMatchingParens(wchar_t wch); 41 42 WideStringView m_Cur; 43 wchar_t m_Separator; 44 }; 45 46 #endif // CORE_FXCRT_CSS_CFX_CSSVALUELISTPARSER_H_ 47