-
Notifications
You must be signed in to change notification settings - Fork 1
/
css_length.cpp
54 lines (51 loc) · 1.05 KB
/
css_length.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "litehtml/html.h"
#include "litehtml/css_length.h"
void litehtml::css_length::fromString( const tstring& str, const tstring& predefs, int defValue )
{
// TODO: Make support for calc
if(str.substr(0, 4) == _t("calc"))
{
m_is_predefined = true;
m_predef = 0;
return;
}
int predef = value_index(str.c_str(), predefs.c_str(), -1);
if(predef >= 0)
{
m_is_predefined = true;
m_predef = predef;
} else
{
m_is_predefined = false;
tstring num;
tstring un;
bool is_unit = false;
for(tstring::const_iterator chr = str.begin(); chr != str.end(); chr++)
{
if(!is_unit)
{
if(t_isdigit(*chr) || *chr == _t('.') || *chr == _t('+') || *chr == _t('-'))
{
num += *chr;
} else
{
is_unit = true;
}
}
if(is_unit)
{
un += *chr;
}
}
if(!num.empty())
{
m_value = (float) t_strtod(num.c_str(), 0);
m_units = (css_units) value_index(un.c_str(), css_units_strings, css_units_none);
} else
{
// not a number so it is predefined
m_is_predefined = true;
m_predef = defValue;
}
}
}