[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:       2011-06-19 14:30:36
Message-ID: 20110619143036.72074AC86E () svn ! kde ! org
[Download RAW message or body]

SVN commit 1237537 by vriezen:

Support expression functions subsequence and tokenize

 M  +59 -0     src/expression.cpp  
 M  +4 -2      tests/arte.smil  
 M  +8 -0      tests/state.smil  


--- trunk/extragear/multimedia/kmplayer/src/expression.cpp #1237536:1237537
@@ -26,6 +26,8 @@
 #include <qurl.h>
 #include "expression.h"
 
+#include <QRegExp>
+
 using namespace KMPlayer;
 
 QString NodeValue::value () const {
@@ -334,6 +336,18 @@
     virtual Sequence *toSequence () const;
 };
 
+struct SubSequence : public SequenceBase {
+    SubSequence (EvalState *ev) : SequenceBase (ev) {}
+
+    virtual Sequence *toSequence () const;
+};
+
+struct Tokenize : public SequenceBase {
+    Tokenize (EvalState *ev) : SequenceBase (ev) {}
+
+    virtual Sequence *toSequence () const;
+};
+
 struct Multiply : public NumberBase {
     Multiply (EvalState *ev, AST *children) : NumberBase (ev) {
         first_child = children;
@@ -1035,6 +1049,47 @@
     return AST::toSequence ();
 }
 
+Sequence *SubSequence::toSequence () const {
+    Sequence *lst = new Sequence;
+    AST *n = first_child;
+    if (n) {
+        Sequence *src = n->toSequence ();
+        n = n->next_sibling;
+        if (n) {
+            int p = n->toInt ();
+            int len = 1;
+            if (n->next_sibling)
+                len = n->next_sibling->toInt ();
+            NodeValueItem *itm = src->first ();
+            for (; itm && --p; itm = itm->nextSibling ())
+            {}
+            for (; itm && len--; itm = itm->nextSibling ())
+                lst->append (new NodeValueItem (itm->data));
+        }
+    }
+    return lst;
+}
+
+Sequence *Tokenize::toSequence () const {
+    Sequence *lst = new Sequence;
+    if (first_child) {
+        if (first_child->next_sibling) {
+            QString s = first_child->toString ();
+            QRegExp r (first_child->next_sibling->toString ());
+            int p = 0;
+            while (p >= 0) {
+                p = r.indexIn (s, p);
+                if (p >= 0) {
+                    int len = r.matchedLength();
+                    lst->append (new NodeValueItem (s.mid (p, len)));
+                    p += len;
+                }
+            }
+        }
+    }
+    return lst;
+}
+
 #define BIN_OP_TO_INT(NAME,OP)                                           \
     AST *second_child = first_child->next_sibling;                       \
     AST::Type t1 = first_child->type ();                                 \
@@ -1533,10 +1588,14 @@
                     func = new StringJoin (ast->eval_state);
                 else if (name == "string-length")
                     func = new StringLength (ast->eval_state);
+                else if (name == "subsequence")
+                    func = new SubSequence (ast->eval_state);
                 else if (name == "substring-after")
                     func = new SubstringAfter (ast->eval_state);
                 else if (name == "substring-before")
                     func = new SubstringBefore (ast->eval_state);
+                else if (name == "tokenize")
+                    func = new Tokenize (ast->eval_state);
                 else if (name == "escape-uri")
                     func = new EscapeUri (ast->eval_state);
                 else
--- trunk/extragear/multimedia/kmplayer/tests/arte.smil #1237536:1237537
@@ -143,11 +143,13 @@
                           value="concat('Could not get HTML ', /data/page/uri)"/>
               </switch>
               <seq begin="mystate.stateChange(/data/page/html)">
-                <setvalue ref="/data/tmp"
+                <!-- setvalue ref="/data/tmp"
                           value="substring-after(/data/page/html, \
'vars_player.videorefFileUrl')"/>  <setvalue ref="/data/tmp"
-                          value="substring-before(/data/tmp, ';')"/>
+                          value="substring-before(/data/tmp, ';')"/-->
                 <setvalue ref="/data/tmp"
+                          value="subsequence(tokenize(/data/page/html, \
'vars_player.videorefFileUrl *= *&quot;[^&quot;]+&quot;'),1)"/> +                \
<setvalue ref="/data/tmp"  value="substring-after(/data/tmp, '&quot;')"/>
                 <setvalue ref="/data/vref/uri"
                           value="substring-before(/data/tmp, '&quot;')"/>
--- trunk/extragear/multimedia/kmplayer/tests/state.smil #1237536:1237537
@@ -54,6 +54,14 @@
     </par>
     <delvalue ref="//@foo"/>
     <par dur="5">
+      <text src="data:,Title%20&quot;{/data/books/book[2]/title}&quot;"
+            left="10" top="10" width="300" height="20"/>
+      <text src="data:,Has%20{tokenize(/data/books/book[2]/title,&quot;\S+&quot;)}%20words"
 +            left="10" top="40" width="300" height="20"/>
+      <text src="data:,First \
word%20is%20&quot;{subsequence(tokenize(/data/books/book[2]/title,&quot;\S+&quot;),1)}&quot;"
 +            left="10" top="70" width="300" height="20"/>
+      <text src="data:,First two \
words%20are%20&quot;{string-join(subsequence(tokenize(/data/books/book[2]/title,&quot;\S+&quot;),1,2), \
' ')}&quot;" +            left="10" top="100" width="300" height="20"/>
       <text src="data:,second%20attribute%20on%20book%20{//book/@*[2]}" left="10" \
top="160" width="300" height="20"/>  </par>
     <delvalue ref="//books"/>


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

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