Paul J. Lucas has proposed merging lp:~zorba-coders/zorba/bug-1090514 into 
lp:zorba.

Commit message:
Fixed most generate-id() bugs.

Requested reviews:
  Paul J. Lucas (paul-lucas)
Related bugs:
  Bug #1090514 in Zorba: "fn-generate-id failures"
  https://bugs.launchpad.net/zorba/+bug/1090514

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-1090514/+merge/162683

Fixed most generate-id() bugs.
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug-1090514/+merge/162683
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/runtime/nodes/nodes_impl.cpp'
--- src/runtime/nodes/nodes_impl.cpp	2013-03-05 12:34:19 +0000
+++ src/runtime/nodes/nodes_impl.cpp	2013-05-06 23:27:27 +0000
@@ -27,6 +27,7 @@
 #include "store/api/store.h"
 #include "store/api/copymode.h"
 
+#include "util/ascii_util.h"
 #include "util/string_util.h"
 #include "util/uri_util.h"
 #include "zorbautils/string_util.h"
@@ -453,35 +454,31 @@
 ********************************************************************************/
 bool FnGenerateIdIterator::nextImpl(store::Item_t& result, PlanState& planState) const
 {
-  store::Item_t     item;
-  bool retval;
+  store::Item_t item;
+  zstring id;
 
   PlanIteratorState* state;
   DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
 
-  if (theChildren.size())
+  // Note that the zero-argument version of this function is transformed into
+  // the one-argument form in translator.cpp.
+
+  if (consumeNext(item, theChildren[0].getp(), planState))
   {
+    store::Item_t item_uri;
+    if (GENV_STORE.getNodeReference(item_uri, item.getp()))
     {
-      zstring uri_string, lRes;
-      if(consumeNext(item, theChildren[0].getp(), planState))
-      {
-        store::Item_t item_uri;
-        if (GENV_STORE.getNodeReference(item_uri, item.getp()))
-        {
-          uri_string = item_uri->getStringValue();
-          // need to convert the opaque uri into a valid ncname
-#ifndef NDEBUG
-          ZORBA_ASSERT( uri_string.find_first_of("urn:uuid:") == 0 );
-#endif
-          lRes = "u" + uri_string.substr(9);
-        }
-      }
-      retval = GENV_ITEMFACTORY->createString(result, lRes);
+      item_uri->getStringValue2( id );
+      // need to convert the opaque uri into a valid ncname
+      if ( ascii::begins_with( id, "urn:uuid:" ) )
+        id.erase( 0, 9 );
+      ascii::remove_not_chars( id, ascii::alnum );
+      id.insert( (zstring::size_type)0, 1, 'u' );
     }
-    STACK_PUSH(retval, state);
   }
-
-  STACK_END (state);
+  GENV_ITEMFACTORY->createString(result, id);
+  STACK_PUSH(true, state);
+  STACK_END(state);
 }
 
 

=== modified file 'src/util/ascii_util.h'
--- src/util/ascii_util.h	2013-05-01 03:57:57 +0000
+++ src/util/ascii_util.h	2013-05-06 23:27:27 +0000
@@ -41,6 +41,9 @@
 
 ////////// constants //////////////////////////////////////////////////////////
 
+char const alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+char const alnum[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+char const digit[] = "0123456789";
 char const whitespace[] = " \f\n\r\t\v";
 
 ////////// Non-ASCII character stripping //////////////////////////////////////
@@ -814,7 +817,7 @@
  * Removes all specified characters by shifting the contents of the buffer to
  * the left.
  *
- * @param s The string.
+ * @param s The string to remove characters from.
  * @param s_len The length of \a s.
  * @param chars The characters to remove.
  * @return Returns the new length of \a s with all \a chars removed.
@@ -822,6 +825,15 @@
 size_type remove_chars( char *s, size_type s_len, char const *chars );
 
 /**
+ * Removes all characters that are not among the specified characters.
+ *
+ * @param s The string to remove characters from.
+ * @param keep_chars The characters to keep.
+ */
+template<class StringType>
+void remove_not_chars( StringType &s, char const *keep_chars );
+
+/**
  * Removes all whitespace characters by shifting the contents of the buffer to
  * the left.
  *

=== modified file 'src/util/ascii_util.tcc'
--- src/util/ascii_util.tcc	2013-02-07 17:24:36 +0000
+++ src/util/ascii_util.tcc	2013-05-06 23:27:27 +0000
@@ -56,6 +56,13 @@
 }
 
 template<class StringType>
+void remove_not_chars( StringType &s, char const *keep_chars ) {
+  typename StringType::size_type pos = 0;
+  while ( (pos = s.find_first_not_of( keep_chars, pos )) != StringType::npos )
+    s.erase( pos, 1 );
+}
+
+template<class StringType>
 bool replace_all( StringType &s, char from, char to ) {
   bool replaced_any = false;
   for ( typename StringType::size_type pos = 0; pos < s.size(); ++pos ) {

=== modified file 'test/fots/CMakeLists.txt'
--- test/fots/CMakeLists.txt	2013-05-06 09:20:46 +0000
+++ test/fots/CMakeLists.txt	2013-05-06 23:27:27 +0000
@@ -176,15 +176,8 @@
 EXPECTED_FOTS_FAILURE (fn-format-number numberformat83 1167643)
 EXPECTED_FOTS_FAILURE (fn-format-number numberformat87 1167641)
 EXPECTED_FOTS_FAILURE (fn-format-number numberformat88 1167641)
-EXPECTED_FOTS_FAILURE (fn-generate-id generate-id-001 0)
-EXPECTED_FOTS_FAILURE (fn-generate-id generate-id-002 0)
-EXPECTED_FOTS_FAILURE (fn-generate-id generate-id-003 0)
-EXPECTED_FOTS_FAILURE (fn-generate-id generate-id-004 0)
-EXPECTED_FOTS_FAILURE (fn-generate-id generate-id-005 0)
-EXPECTED_FOTS_FAILURE (fn-generate-id generate-id-006 0)
-EXPECTED_FOTS_FAILURE (fn-generate-id generate-id-014 0)
-EXPECTED_FOTS_FAILURE (fn-generate-id generate-id-015 0)
-EXPECTED_FOTS_FAILURE (fn-generate-id generate-id-017 0)
+EXPECTED_FOTS_FAILURE (fn-generate-id generate-id-015 1090514)
+EXPECTED_FOTS_FAILURE (fn-generate-id generate-id-017 1090514)
 EXPECTED_FOTS_FAILURE (fn-matches cbcl-matches-038 1131304)
 EXPECTED_FOTS_FAILURE (fn-normalize-space fn-normalize-space-23 0)
 EXPECTED_FOTS_FAILURE (fn-normalize-space fn-normalize-space-25 0)

-- 
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