Juan Zacarias has proposed merging 
lp:~zorba-coders/zorba/bug1082740_fn_subsequence into lp:zorba.

Commit message:
Added support for INF and -INF values in fn:subsequence function.

Requested reviews:
  Chris Hillery (ceejatec)
Related bugs:
  Bug #1082740 in Zorba: "subsequence"
  https://bugs.launchpad.net/zorba/+bug/1082740

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug1082740_fn_subsequence/+merge/157755

Added support for INF and -INF values in fn:subsequence function.
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug1082740_fn_subsequence/+merge/157755
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/runtime/sequences/pregenerated/sequences.cpp'
--- src/runtime/sequences/pregenerated/sequences.cpp	2013-03-20 01:19:04 +0000
+++ src/runtime/sequences/pregenerated/sequences.cpp	2013-04-08 21:26:23 +0000
@@ -363,12 +363,14 @@
 void FnSubsequenceIteratorState::init(PlanState& planState) {
   PlanIteratorState::init(planState);
   theRemaining = 0;
+  theRemainingIsPosInf = false;
   theIsChildReset = false;
 }
 
 void FnSubsequenceIteratorState::reset(PlanState& planState) {
   PlanIteratorState::reset(planState);
   theRemaining = 0;
+  theRemainingIsPosInf = false;
   theIsChildReset = false;
 }
 // </FnSubsequenceIterator>

=== modified file 'src/runtime/sequences/pregenerated/sequences.h'
--- src/runtime/sequences/pregenerated/sequences.h	2013-03-20 01:19:04 +0000
+++ src/runtime/sequences/pregenerated/sequences.h	2013-04-08 21:26:23 +0000
@@ -422,6 +422,7 @@
 {
 public:
   xs_long theRemaining; //
+  bool theRemainingIsPosInf; //
   bool theIsChildReset; //
 
   FnSubsequenceIteratorState();

=== modified file 'src/runtime/sequences/sequences_impl.cpp'
--- src/runtime/sequences/sequences_impl.cpp	2013-03-26 18:10:32 +0000
+++ src/runtime/sequences/sequences_impl.cpp	2013-04-08 21:26:23 +0000
@@ -480,14 +480,30 @@
   state->theIsChildReset = false;
 
   CONSUME(startPosItem, 1);
+
+  //If starting position is set to +INF return empty sequence
+  if (startPosItem->getDoubleValue().isPosInf())
+    goto done;
+
   startPos =
   static_cast<xs_long>(startPosItem->getDoubleValue().round().getNumber()) - 1;
 
   if (theChildren.size() == 3)
   {
     CONSUME(lengthItem, 2);
-    state->theRemaining =
-    static_cast<xs_long>(lengthItem->getDoubleValue().round().getNumber());
+    if (lengthItem->getDoubleValue().isPosInf())
+    {
+      //if startPos is -INF and length is +INF return empty sequence because -INF + INF = NaN
+      if (startPosItem->getDoubleValue().isNegInf())
+        goto done;
+
+      //the remaining is set as +INF to return all the values after the start position
+      state->theRemainingIsPosInf = true;
+      state->theRemaining = 1;
+    }
+    else
+      state->theRemaining =
+      static_cast<xs_long>(lengthItem->getDoubleValue().round().getNumber());
   }
 
   if (startPos < 0)
@@ -509,7 +525,7 @@
       goto done;
   }
 
-  if (theChildren.size() < 3)
+  if (theChildren.size() < 3 || state->theRemainingIsPosInf)
   {
     while (CONSUME(result, 0))
     {

=== modified file 'src/runtime/spec/sequences/sequences.xml'
--- src/runtime/spec/sequences/sequences.xml	2013-03-20 01:19:04 +0000
+++ src/runtime/spec/sequences/sequences.xml	2013-04-08 21:26:23 +0000
@@ -420,7 +420,10 @@
 
     <zorba:member type="xs_long" name="theRemaining"
                   defaultValue="0" brief=""/>
+    <zorba:member type="bool" name="theRemainingIsPosInf" 
+                  defaultValue="false" brief=""/>
     <zorba:member type="bool" name="theIsChildReset" defaultValue="false"/>
+    
 
   </zorba:state>
 

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to