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