Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Commit

Permalink
Merge 55019bd into ef4c292
Browse files Browse the repository at this point in the history
  • Loading branch information
ayazhafiz committed Jan 4, 2019
2 parents ef4c292 + 55019bd commit f62fb08
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions include/layout.hpp
Expand Up @@ -282,10 +282,10 @@ class StyledBox : public Box {
void setHeight();

/**
* Get the box an inline node should go into, or a create a new one
* Returns a pointer to the box an inline node should go into
* @return box to put inline node in
*/
Box * getInlineContainer();
Box * inlineContainer();

Style::StyledNode content;
DisplayType display;
Expand Down
8 changes: 5 additions & 3 deletions include/parser/css.hpp
Expand Up @@ -88,12 +88,14 @@ class CSSParser : public Parser<CSS::StyleSheet> {

// casted std::is_ methods for parameter use
static constexpr auto cisdigit = static_cast<int (*)(int)>(std::isdigit);
static constexpr auto cisalnum = static_cast<int (*)(int)>(std::isalnum);
static constexpr auto cisspace = static_cast<int (*)(int)>(std::isspace);
static constexpr auto cisfloat = [](char c) {
return std::isdigit(c) || c == '.' || c == '-';
};
static constexpr auto cisalpha = static_cast<int (*)(int)>(std::isalpha);
static constexpr auto cisalnum = static_cast<int (*)(int)>(std::isalnum);
static constexpr auto cisspace = static_cast<int (*)(int)>(std::isspace);
static constexpr auto cisunit = [](char c) {
return std::isalpha(c) || c == '%';
};
};

#endif
2 changes: 2 additions & 0 deletions include/parser/parser.hpp
Expand Up @@ -110,4 +110,6 @@ class Parser {
uint64_t ptr;
};

#include "../../src/parser/parser.cpp"

#endif
Binary file modified output.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/layout.cpp
Expand Up @@ -179,7 +179,7 @@ Layout::BoxPtr Layout::Box::from(const Style::StyledNode & styledRoot) {
root.children.push_back(Box::from(child));
break;
case Inline:
root.getInlineContainer()->children.push_back(Box::from(child));
root.inlineContainer()->children.push_back(Box::from(child));
break;
case None:
default:
Expand Down Expand Up @@ -403,10 +403,10 @@ void Layout::StyledBox::setHeight() {
}

/**
* Get the box an inline node should go into, or a create a new one
* Returns a pointer to the box an inline node should go into
* @return box to put inline node in
*/
Layout::Box * Layout::StyledBox::getInlineContainer() {
Layout::Box * Layout::StyledBox::inlineContainer() {
if (display == Inline) {
return this;
} else { // *this is a block display
Expand Down
4 changes: 2 additions & 2 deletions src/parser/css.cpp
Expand Up @@ -5,7 +5,7 @@

#include "parser/css.hpp"

#include "parser.cpp"
#include "parser/parser.hpp"

#include <algorithm>
#include <functional>
Expand Down Expand Up @@ -184,7 +184,7 @@ CSS::ValuePtr CSSParser::parseHex() {
* @return Unit
*/
CSS::Unit CSSParser::parseUnit() {
auto raw = build_until(std::not_fn(cisalpha));
auto raw = build_until(std::not_fn(cisunit));
auto rawArr = CSS::UnitRaw();
return static_cast<CSS::Unit>(std::find(rawArr.begin(), rawArr.end(), raw) -
rawArr.begin());
Expand Down
2 changes: 1 addition & 1 deletion src/parser/html.cpp
Expand Up @@ -5,7 +5,7 @@

#include "parser/html.hpp"

#include "parser.cpp"
#include "parser/parser.hpp"

#include <cctype>

Expand Down
6 changes: 5 additions & 1 deletion tests/parser/css.cpp
Expand Up @@ -93,13 +93,17 @@ body {

TEST_F(CSSParserTest, UnitDeclaration) {
CSSParser parser(
"body { font-size:15px;font-size:1.0em;font-size:5.5vh; }");
"body { font-size:15px;"
"font-size:1.0em;"
"font-size:5.5vh;"
"font-size:10%; }");
auto eval = parser.evaluate();
ASSERT_PRINT(&eval, R"(
body {
font-size: 15px;
font-size: 1em;
font-size: 5.5vh;
font-size: 10%;
}
)");
Expand Down

0 comments on commit f62fb08

Please sign in to comment.