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