Disable stack execution on plugins
[claws.git] / src / plugins / litehtml_viewer / litehtml / css_length.cpp
blobd1c69d2612a2627c1fe70813b9116e40d7f20b85
1 #include "html.h"
2 #include "css_length.h"
4 void litehtml::css_length::fromString( const string& str, const string& predefs, int defValue )
6 // TODO: Make support for calc
7 if(str.substr(0, 4) == "calc")
9 m_is_predefined = true;
10 m_predef = defValue;
11 return;
14 int predef = value_index(str, predefs, -1);
15 if(predef >= 0)
17 m_is_predefined = true;
18 m_predef = predef;
19 } else
21 m_is_predefined = false;
23 string num;
24 string un;
25 bool is_unit = false;
26 for(char chr : str)
28 if(!is_unit)
30 if(t_isdigit(chr) || chr == '.' || chr == '+' || chr == '-')
32 num += chr;
33 } else
35 is_unit = true;
38 if(is_unit)
40 un += chr;
43 if(!num.empty())
45 m_value = t_strtof(num);
46 m_units = (css_units) value_index(un, css_units_strings, css_units_none);
47 } else
49 // not a number so it is predefined
50 m_is_predefined = true;
51 m_predef = defValue;
56 litehtml::css_length litehtml::css_length::from_string(const string& str, const string& predefs, int defValue)
58 css_length len;
59 len.fromString(str, predefs, defValue);
60 return len;
63 litehtml::string litehtml::css_length::to_string() const
65 if(m_is_predefined)
67 return "def(" + std::to_string(m_predef) + ")";
69 return std::to_string(m_value) + "{" + index_value(m_units, css_units_strings) + "}";
72 litehtml::css_length litehtml::css_length::predef_value(int val)
74 css_length len;
75 len.predef(val);
76 return len;