diff options
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/core/utils/CSSParser.cpp | 27 | ||||
-rw-r--r-- | src/core/utils/CSSParser.hpp | 64 | ||||
-rw-r--r-- | test/core/utils/CSSParserTest.cpp | 116 |
4 files changed, 210 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 58fa742..53fa6a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,6 +95,7 @@ ADD_DEFINITIONS( ) # ousia_script library (containing the bindings needed for script engines) +# TODO: This is not only the script library. ADD_LIBRARY(ousia_core src/core/dom/Managed src/core/dom/Node @@ -103,6 +104,7 @@ ADD_LIBRARY(ousia_core src/core/script/ScriptEngine src/core/script/Variant src/core/utils/BufferedCharReader + src/core/utils/CSSParser src/core/utils/Tokenizer src/core/utils/Utils ) @@ -138,6 +140,7 @@ IF(TEST) test/core/script/ObjectTest test/core/script/VariantTest test/core/utils/BufferedCharReaderTest + test/core/utils/CSSParserTest test/core/utils/RangeSetTest test/core/utils/TokenizerTest test/core/utils/UtilsTest diff --git a/src/core/utils/CSSParser.cpp b/src/core/utils/CSSParser.cpp new file mode 100644 index 0000000..6ac98fa --- /dev/null +++ b/src/core/utils/CSSParser.cpp @@ -0,0 +1,27 @@ +/* + Ousía + Copyright (C) 2014 Benjamin Paaßen, Andreas Stöckel + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "CSSParser.hpp" + +namespace ousia { +namespace utils { + + + +} +} diff --git a/src/core/utils/CSSParser.hpp b/src/core/utils/CSSParser.hpp new file mode 100644 index 0000000..4e82371 --- /dev/null +++ b/src/core/utils/CSSParser.hpp @@ -0,0 +1,64 @@ +/* + Ousía + Copyright (C) 2014 Benjamin Paaßen, Andreas Stöckel + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _OUSIA_UTILS_CSS_PARSER_HPP_ +#define _OUSIA_UTILS_CSS_PARSER_HPP_ + +#include <istream> +#include <tuple> + +namespace ousia { +namespace utils { + +/* + * The Specificity or Precedence of a CSS RuleSet, which decides which + * rules are applied when different RuleSets contain conflicting information. + * + * The Specificity is calculated using the official W3C recommendation + * http://www.w3.org/TR/CSS2/cascade.html#specificity + * + * Note that we do not need to use the integer 'a', since we do not allow + * local style definitions for single nodes. + */ +struct Specificity { + +int b; +int c; +int d; + +Specificity(int b, int c, int d): b(b), c(c), d(d) {} + +}; + + +bool operator< (const Specificity &x, const Specificity &y){ + return std::tie(x.b, x.c, x.d) < std::tie(y.b, y.c, y.d); +} + +bool operator> (const Specificity &x, const Specificity &y){ + return std::tie(x.b, x.c, x.d) > std::tie(y.b, y.c, y.d); +} + +bool operator== (const Specificity &x, const Specificity &y){ + return std::tie(x.b, x.c, x.d) == std::tie(y.b, y.c, y.d); +} + +} +} + +#endif diff --git a/test/core/utils/CSSParserTest.cpp b/test/core/utils/CSSParserTest.cpp new file mode 100644 index 0000000..920752b --- /dev/null +++ b/test/core/utils/CSSParserTest.cpp @@ -0,0 +1,116 @@ +/* + Ousía + Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <gtest/gtest.h> + +#include <core/utils/CSSParser.hpp> + +namespace ousia { +namespace utils { +TEST(Specificity, testOperators) +{ + Specificity s1{0,0,1}; + Specificity s2{0,1,1}; + Specificity s3{1,1,1}; + Specificity s4{0,0,2}; + Specificity s5{1,0,2}; + + //This should be s1 < s4 < s2 < s5 < s3 + + ASSERT_TRUE(s1 == s1); + ASSERT_FALSE(s1 < s1); + ASSERT_FALSE(s1 > s1); + ASSERT_FALSE(s1 == s2); + ASSERT_TRUE(s1 < s2); + ASSERT_FALSE(s1 > s2); + ASSERT_FALSE(s1 == s3); + ASSERT_TRUE(s1 < s3); + ASSERT_FALSE(s1 > s3); + ASSERT_FALSE(s1 == s4); + ASSERT_TRUE(s1 < s4); + ASSERT_FALSE(s1 > s4); + ASSERT_FALSE(s1 == s5); + ASSERT_TRUE(s1 < s5); + ASSERT_FALSE(s1 > s5); + + ASSERT_FALSE(s2 == s1); + ASSERT_FALSE(s2 < s1); + ASSERT_TRUE(s2 > s1); + ASSERT_TRUE(s2 == s2); + ASSERT_FALSE(s2 < s2); + ASSERT_FALSE(s2 > s2); + ASSERT_FALSE(s2 == s3); + ASSERT_TRUE(s2 < s3); + ASSERT_FALSE(s2 > s3); + ASSERT_FALSE(s2 == s4); + ASSERT_FALSE(s2 < s4); + ASSERT_TRUE(s2 > s4); + ASSERT_FALSE(s2 == s5); + ASSERT_TRUE(s2 < s5); + ASSERT_FALSE(s2 > s5); + + ASSERT_FALSE(s3 == s1); + ASSERT_FALSE(s3 < s1); + ASSERT_TRUE(s3 > s1); + ASSERT_FALSE(s3 == s2); + ASSERT_FALSE(s3 < s2); + ASSERT_TRUE(s3 > s2); + ASSERT_TRUE(s3 == s3); + ASSERT_FALSE(s3 < s3); + ASSERT_FALSE(s3 > s3); + ASSERT_FALSE(s3 == s4); + ASSERT_FALSE(s3 < s4); + ASSERT_TRUE(s3 > s4); + ASSERT_FALSE(s3 == s5); + ASSERT_FALSE(s3 < s5); + ASSERT_TRUE(s3 > s5); + + ASSERT_FALSE(s4 == s1); + ASSERT_FALSE(s4 < s1); + ASSERT_TRUE(s4 > s1); + ASSERT_FALSE(s4 == s2); + ASSERT_TRUE(s4 < s2); + ASSERT_FALSE(s4 > s2); + ASSERT_FALSE(s4 == s3); + ASSERT_TRUE(s4 < s3); + ASSERT_FALSE(s4 > s3); + ASSERT_TRUE(s4 == s4); + ASSERT_FALSE(s4 < s4); + ASSERT_FALSE(s4 > s4); + ASSERT_FALSE(s4 == s5); + ASSERT_TRUE(s4 < s5); + ASSERT_FALSE(s4 > s5); + + ASSERT_FALSE(s5 == s1); + ASSERT_FALSE(s5 < s1); + ASSERT_TRUE(s5 > s1); + ASSERT_FALSE(s5 == s2); + ASSERT_FALSE(s5 < s2); + ASSERT_TRUE(s5 > s2); + ASSERT_FALSE(s5 == s3); + ASSERT_TRUE(s5 < s3); + ASSERT_FALSE(s5 > s3); + ASSERT_FALSE(s5 == s4); + ASSERT_FALSE(s5 < s4); + ASSERT_TRUE(s5 > s4); + ASSERT_TRUE(s5 == s5); + ASSERT_FALSE(s5 < s5); + ASSERT_FALSE(s5 > s5); +} +} +} |