MCPcopy Create free account
hub / github.com/SpartanJ/eepp / parse

Method parse

src/eepp/ui/css/mediaquery.cpp:34–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32}
33
34MediaQuery::ptr MediaQuery::parse( const std::string& str ) {
35 DisplayManager* displayManager = Engine::instance()->getDisplayManager();
36 int currentDisplayIndex = Engine::instance()->getCurrentWindow()->getCurrentDisplayIndex();
37 Display* currentDisplay = displayManager->getDisplayIndex( currentDisplayIndex );
38 Float dpi = currentDisplay->getDPI();
39 MediaQuery::ptr query = std::make_shared<MediaQuery>();
40
41 std::vector<std::string> tokens = String::split( str, " \t\r\n", "", "(" );
42
43 for ( auto& tok : tokens ) {
44 if ( tok == "not" ) {
45 query->mNot = true;
46 } else if ( tok.at( 0 ) == '(' ) {
47 tok.erase( 0, 1 );
48
49 if ( tok.at( tok.length() - 1 ) == ')' ) {
50 tok.erase( tok.length() - 1, 1 );
51 }
52
53 MediaQueryExpression expr;
54 std::vector<std::string> exprTokens = String::split( tok, ':' );
55 if ( !exprTokens.empty() ) {
56 String::trimInPlace( exprTokens[0] );
57
58 expr.feature = (MediaFeature)String::valueIndex( exprTokens[0], MediaFeatureStrings,
59 media_feature_none );
60
61 if ( expr.feature != media_feature_none ) {
62 if ( exprTokens.size() == 1 ) {
63 expr.checkAsBool = true;
64 } else {
65 String::trimInPlace( exprTokens[1] );
66 expr.checkAsBool = false;
67
68 if ( expr.feature == media_feature_orientation ) {
69 expr.val = String::valueIndex( exprTokens[1], MediaOrientationStrings,
70 media_orientation_landscape );
71 } else {
72 std::string::size_type slash_pos = exprTokens[1].find( '/' );
73 if ( slash_pos != std::string::npos ) {
74 std::string val1 = exprTokens[1].substr( 0, slash_pos );
75 std::string val2 = exprTokens[1].substr( slash_pos + 1 );
76 String::trimInPlace( val1 );
77 String::trimInPlace( val2 );
78
79 int intVal1, intVal2;
80 float fVal1, fVal2;
81
82 if ( String::fromString( intVal1, val1 ) &&
83 String::fromString( intVal2, val2 ) ) {
84 expr.val = intVal1;
85 expr.val2 = intVal2;
86 }
87
88 if ( String::fromString( fVal1, val1 ) &&
89 String::fromString( fVal2, val2 ) ) {
90 expr.fval = fVal1;
91 expr.fval2 = fVal2;

Callers 2

loadFromXmlNodeMethod · 0.45
setStyleSheetPropertyMethod · 0.45

Calls 15

fromStringFunction · 0.85
getDisplayManagerMethod · 0.80
getCurrentWindowMethod · 0.80
getDisplayIndexMethod · 0.80
getDPIMethod · 0.80
atMethod · 0.80
substrMethod · 0.80
asPixelsMethod · 0.80
push_backMethod · 0.80
eraseMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected