FAQ

svn commit: r882422 - in /lucene/lucy/trunk: core/Lucy/Test/Util/ core/Lucy/Util/ perl/lib/Lucy/ perl/lib/Lucy/Util/ perl/t/core/

Marvin
Nov 20, 2009 at 6:01 am
Author: marvin
Date: Fri Nov 20 06:01:30 2009
New Revision: 882422

URL: http://svn.apache.org/viewvc?rev=882422&view=rev
Log:
Commit LUCY-66, adding Lucy::Util::IndexFileNames.

Added:
lucene/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.bp (with props)
lucene/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.c (with props)
lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.bp (with props)
lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.c (with props)
lucene/lucy/trunk/perl/lib/Lucy/Util/IndexFileNames.pm (with props)
lucene/lucy/trunk/perl/t/core/033-index_file_names.t (with props)
Modified:
lucene/lucy/trunk/perl/lib/Lucy/Test.pm

Added: lucene/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.bp?rev=882422&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.bp (added)
+++ lucene/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.bp Fri Nov 20 06:01:30 2009
@@ -0,0 +1,22 @@
+parcel Lucy;
+
+inert class Lucy::Test::Util::TestIndexFileNames cnick TestIxFileNames {
+ inert void
+ run_tests();
+}
+
+/* Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+

Propchange: lucene/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.bp
------------------------------------------------------------------------------
svn:eol-style = native

Added: lucene/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.c?rev=882422&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.c (added)
+++ lucene/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.c Fri Nov 20 06:01:30 2009
@@ -0,0 +1,88 @@
+#include "Lucy/Util/ToolSet.h"
+
+#include "Lucy/Test.h"
+#include "Lucy/Test/Util/TestIndexFileNames.h"
+#include "Lucy/Util/IndexFileNames.h"
+
+static void
+test_local_part(TestBatch *batch)
+{
+ ZombieCharBuf source = ZCB_BLANK;
+ ZombieCharBuf target = ZCB_BLANK;
+ ZombieCharBuf *got = ⌖
+
+ got = IxFileNames_local_part((CharBuf*)&source, got);
+ ASSERT_TRUE(batch, CB_Equals(got, (Obj*)&source), "simple name");
+
+ ZCB_Assign_Str(&source, "foo.txt", 7);
+ got = IxFileNames_local_part((CharBuf*)&source, got);
+ ASSERT_TRUE(batch, CB_Equals(got, (Obj*)&source), "name with extension");
+
+ ZCB_Assign_Str(&source, "/foo", 4);
+ got = IxFileNames_local_part((CharBuf*)&source, got);
+ ASSERT_TRUE(batch, CB_Equals_Str(got, "foo", 3), "strip leading slash");
+
+ ZCB_Assign_Str(&source, "/foo/", 5);
+ got = IxFileNames_local_part((CharBuf*)&source, got);
+ ASSERT_TRUE(batch, CB_Equals_Str(got, "foo", 3), "strip trailing slash");
+
+ ZCB_Assign_Str(&source, "foo/bar\\ ", 9);
+ got = IxFileNames_local_part((CharBuf*)&source, got);
+ ASSERT_TRUE(batch, CB_Equals_Str(got, "bar\\ ", 5),
+ "Include garbage like backslashes and spaces");
+
+ ZCB_Assign_Str(&source, "foo/bar/baz.txt", 15);
+ got = IxFileNames_local_part((CharBuf*)&source, got);
+ ASSERT_TRUE(batch, CB_Equals_Str(got, "baz.txt", 7), "find last component");
+}
+
+static void
+test_extract_gen(TestBatch *batch)
+{
+ ZombieCharBuf source = ZCB_BLANK;
+
+ source = ZCB_make_str("seg_9", 5);
+ ASSERT_INT_EQ(batch, IxFileNames_extract_gen((CharBuf*)&source), 9,
+ "extract_gen");
+
+ source = ZCB_make_str("seg_9/", 6);
+ ASSERT_INT_EQ(batch, IxFileNames_extract_gen((CharBuf*)&source), 9,
+ "deal with trailing slash");
+
+ source = ZCB_make_str("seg_9_8", 7);
+ ASSERT_INT_EQ(batch, IxFileNames_extract_gen((CharBuf*)&source), 9,
+ "Only go past first underscore");
+
+ source = ZCB_make_str("snapshot_5.json", 15);
+ ASSERT_INT_EQ(batch, IxFileNames_extract_gen((CharBuf*)&source), 5,
+ "Deal with file suffix");
+}
+
+void
+TestIxFileNames_run_tests()
+{
+ TestBatch *batch = Test_new_batch("TestIndexFileNames", 10, NULL);
+
+ PLAN(batch);
+
+ test_local_part(batch);
+ test_extract_gen(batch);
+
+ batch->destroy(batch);
+}
+
+/* Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+

Propchange: lucene/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.c
------------------------------------------------------------------------------
svn:eol-style = native

Added: lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.bp?rev=882422&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.bp (added)
+++ lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.bp Fri Nov 20 06:01:30 2009
@@ -0,0 +1,41 @@
+parcel Lucy;
+
+/** Utilities for parsing, interpreting and generating index file names.
+ */
+inert class Lucy::Util::IndexFileNames cnick IxFileNames {
+
+ /** Skip past the first instance of an underscore in the CharBuf, then
+ * attempt to decode a base 36 number. For example, "snapshot_5.json"
+ * yields 5, and "seg_a1" yields 27.
+ *
+ * @return a generation number, or 0 if no number can be extracted.
+ */
+ inert i32_t
+ extract_gen(const CharBuf *name);
+
+ /** Split the <code>path</code> on '/' and assign the last component to
+ * <code>target</code>, which will remain valid only as long as
+ * <code>path</code> is unmodified. Trailing slashes will be stripped.
+ *
+ * @param target The target string to assign to.
+ * @return target, allowing an assignment idiom.
+ */
+ inert ZombieCharBuf*
+ local_part(const CharBuf *path, ZombieCharBuf *target);
+}
+
+/* Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+

Propchange: lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.bp
------------------------------------------------------------------------------
svn:eol-style = native

Added: lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.c?rev=882422&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.c (added)
+++ lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.c Fri Nov 20 06:01:30 2009
@@ -0,0 +1,66 @@
+#define C_LUCY_INDEXFILENAMES
+#include "Lucy/Util/ToolSet.h"
+
+#include "Lucy/Util/IndexFileNames.h"
+#include "Lucy/Util/StringHelper.h"
+
+i32_t
+IxFileNames_extract_gen(const CharBuf *name)
+{
+ ZombieCharBuf num_string = ZCB_make(name);
+
+ /* Advance past first underscore. Bail if we run out of string or if we
+ * encounter a NULL. */
+ while (1) {
+ u32_t code_point = ZCB_Nip_One(&num_string);
+ if (code_point == 0) { return 0; }
+ else if (code_point == '_') { break; }
+ }
+
+ return (i32_t)ZCB_BaseX_To_I64(&num_string, 36);
+}
+
+ZombieCharBuf*
+IxFileNames_local_part(const CharBuf *path, ZombieCharBuf *target)
+{
+ ZombieCharBuf scratch = ZCB_make(path);
+ size_t local_part_start = CB_Length(path);
+ u32_t code_point;
+
+ ZCB_Assign(target, path);
+
+ /* Trim trailing slash. */
+ while (ZCB_Code_Point_From(target, 1) == '/') {
+ ZCB_Chop(target, 1);
+ ZCB_Chop(&scratch, 1);
+ local_part_start--;
+ }
+
+ /* Substring should start after last slash. */
+ while (0 != (code_point = ZCB_Code_Point_From(&scratch, 1))) {
+ if (code_point == '/') {
+ ZCB_Nip(target, local_part_start);
+ break;
+ }
+ ZCB_Chop(&scratch, 1);
+ local_part_start--;
+ }
+
+ return target;
+}
+
+/* Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+

Propchange: lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.c
------------------------------------------------------------------------------
svn:eol-style = native

Modified: lucene/lucy/trunk/perl/lib/Lucy/Test.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/perl/lib/Lucy/Test.pm?rev=882422&r1=882421&r2=882422&view=diff
==============================================================================
--- lucene/lucy/trunk/perl/lib/Lucy/Test.pm (original)
+++ lucene/lucy/trunk/perl/lib/Lucy/Test.pm Fri Nov 20 06:01:30 2009
@@ -53,6 +53,9 @@
lucy_TestRAMFH_run_tests();
}
/* Lucy::Util */
+ else if (strEQ(package, "TestIndexFileNames")) {
+ lucy_TestIxFileNames_run_tests();
+ }
else if (strEQ(package, "TestNumberUtils")) {
lucy_TestNumUtil_run_tests();
}

Added: lucene/lucy/trunk/perl/lib/Lucy/Util/IndexFileNames.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/perl/lib/Lucy/Util/IndexFileNames.pm?rev=882422&view=auto
==============================================================================
--- lucene/lucy/trunk/perl/lib/Lucy/Util/IndexFileNames.pm (added)
+++ lucene/lucy/trunk/perl/lib/Lucy/Util/IndexFileNames.pm Fri Nov 20 06:01:30 2009
@@ -0,0 +1,43 @@
+use Lucy;
+
+1;
+
+__END__
+
+__BINDING__
+
+my $xs_code = <<'END_XS_CODE';
+MODULE = Lucy PACKAGE = Lucy::Util::IndexFileNames
+
+IV
+extract_gen(name)
+ lucy_ZombieCharBuf name;
+CODE:
+ RETVAL = lucy_IxFileNames_extract_gen((lucy_CharBuf*)&name);
+OUTPUT: RETVAL
+END_XS_CODE
+
+Boilerplater::Binding::Perl::Class->register(
+ parcel => "Lucy",
+ class_name => "Lucy::Util::IndexFileNames",
+ xs_code => $xs_code,
+);
+
+__COPYRIGHT__
+
+ /**
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+

Propchange: lucene/lucy/trunk/perl/lib/Lucy/Util/IndexFileNames.pm
------------------------------------------------------------------------------
svn:eol-style = native

Added: lucene/lucy/trunk/perl/t/core/033-index_file_names.t
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/perl/t/core/033-index_file_names.t?rev=882422&view=auto
==============================================================================
--- lucene/lucy/trunk/perl/t/core/033-index_file_names.t (added)
+++ lucene/lucy/trunk/perl/t/core/033-index_file_names.t Fri Nov 20 06:01:30 2009
@@ -0,0 +1,6 @@
+use strict;
+use warnings;
+
+use Lucy::Test;
+Lucy::Test::run_tests("TestIndexFileNames");
+

Propchange: lucene/lucy/trunk/perl/t/core/033-index_file_names.t
------------------------------------------------------------------------------
svn:eol-style = native
reply

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post

1 user in discussion

Marvin: 1 post