gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r19136 - gnunet/src/fs


From: gnunet
Subject: [GNUnet-SVN] r19136 - gnunet/src/fs
Date: Sat, 14 Jan 2012 16:25:14 +0100

Author: grothoff
Date: 2012-01-14 16:25:14 +0100 (Sat, 14 Jan 2012)
New Revision: 19136

Modified:
   gnunet/src/fs/fs_uri.c
Log:
-LRN: use correct character counting, instead of byte counting

Modified: gnunet/src/fs/fs_uri.c
===================================================================
--- gnunet/src/fs/fs_uri.c      2012-01-14 15:24:01 UTC (rev 19135)
+++ gnunet/src/fs/fs_uri.c      2012-01-14 15:25:14 UTC (rev 19136)
@@ -1541,7 +1541,24 @@
   return (char *) normalized;
 }
 
+/**
+ * Counts the number of UTF-8 characters (not bytes) in the string,
+ * returns that count.
+ */
+static size_t
+u8_strcount (const uint8_t *s)
+{
+  size_t count;
+  ucs4_t c;
+  GNUNET_assert (s != NULL);
+  if (s[0] == 0)
+    return 0;
+  for (count = 0; s != NULL; count++)
+    s = u8_next (&c, s);
+  return count - 1;
+}
 
+
 /**
  * Break the filename up by matching [], () and {} pairs to make
  * keywords. In case of nesting parentheses only the inner pair counts.
@@ -1600,7 +1617,7 @@
       tmp = close_paren[0];
       close_paren[0] = '\0';
       /* Keywords must be at least 3 characters long */
-      if (u8_strlen ((const uint8_t *) &open_paren[1]) <= 2)
+      if (u8_strcount ((const uint8_t *) &open_paren[1]) <= 2)
       {
         close_paren[0] = tmp;
         continue;
@@ -1669,7 +1686,7 @@
   for (p = strtok (ss, TOKENS); p != NULL; p = strtok (NULL, TOKENS))
   {
     /* Keywords must be at least 3 characters long */
-    if (u8_strlen ((const uint8_t *) p) <= 2)
+    if (u8_strcount ((const uint8_t *) p) <= 2)
       continue;
     if (NULL != array)
     {
@@ -1735,7 +1752,7 @@
    * and will return the length of its valid part, skipping the keyword.
    * If it does - fix the extractor, not this check!
    */
-  if (u8_strlen ((const uint8_t *) data) <= 2)
+  if (u8_strcount ((const uint8_t *) data) <= 2)
   {
     return 0;
   }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]