libhtmlpp 1.0.0
Loading...
Searching...
No Matches
css.h
Go to the documentation of this file.
1/*******************************************************************************
2Copyright (c) 2021, Jan Koester jan.koester@gmx.net
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the <organization> nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*******************************************************************************/
27
28#pragma once
29
30#include <string>
31#include <vector>
32#include <memory>
33
34namespace libhtmlpp {
35
37 public:
39 CSSProperty(const std::string &name, const std::string &value);
40 CSSProperty(const CSSProperty &prop);
42
43 CSSProperty& operator=(const CSSProperty &prop);
44
45 const std::string& getName() const;
46 void setName(const std::string &name);
47
48 const std::string& getValue() const;
49 void setValue(const std::string &value);
50
51 private:
52 std::string _Name;
53 std::string _Value;
54 };
55
57 public:
59 CSSDeclaration(const CSSDeclaration &decl);
61
63
64 void addProperty(const std::string &name, const std::string &value);
65 void removeProperty(const std::string &name);
66
67 const CSSProperty* getProperty(const std::string &name) const;
68
69 const std::vector<CSSProperty>& getProperties() const;
70
71 std::string serialize() const;
72
73 void parse(const std::string &input);
74 void clear();
75
76 private:
77 std::vector<CSSProperty> _Properties;
78 };
79
80 class CSSRule {
81 public:
82 CSSRule();
83 CSSRule(const std::string &selector);
84 CSSRule(const CSSRule &rule);
85 ~CSSRule();
86
87 CSSRule& operator=(const CSSRule &rule);
88
89 const std::string& getSelector() const;
90 void setSelector(const std::string &selector);
91
93 const CSSDeclaration& getDeclaration() const;
94
95 std::string serialize(bool formatted = false) const;
96
97 private:
98 std::string _Selector;
99 CSSDeclaration _Declaration;
100 };
101
103 public:
105 CSSStyleSheet(const CSSStyleSheet &sheet);
107
109
110 void parse(const std::string &input);
111
112 void addRule(const CSSRule &rule);
113 void removeRule(size_t index);
114
115 const CSSRule* getRule(size_t index) const;
116 size_t getRuleCount() const;
117
118 const std::vector<CSSRule>& getRules() const;
119
120 std::string serialize(bool formatted = false) const;
121 void clear();
122
123 static CSSDeclaration parseInlineStyle(const std::string &style);
124
125 private:
126 void _skipWhitespace(const std::string &input, size_t &pos) const;
127 void _skipComment(const std::string &input, size_t &pos) const;
128 std::vector<CSSRule> _Rules;
129 };
130
131}
132
void addProperty(const std::string &name, const std::string &value)
Definition css.cpp:92
void removeProperty(const std::string &name)
Definition css.cpp:107
const std::vector< CSSProperty > & getProperties() const
Definition css.cpp:124
std::string serialize() const
Definition css.cpp:128
const CSSProperty * getProperty(const std::string &name) const
Definition css.cpp:116
void parse(const std::string &input)
Definition css.cpp:140
CSSDeclaration & operator=(const CSSDeclaration &decl)
Definition css.cpp:85
void setName(const std::string &name)
Definition css.cpp:71
const std::string & getName() const
Definition css.cpp:70
void setValue(const std::string &value)
Definition css.cpp:74
CSSProperty & operator=(const CSSProperty &prop)
Definition css.cpp:62
const std::string & getValue() const
Definition css.cpp:73
CSSDeclaration & getDeclaration()
Definition css.cpp:228
std::string serialize(bool formatted=false) const
Definition css.cpp:231
void setSelector(const std::string &selector)
Definition css.cpp:226
CSSRule & operator=(const CSSRule &rule)
Definition css.cpp:217
const std::string & getSelector() const
Definition css.cpp:225
void parse(const std::string &input)
Definition css.cpp:281
const std::vector< CSSRule > & getRules() const
Definition css.cpp:405
CSSStyleSheet & operator=(const CSSStyleSheet &sheet)
Definition css.cpp:256
static CSSDeclaration parseInlineStyle(const std::string &style)
Definition css.cpp:423
std::string serialize(bool formatted=false) const
Definition css.cpp:409
const CSSRule * getRule(size_t index) const
Definition css.cpp:396
void addRule(const CSSRule &rule)
Definition css.cpp:386
void removeRule(size_t index)
Definition css.cpp:390
size_t getRuleCount() const
Definition css.cpp:401
Core namespace for the libhtmlpp HTML parsing and printing library.
Definition css.h:34