lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r930417 - in /lucene/lucy/trunk/core/Lucy/Index: Segment.bp Segment.c
Date Fri, 02 Apr 2010 22:17:25 GMT
Author: marvin
Date: Fri Apr  2 22:17:25 2010
New Revision: 930417

URL: http://svn.apache.org/viewvc?rev=930417&view=rev
Log:
Add a Seg_valid_seg_name() inert function to Segment.

Modified:
    lucene/lucy/trunk/core/Lucy/Index/Segment.bp
    lucene/lucy/trunk/core/Lucy/Index/Segment.c

Modified: lucene/lucy/trunk/core/Lucy/Index/Segment.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Index/Segment.bp?rev=930417&r1=930416&r2=930417&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Index/Segment.bp (original)
+++ lucene/lucy/trunk/core/Lucy/Index/Segment.bp Fri Apr  2 22:17:25 2010
@@ -35,6 +35,12 @@ class Lucy::Index::Segment cnick Seg ext
     inert incremented CharBuf*
     num_to_name(i64_t number);
 
+    /** Return true if the CharBuf is a segment name, i.e. matches this
+     * pattern:  /^seg_\w+$/
+     */
+    inert bool_t
+    valid_seg_name(const CharBuf *name);
+
     /** Register a new field and assign it a field number.  If the field was
      * already known, nothing happens.
      * 

Modified: lucene/lucy/trunk/core/Lucy/Index/Segment.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Index/Segment.c?rev=930417&r1=930416&r2=930417&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Index/Segment.c (original)
+++ lucene/lucy/trunk/core/Lucy/Index/Segment.c Fri Apr  2 22:17:25 2010
@@ -1,3 +1,5 @@
+#include <ctype.h>
+
 #define C_LUCY_SEGMENT
 #include "Lucy/Util/ToolSet.h"
 
@@ -46,6 +48,22 @@ Seg_num_to_name(i64_t number)
     return CB_newf("seg_%s", &base36);
 }
 
+bool_t
+Seg_valid_seg_name(const CharBuf *name)
+{
+    if (CB_Starts_With_Str(name, "seg_", 4)) {
+        size_t size = ZCB_size() + CB_Get_Size(name) + 1;
+        ZombieCharBuf *scratch = ZCB_wrap(alloca(size), name);
+        ZCB_Nip(scratch, 4);
+        uint32_t code_point;
+        while (0 != (code_point = ZCB_Nip_One(scratch))) {
+            if (!isalnum(code_point)) { return false; }
+        }
+        if (ZCB_Get_Size(scratch) == 0) { return true; } // Success!
+    }
+    return false;
+}
+
 void
 Seg_destroy(Segment *self)
 {



Mime
View raw message