lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [Lucene.Net] svn commit: r1132400 - in /incubator/lucene.net/trunk: src/core/Index/ReusableStringReader.cs test/core/TestSupportClass.cs
Date Sun, 05 Jun 2011 13:27:34 GMT
Author: digy
Date: Sun Jun  5 13:27:34 2011
New Revision: 1132400

URL: http://svn.apache.org/viewvc?rev=1132400&view=rev
Log:
[LUCENENET-422] Custom tokenizers may fail when indexing due to ReusableStringReader not implement
some method of TextReader

Modified:
    incubator/lucene.net/trunk/src/core/Index/ReusableStringReader.cs
    incubator/lucene.net/trunk/test/core/TestSupportClass.cs

Modified: incubator/lucene.net/trunk/src/core/Index/ReusableStringReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/ReusableStringReader.cs?rev=1132400&r1=1132399&r2=1132400&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/ReusableStringReader.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/ReusableStringReader.cs Sun Jun  5 13:27:34
2011
@@ -69,28 +69,62 @@ namespace Lucene.Net.Index
 
         public override int Read()
         {
-            throw new NotImplementedException("This method is not implemented");
+            if (left > 0)
+            {
+                char ch = s[upto];
+                upto += 1;
+                left -= 1;
+                return (int)ch;
+            }
+            return -1;
         }
 
         public override int ReadBlock(char[] buffer, int index, int count)
         {
-            throw new NotImplementedException("This method is not implemented");
+            return Read(buffer, index, count);
         }
 
         public override string ReadLine()
         {
-            throw new NotImplementedException("This method is not implemented");
+            int i;
+            for (i = upto; i < s.Length; i++)
+            {
+                char c = s[i];
+                if (c == '\r' || c == '\n')
+                {
+                    string result = s.Substring(upto, i - upto);
+                    upto = i + 1;
+                    left = s.Length - upto;
+                    if (c == '\r' && upto < s.Length && s[upto] == '\n')
+                    {
+                        upto++;
+                        left--;
+                    }
+                    return result;
+                }
+            }
+            if (i > upto)
+            {
+                return ReadToEnd();
+            }
+            return null;
         }
 
         public override int Peek()
         {
-            throw new NotImplementedException("This method is not implemented");
+            if (left > 0)
+            {
+                return (int)s[upto];
+            }
+            return -1;
         }
 
         public override string ReadToEnd()
         {
+            string result = s.Substring(upto, left);
             left = 0;
-            return s;
+            upto = s.Length - 1;
+            return result;
         }
     }
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/test/core/TestSupportClass.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/TestSupportClass.cs?rev=1132400&r1=1132399&r2=1132400&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/TestSupportClass.cs (original)
+++ incubator/lucene.net/trunk/test/core/TestSupportClass.cs Sun Jun  5 13:27:34 2011
@@ -985,7 +985,7 @@ namespace Lucene.Net._SupportClass
             wr.Close();
         }
 
-        static string TEST_STRING = "Some Text and some more Text";
+        static string TEST_STRING = "First Line\nSecond Line";
 
         class TestAnalyzer : Lucene.Net.Analysis.Analyzer
         {
@@ -995,20 +995,23 @@ namespace Lucene.Net._SupportClass
             }
         }
 
-        class TestTokenizer : Lucene.Net.Analysis.CharTokenizer
+        class TestTokenizer : Lucene.Net.Analysis.Tokenizer
         {
             public TestTokenizer(System.IO.TextReader Reader)
-                : base(Reader)
             {
                 //Caution: "Reader" is actually of type "ReusableStringReader" and some 
                 //methods (for ex. "ReadToEnd", "Peek",  "ReadLine") is not implemented.

-                Assert.AreEqual(TEST_STRING, Reader.ReadToEnd(), "Issue LUCENENET-150: \"ReadToEnd\"
method is not implemented");
+
+                Assert.AreEqual("ReusableStringReader", Reader.GetType().Name);
+                Assert.AreEqual("First Line", Reader.ReadLine(), "\"ReadLine\" method is
not implemented");
+                Assert.AreEqual("Second Line", Reader.ReadToEnd(), "\"ReadToEnd\" method
is not implemented");
             }
 
-            protected override bool IsTokenChar(char c)
+            public override Token Next()
             {
-                return char.IsLetterOrDigit(c);
+                return null;
             }
+
         }
 
         [Test]



Mime
View raw message