chiark / gitweb /
test and fix utf32_iterator_set()
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 18 Nov 2007 23:07:22 +0000 (23:07 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 18 Nov 2007 23:07:22 +0000 (23:07 +0000)
lib/test.c
lib/unicode.c

index 4b073a8b8fdfc75cab205d6a03ad1cd49705f7c3..04346fe621a21e16002d1cd29bd75b2c8752f837 100644 (file)
@@ -514,8 +514,10 @@ static void breaktest(const char *path,
     for(n = 0; n <= bn; ++n) {
       if(breakfn(buffer, bn, n) != break_allowed[n]) {
         fprintf(stderr,
-                "%s:%d: offset %zu: mismatch\n",
-                path, lineno, n);
+                "%s:%d: offset %zu: mismatch\n"
+                "%s\n"
+                "\n",
+                path, lineno, n, l);
         count_error();
       }
       ++tests;
index 5b48b3cc53c6cf3952ab334ce071999b54721e1f..26363f29c9540361064f452a04d2f5ed120a7dfe 100644 (file)
@@ -371,7 +371,7 @@ static void utf32__iterator_init(utf32_iterator it,
   it->ns = ns;
   it->n = 0;
   it->last[0] = it->last[1] = -1;
-  utf32_iterator_advance(it, n);
+  utf32_iterator_set(it, n);
 }
 
 /** @brief Destroy an iterator
@@ -404,15 +404,26 @@ int utf32_iterator_set(utf32_iterator it, size_t n) {
    * non-ignorable code points as we advance forwards, so we'd better pass two
    * such characters on the way back (if such are available).
    */
-  size_t m = n;
-  int i;
+  size_t m;
 
   if(n > it->ns)                        /* range check */
     return -1;
-  for(i = 0; i < 2; ++i)
-    while(m > 0
-          && utf32__boundary_ignorable(utf32__word_break(it->s[m - 1])))
+  /* Walk backwards skipping ignorable code points */
+  m = n;
+  while(m > 0 && (utf32__boundary_ignorable(utf32__word_break(it->s[m-1]))))
+    --m;
+  /* Either m=0 or s[m-1] is not ignorable */
+  if(m > 0) {
+    --m;
+    /* s[m] is our first non-ignorable code; look for a second in the same
+       way **/
+    while(m > 0 && (utf32__boundary_ignorable(utf32__word_break(it->s[m-1]))))
       --m;
+    /* Either m=0 or s[m-1] is not ignorable */
+    if(m > 0)
+      --m;
+  }
+  it->last[0] = it->last[1] = -1;
   it->n = m;
   return utf32_iterator_advance(it, n - m);
 }