lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] svn commit: r1378773 - in /lucy/trunk/clownfish: perl/t/051-symbol.t src/CFCSymbol.c
Date Thu, 30 Aug 2012 00:09:03 GMT
Author: marvin
Date: Thu Aug 30 00:09:03 2012
New Revision: 1378773

URL: http://svn.apache.org/viewvc?rev=1378773&view=rev
Log:
Relax class name restrictions slightly.

Require that the last class name component contain lower case letters,
but allow all upper case in prior components: FOO::BAR::Baz

Modified:
    lucy/trunk/clownfish/perl/t/051-symbol.t
    lucy/trunk/clownfish/src/CFCSymbol.c

Modified: lucy/trunk/clownfish/perl/t/051-symbol.t
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/perl/t/051-symbol.t?rev=1378773&r1=1378772&r2=1378773&view=diff
==============================================================================
--- lucy/trunk/clownfish/perl/t/051-symbol.t (original)
+++ lucy/trunk/clownfish/perl/t/051-symbol.t Thu Aug 30 00:09:03 2012
@@ -16,10 +16,10 @@
 use strict;
 use warnings;
 
-use Test::More tests => 44;
+use Test::More tests => 40;
 use Clownfish::CFC;
 
-for (qw( foo FOO 1Foo Foo_Bar FOOBAR 1FOOBAR )) {
+for (qw( foo 1Foo Foo_Bar 1FOOBAR )) {
     eval { my $thing = new_symbol( class_name => $_ ) };
     like( $@, qr/class_name/, "Reject invalid class name $_" );
     my $bogus_middle = "Foo::" . $_ . "::Bar";

Modified: lucy/trunk/clownfish/src/CFCSymbol.c
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCSymbol.c?rev=1378773&r1=1378772&r2=1378773&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCSymbol.c (original)
+++ lucy/trunk/clownfish/src/CFCSymbol.c Thu Aug 30 00:09:03 2012
@@ -57,32 +57,29 @@ S_validate_exposure(const char *exposure
 
 static int
 S_validate_class_name(const char *class_name) {
-    const char *ptr;
+    // The last component must contain lowercase letters (for now).
+    const char *last_colon = strrchr(class_name, ':');
+    const char *substring = last_colon ? last_colon + 1 : class_name;
+    for (;;substring++) {
+        if (*substring == 0)          { return false; }
+        else if (*substring == ':')   { return false; }
+        else if (islower(*substring)) { break; }
+    }
 
     // Must be UpperCamelCase, separated by "::".
-    for (ptr = class_name; *ptr != 0;) {
-        if (!isupper(*ptr)) { return false; }
-
-        // Each component must contain lowercase letters.
-        const char *substring;
-        for (substring = ptr; ; substring++) {
-            if (*substring == 0)          { return false; }
-            else if (*substring == ':')   { return false; }
-            else if (islower(*substring)) { break; }
-        }
-
-        while (*ptr != 0) {
-            if (*ptr == 0) { break; }
-            else if (*ptr == ':') {
-                ptr++;
-                if (*ptr != ':') { return false; }
-                ptr++;
-                if (*ptr == 0) { return false; }
-                break;
-            }
-            else if (!isalnum(*ptr)) { return false; }
+    const char *ptr = class_name;
+    if (!isupper(*ptr)) { return false; }
+    while (*ptr != 0) {
+        if (*ptr == 0) { break; }
+        else if (*ptr == ':') {
+            ptr++;
+            if (*ptr != ':') { return false; }
+            ptr++;
+            if (!isupper(*ptr)) { return false; }
             ptr++;
         }
+        else if (!isalnum(*ptr)) { return false; }
+        else { ptr++; }
     }
 
     return true;



Mime
View raw message