[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/multimedia/kmplayer
From:       Koos Vriezen <koos.vriezen () gmail ! com>
Date:       2010-03-21 22:05:58
Message-ID: 20100321220558.9D7E9AC86A () svn ! kde ! org
[Download RAW message or body]

SVN commit 1106127 by vriezen:

Add 'escape-uri' and 'contains' expression functions

Also support context node '.' so that 'contains' can be used in
predicates

 M  +65 -5     src/expression.cpp  
 M  +2 -2      tests/state.smil  


--- trunk/extragear/multimedia/kmplayer/src/expression.cpp #1106126:1106127
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
+#include <qurl.h>
 #include "expression.h"
 
 using namespace KMPlayer;
@@ -145,9 +146,12 @@
 };
 
 struct Step : public StringBase {
-    Step (EvalState *ev) : StringBase (ev), any_node (false), is_attr (false) {}
+    Step (EvalState *ev, bool context=false)
+     : StringBase (ev),
+       any_node (false), context_node (context), is_attr (false) {}
     Step (EvalState *ev, const char *s, const char *e, bool isattr=false)
-     : StringBase (ev, s, e), any_node (string == "*"), is_attr (isattr) {}
+     : StringBase (ev, s, e),
+       any_node (string == "*"), context_node (false), is_attr (isattr) {}
 
     bool matches (Node *n);
     bool matches (Attribute *a);
@@ -156,12 +160,14 @@
 #ifdef KMPLAYER_EXPR_DEBUG
     virtual void dump () const {
         fprintf (stderr, "Step %c%s",
-                is_attr ? '@' : ' ',string.toAscii ().constData ());
+                is_attr ? '@' : ' ',
+                context_node ? "." : string.toAscii ().constData ());
         AST::dump();
     }
 #endif
 
     bool any_node;
+    bool context_node;
     bool is_attr;
 };
 
@@ -198,6 +204,12 @@
 #endif
 };
 
+struct Contains : public BoolBase {
+    Contains (EvalState *ev) : BoolBase (ev) {}
+
+    virtual bool toBool () const;
+};
+
 struct Not : public BoolBase {
     Not (EvalState *ev) : BoolBase (ev) {}
 
@@ -264,6 +276,12 @@
     virtual QString toString () const;
 };
 
+struct EscapeUri : public StringBase {
+    EscapeUri (EvalState *ev) : StringBase (ev) {}
+
+    virtual QString toString () const;
+};
+
 struct Sort : public AST {
     Sort (EvalState *ev) : AST (ev) {}
 
@@ -572,6 +590,9 @@
             if (recurse)
                 for (Node *c = n->firstChild(); c; c = c->nextSibling ())
                     recursive_lst.append (new NodeValueItem (c));
+        } else if (step->context_node) {
+            if (eval_state->parent)
+                lst->append (new NodeValueItem (eval_state->parent->root));
         } else {
             for (Node *c = n->firstChild(); c; c = c->nextSibling ()) {
                 if (step->matches (c))
@@ -658,6 +679,19 @@
     return TString;
 }
 
+bool Contains::toBool () const {
+    if (eval_state->sequence != sequence) {
+        sequence = eval_state->sequence;
+        b = false;
+        if (first_child) {
+            AST *s = first_child->next_sibling;
+            if (s)
+                b = first_child->toString ().indexOf (s->toString ()) > -1;
+        }
+    }
+    return b;
+}
+
 bool Not::toBool () const {
     if (eval_state->sequence != sequence) {
         sequence = eval_state->sequence;
@@ -764,6 +798,16 @@
     return string;
 }
 
+QString EscapeUri::toString () const {
+    if (eval_state->sequence != sequence) {
+        sequence = eval_state->sequence;
+        string.clear ();
+        if (first_child)
+            string = QUrl::toPercentEncoding (first_child->toString ());
+    }
+    return string;
+}
+
 QString StringJoin::toString () const {
     if (eval_state->sequence != sequence) {
         sequence = eval_state->sequence;
@@ -1140,7 +1184,8 @@
             }
             *end = s;
         }
-        if (*end && (!sign || *end > str) && *end - str < 64) {
+        if (*end && (!sign || *end > str) && *end - str < 64 &&
+                (!decimal || *end > str)) {
             char buf[64];
             ++(*end);
             memcpy (buf, str, *end - str);
@@ -1163,7 +1208,15 @@
 #endif
     Step *entry = NULL;
     const char *s = str;
-    if (*s == '/') {
+    if (*s == '.') {
+        ++s;
+        if (s && *s == '.') { // TODO
+            entry = new Step (ast->eval_state, true);
+            ++s;
+        } else {
+            entry = new Step (ast->eval_state, true);
+        }
+    } else if (*s == '/') {
         entry = new Step (ast->eval_state);
     } else {
         bool is_attr = *s == '@';
@@ -1196,6 +1249,9 @@
     if (entry) {
         appendASTChild (ast, entry);
         *end = s;
+#ifdef KMPLAYER_EXPR_DEBUG
+        fprintf (stderr, "%s success end:'%s'\n", __FUNCTION__, *end);
+#endif
         return true;
     }
     return false;
@@ -1295,6 +1351,8 @@
                 AST *func = NULL;
                 if (name == "concat")
                     func = new Concat (ast->eval_state);
+                else if (name == "contains")
+                    func = new Contains (ast->eval_state);
                 else if (name == "hours-from-time")
                     func = new HoursFromTime (ast->eval_state);
                 else if (name == "minutes-from-time")
@@ -1317,6 +1375,8 @@
                     func = new Sort (ast->eval_state);
                 else if (name == "string-join")
                     func = new StringJoin (ast->eval_state);
+                else if (name == "escape-uri")
+                    func = new EscapeUri (ast->eval_state);
                 else
                     return false;
                 appendASTChild (ast, func);
--- trunk/extragear/multimedia/kmplayer/tests/state.smil #1106126:1106127
@@ -35,7 +35,7 @@
             left="200" top="70" width="190" height="20"/>
       <text src="data:,{//book[last()]/author}"
             left="10" top="100" width="190" height="20"/>
-      <text src="data:,{/data/books/book[last()]/title}"
+      <text src="data:,{/data/books/book/title[contains(., 'Pygma')]}"
             left="200" top="100" width="190" height="20"/>
       <text src="data:,books%20{number(/data/books/book)}"
             left="10" top="160" width="300" height="20"/>
@@ -47,7 +47,7 @@
     <par dur="5">
       <text src="data:,books%20with%20price%20{//book[@price]}" left="10" top="10" \
                width="300" height="20"/>
       <text src="data:,books%20with%20price%2010p%20{//book[@price=&quot;10p&quot;]/title}" \
                left="10" top="40" width="300" height="20"/>
-      <text src="data:,price%20of%20{string-join(//book[3]/title | //book[3]/@price, \
' is ')}" left="10" top="70" width="300" height="20"/> +      <text \
src="data:,price%20of%20{escape-uri(string-join(//book[3]/title | //book[3]/@price, ' \
                is '))}" left="10" top="70" width="300" height="20"/>
       <text src="data:,attributes%20on%20second%20book%20{//book[2]/@*}" left="10" \
                top="100" width="300" height="20"/>
       <text src="data:,total%20attributes%20on%20book%20{//book/@*}" left="10" \
                top="130" width="300" height="20"/>
       <text src="data:,second%20attribute%20on%20book%20{//book/@*[2]}" left="10" \
top="160" width="300" height="20"/>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic