lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [46/47] lucenenet git commit: Codecs.SimpleText: Fixed several bugs due to string parsing/formatting without invariant culture, missing CompareTo() calls, and missing null checks.
Date Tue, 11 Oct 2016 18:35:31 GMT
Codecs.SimpleText: Fixed several bugs due to string parsing/formatting without invariant culture,
missing CompareTo() calls, and missing null checks.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/7d1915a9
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/7d1915a9
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/7d1915a9

Branch: refs/heads/master
Commit: 7d1915a9b6804c954804bb9a013827e271412f47
Parents: fbc171b
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Tue Oct 11 17:09:36 2016 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Wed Oct 12 01:11:00 2016 +0700

----------------------------------------------------------------------
 .../SimpleText/SimpleTextFieldsReader.cs        | 16 +++++++-------
 .../SimpleText/SimpleTextFieldsWriter.cs        | 17 ++++++++-------
 .../SimpleText/SimpleTextLiveDocsFormat.cs      |  5 +++--
 .../SimpleText/SimpleTextSegmentInfoWriter.cs   |  9 ++++----
 .../SimpleText/SimpleTextStoredFieldsWriter.cs  |  4 ++--
 .../SimpleText/SimpleTextTermVectorsWriter.cs   | 23 ++++++++++----------
 6 files changed, 39 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7d1915a9/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs
index 1bc6c17..da964ba 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsReader.cs
@@ -199,7 +199,7 @@ namespace Lucene.Net.Codecs.SimpleText
             public override DocsEnum Docs(Bits liveDocs, DocsEnum reuse, int flags)
             {
                 SimpleTextDocsEnum docsEnum;
-                if (reuse is SimpleTextDocsEnum && ((SimpleTextDocsEnum) reuse).CanReuse(_outerInstance._input))
+                if (reuse != null && reuse is SimpleTextDocsEnum && ((SimpleTextDocsEnum)
reuse).CanReuse(_outerInstance._input))
                 {
                     docsEnum = (SimpleTextDocsEnum) reuse;
                 }
@@ -214,14 +214,14 @@ namespace Lucene.Net.Codecs.SimpleText
             public override DocsAndPositionsEnum DocsAndPositions(Bits liveDocs, DocsAndPositionsEnum
reuse, int flags)
             {
 
-                if (_indexOptions < IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)
+                if (_indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) <
0)
                 {
                     // Positions were not indexed
                     return null;
                 }
 
                 SimpleTextDocsAndPositionsEnum docsAndPositionsEnum;
-                if (reuse is SimpleTextDocsAndPositionsEnum && ((SimpleTextDocsAndPositionsEnum)
reuse).CanReuse(_outerInstance._input))
+                if (reuse != null && reuse is SimpleTextDocsAndPositionsEnum &&
((SimpleTextDocsAndPositionsEnum) reuse).CanReuse(_outerInstance._input))
                 {
                     docsAndPositionsEnum = (SimpleTextDocsAndPositionsEnum) reuse;
                 }
@@ -399,8 +399,8 @@ namespace Lucene.Net.Codecs.SimpleText
                 _liveDocs = liveDocs;
                 _nextDocStart = fp;
                 _docId = -1;
-                _readPositions = indexOptions >= IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
-                _readOffsets = indexOptions >= IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
+                _readPositions = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)
>= 0;
+                _readOffsets = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS)
>= 0;
 
                 if (!_readOffsets)
                 {
@@ -709,18 +709,18 @@ namespace Lucene.Net.Codecs.SimpleText
 
             public override bool HasFreqs()
             {
-                return _fieldInfo.FieldIndexOptions >= IndexOptions.DOCS_AND_FREQS;
+                return _fieldInfo.FieldIndexOptions.GetValueOrDefault().CompareTo(IndexOptions.DOCS_AND_FREQS)
>= 0;
             }
 
             public override bool HasOffsets()
             {
                 return
-                    _fieldInfo.FieldIndexOptions >= IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
+                    _fieldInfo.FieldIndexOptions.GetValueOrDefault().CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS)
>= 0;
             }
 
             public override bool HasPositions()
             {
-                return _fieldInfo.FieldIndexOptions >= IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
+                return _fieldInfo.FieldIndexOptions.GetValueOrDefault().CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)
>= 0;
             }
 
             public override bool HasPayloads()

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7d1915a9/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs
index 465d97b..ec54003 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs
@@ -16,8 +16,9 @@
  */
 
 using System;
-using System.Diagnostics;
 using System.Collections.Generic;
+using System.Diagnostics;
+using System.Globalization;
 
 namespace Lucene.Net.Codecs.SimpleText
 {
@@ -136,8 +137,8 @@ namespace Lucene.Net.Codecs.SimpleText
             {
                 _outerInstance = outerInstance;
                 _indexOptions = field.FieldIndexOptions.Value;
-                _writePositions = _indexOptions >= IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
-                _writeOffsets = _indexOptions >= IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
+                _writePositions = _indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)
>= 0;
+                _writeOffsets = _indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS)
>= 0;
             }
 
             public override void StartDoc(int docId, int termDocFreq)
@@ -152,12 +153,12 @@ namespace Lucene.Net.Codecs.SimpleText
                 }
 
                 _outerInstance.Write(DOC);
-                _outerInstance.Write(Convert.ToString(docId));
+                _outerInstance.Write(Convert.ToString(docId, CultureInfo.InvariantCulture));
                 _outerInstance.Newline();
                 if (_indexOptions != IndexOptions.DOCS_ONLY)
                 {
                     _outerInstance.Write(FREQ);
-                    _outerInstance.Write(Convert.ToString(termDocFreq));
+                    _outerInstance.Write(Convert.ToString(termDocFreq, CultureInfo.InvariantCulture));
                     _outerInstance.Newline();
                 }
 
@@ -176,7 +177,7 @@ namespace Lucene.Net.Codecs.SimpleText
                 if (_writePositions)
                 {
                     _outerInstance.Write(POS);
-                    _outerInstance.Write(Convert.ToString(position));
+                    _outerInstance.Write(Convert.ToString(position, CultureInfo.InvariantCulture));
                     _outerInstance.Newline();
                 }
 
@@ -187,10 +188,10 @@ namespace Lucene.Net.Codecs.SimpleText
                         "startOffset=" + startOffset + " lastStartOffset=" + _lastStartOffset);
                     _lastStartOffset = startOffset;
                     _outerInstance.Write(START_OFFSET);
-                    _outerInstance.Write(Convert.ToString(startOffset));
+                    _outerInstance.Write(Convert.ToString(startOffset, CultureInfo.InvariantCulture));
                     _outerInstance.Newline();
                     _outerInstance.Write(END_OFFSET);
-                    _outerInstance.Write(Convert.ToString(endOffset));
+                    _outerInstance.Write(Convert.ToString(endOffset, CultureInfo.InvariantCulture));
                     _outerInstance.Newline();
                 }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7d1915a9/src/Lucene.Net.Codecs/SimpleText/SimpleTextLiveDocsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextLiveDocsFormat.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextLiveDocsFormat.cs
index 57c50f4..5b7db99 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextLiveDocsFormat.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextLiveDocsFormat.cs
@@ -22,6 +22,7 @@ namespace Lucene.Net.Codecs.SimpleText
     using System.Diagnostics;
     using System.Collections;
     using System.Collections.Generic;
+    using System.Globalization;
     using Support;
 
 	using IndexFileNames = Index.IndexFileNames;
@@ -133,13 +134,13 @@ namespace Lucene.Net.Codecs.SimpleText
             {
                 output = dir.CreateOutput(fileName, context);
                 SimpleTextUtil.Write(output, SIZE);
-                SimpleTextUtil.Write(output, Convert.ToString(size), scratch);
+                SimpleTextUtil.Write(output, Convert.ToString(size, CultureInfo.InvariantCulture),
scratch);
                 SimpleTextUtil.WriteNewline(output);
 
                 for (int i = set.NextSetBit(0); i >= 0; i = set.NextSetBit(i + 1))
                 {
                     SimpleTextUtil.Write(output, DOC);
-                    SimpleTextUtil.Write(output, Convert.ToString(i), scratch);
+                    SimpleTextUtil.Write(output, Convert.ToString(i, CultureInfo.InvariantCulture),
scratch);
                     SimpleTextUtil.WriteNewline(output);
                 }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7d1915a9/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoWriter.cs
index 35d0437..0c77fda 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoWriter.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoWriter.cs
@@ -19,6 +19,7 @@ namespace Lucene.Net.Codecs.SimpleText
 {
     using System;
     using System.Collections.Generic;
+    using System.Globalization;
 
     using FieldInfos = Index.FieldInfos;
     using IndexFileNames = Index.IndexFileNames;
@@ -65,17 +66,17 @@ namespace Lucene.Net.Codecs.SimpleText
                 SimpleTextUtil.WriteNewline(output);
 
                 SimpleTextUtil.Write(output, SI_DOCCOUNT);
-                SimpleTextUtil.Write(output, Convert.ToString(si.DocCount), scratch);
+                SimpleTextUtil.Write(output, Convert.ToString(si.DocCount, CultureInfo.InvariantCulture),
scratch);
                 SimpleTextUtil.WriteNewline(output);
 
                 SimpleTextUtil.Write(output, SI_USECOMPOUND);
-                SimpleTextUtil.Write(output, Convert.ToString(si.UseCompoundFile), scratch);
+                SimpleTextUtil.Write(output, Convert.ToString(si.UseCompoundFile, CultureInfo.InvariantCulture).ToLowerInvariant(),
scratch);
                 SimpleTextUtil.WriteNewline(output);
 
                 IDictionary<string, string> diagnostics = si.Diagnostics;
                 int numDiagnostics = diagnostics == null ? 0 : diagnostics.Count;
                 SimpleTextUtil.Write(output, SI_NUM_DIAG);
-                SimpleTextUtil.Write(output, Convert.ToString(numDiagnostics), scratch);
+                SimpleTextUtil.Write(output, Convert.ToString(numDiagnostics, CultureInfo.InvariantCulture),
scratch);
                 SimpleTextUtil.WriteNewline(output);
 
                 if (numDiagnostics > 0)
@@ -95,7 +96,7 @@ namespace Lucene.Net.Codecs.SimpleText
                 var files = si.Files;
                 var numFiles = files == null ? 0 : files.Count;
                 SimpleTextUtil.Write(output, SI_NUM_FILES);
-                SimpleTextUtil.Write(output, Convert.ToString(numFiles), scratch);
+                SimpleTextUtil.Write(output, Convert.ToString(numFiles, CultureInfo.InvariantCulture),
scratch);
                 SimpleTextUtil.WriteNewline(output);
 
                 if (numFiles > 0)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7d1915a9/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs
index ebfc9b5..369ab1b 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs
@@ -86,11 +86,11 @@ namespace Lucene.Net.Codecs.SimpleText
         public override void StartDocument(int numStoredFields)
 	    {
 	        Write(DOC);
-	        Write(Convert.ToString(_numDocsWritten));
+	        Write(Convert.ToString(_numDocsWritten, CultureInfo.InvariantCulture));
 	        NewLine();
 
 	        Write(NUM);
-	        Write(Convert.ToString(numStoredFields));
+	        Write(Convert.ToString(numStoredFields, CultureInfo.InvariantCulture));
 	        NewLine();
 
 	        _numDocsWritten++;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7d1915a9/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsWriter.cs
index 3425006..c52eb1e 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsWriter.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextTermVectorsWriter.cs
@@ -21,6 +21,7 @@ namespace Lucene.Net.Codecs.SimpleText
     using System;
     using System.Diagnostics;
     using System.Collections.Generic;
+    using System.Globalization;
     using FieldInfo = Index.FieldInfo;
     using FieldInfos = Index.FieldInfos;
     using IndexFileNames = Index.IndexFileNames;
@@ -89,11 +90,11 @@ namespace Lucene.Net.Codecs.SimpleText
         public override void StartDocument(int numVectorFields)
         {
             Write(DOC);
-            Write(Convert.ToString(_numDocsWritten));
+            Write(Convert.ToString(_numDocsWritten, CultureInfo.InvariantCulture));
             NewLine();
 
             Write(NUMFIELDS);
-            Write(Convert.ToString(numVectorFields));
+            Write(Convert.ToString(numVectorFields, CultureInfo.InvariantCulture));
             NewLine();
             _numDocsWritten++;
         }
@@ -101,7 +102,7 @@ namespace Lucene.Net.Codecs.SimpleText
         public override void StartField(FieldInfo info, int numTerms, bool positions, bool
offsets, bool payloads)
         {
             Write(FIELD);
-            Write(Convert.ToString(info.Number));
+            Write(Convert.ToString(info.Number, CultureInfo.InvariantCulture));
             NewLine();
 
             Write(FIELDNAME);
@@ -109,19 +110,19 @@ namespace Lucene.Net.Codecs.SimpleText
             NewLine();
 
             Write(FIELDPOSITIONS);
-            Write(Convert.ToString(positions));
+            Write(Convert.ToString(positions, CultureInfo.InvariantCulture).ToLowerInvariant());
             NewLine();
 
             Write(FIELDOFFSETS);
-            Write(Convert.ToString(offsets));
+            Write(Convert.ToString(offsets, CultureInfo.InvariantCulture).ToLowerInvariant());
             NewLine();
 
             Write(FIELDPAYLOADS);
-            Write(Convert.ToString(payloads));
+            Write(Convert.ToString(payloads, CultureInfo.InvariantCulture).ToLowerInvariant());
             NewLine();
 
             Write(FIELDTERMCOUNT);
-            Write(Convert.ToString(numTerms));
+            Write(Convert.ToString(numTerms, CultureInfo.InvariantCulture));
             NewLine();
 
             _positions = positions;
@@ -136,7 +137,7 @@ namespace Lucene.Net.Codecs.SimpleText
             NewLine();
 
             Write(TERMFREQ);
-            Write(Convert.ToString(freq));
+            Write(Convert.ToString(freq, CultureInfo.InvariantCulture));
             NewLine();
         }
 
@@ -147,7 +148,7 @@ namespace Lucene.Net.Codecs.SimpleText
             if (_positions)
             {
                 Write(POSITION);
-                Write(Convert.ToString(position));
+                Write(Convert.ToString(position, CultureInfo.InvariantCulture));
                 NewLine();
 
                 if (_payloads)
@@ -165,11 +166,11 @@ namespace Lucene.Net.Codecs.SimpleText
             if (_offsets)
             {
                 Write(STARTOFFSET);
-                Write(Convert.ToString(startOffset));
+                Write(Convert.ToString(startOffset, CultureInfo.InvariantCulture));
                 NewLine();
 
                 Write(ENDOFFSET);
-                Write(Convert.ToString(endOffset));
+                Write(Convert.ToString(endOffset, CultureInfo.InvariantCulture));
                 NewLine();
             }
         }


Mime
View raw message