You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2019/09/06 09:01:12 UTC
[lucenenet] 02/21: SWEEP: Lucene.Net - Changed internal number to
string and string to number conversions to use invariant culture. Removed
no-op Convert.ToInt32 and Convert.ToInt64 methods.
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit de629d8c8217abe42d340bbd5cd61ebc49480bd8
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Wed Sep 4 19:01:23 2019 +0700
SWEEP: Lucene.Net - Changed internal number to string and string to number conversions to use invariant culture. Removed no-op Convert.ToInt32 and Convert.ToInt64 methods.
---
src/Lucene.Net/Document/DateTools.cs | 71 +++++++++++-----------
src/Lucene.Net/Index/BufferedUpdates.cs | 6 +-
src/Lucene.Net/Index/CheckIndex.cs | 8 +--
.../Index/DocumentsWriterFlushControl.cs | 6 +-
src/Lucene.Net/Index/FieldInfos.cs | 4 +-
src/Lucene.Net/Index/IndexCommit.cs | 2 +-
.../Index/NumericDocValuesFieldUpdates.cs | 2 +-
.../Index/PersistentSnapshotDeletionPolicy.cs | 3 +-
src/Lucene.Net/Index/StandardDirectoryReader.cs | 2 +-
src/Lucene.Net/Search/FieldComparator.cs | 4 +-
src/Lucene.Net/Search/MultiPhraseQuery.cs | 2 +-
src/Lucene.Net/Search/NumericRangeQuery.cs | 17 +++---
src/Lucene.Net/Search/PhraseQuery.cs | 2 +-
src/Lucene.Net/Store/FSDirectory.cs | 3 +-
src/Lucene.Net/Store/LockStressTest.cs | 9 +--
src/Lucene.Net/Store/LockVerifyServer.cs | 2 +-
src/Lucene.Net/Store/RAMDirectory.cs | 3 +-
src/Lucene.Net/Support/AssemblyUtils.cs | 3 +-
src/Lucene.Net/Support/AtomicInteger.cs | 15 +++++
src/Lucene.Net/Support/AtomicLong.cs | 15 +++++
src/Lucene.Net/Support/Character.cs | 18 ++++++
src/Lucene.Net/Support/StringBuilderExtensions.cs | 2 +-
src/Lucene.Net/Util/Automaton/BasicAutomata.cs | 5 +-
src/Lucene.Net/Util/Automaton/RegExp.cs | 13 ++--
src/Lucene.Net/Util/Automaton/Transition.cs | 3 +-
src/Lucene.Net/Util/Fst/PositiveIntOutputs.cs | 2 +-
src/Lucene.Net/Util/Fst/Util.cs | 3 +-
src/Lucene.Net/Util/RamUsageEstimator.cs | 2 +-
28 files changed, 143 insertions(+), 84 deletions(-)
diff --git a/src/Lucene.Net/Document/DateTools.cs b/src/Lucene.Net/Document/DateTools.cs
index 2edfe7f..568984d 100644
--- a/src/Lucene.Net/Document/DateTools.cs
+++ b/src/Lucene.Net/Document/DateTools.cs
@@ -1,4 +1,5 @@
using System;
+using System.Globalization;
namespace Lucene.Net.Documents
{
@@ -78,31 +79,31 @@ namespace Lucene.Net.Documents
if (resolution == Resolution.YEAR)
{
- return date.ToString(YEAR_FORMAT, System.Globalization.CultureInfo.InvariantCulture);
+ return date.ToString(YEAR_FORMAT, CultureInfo.InvariantCulture);
}
else if (resolution == Resolution.MONTH)
{
- return date.ToString(MONTH_FORMAT, System.Globalization.CultureInfo.InvariantCulture);
+ return date.ToString(MONTH_FORMAT, CultureInfo.InvariantCulture);
}
else if (resolution == Resolution.DAY)
{
- return date.ToString(DAY_FORMAT, System.Globalization.CultureInfo.InvariantCulture);
+ return date.ToString(DAY_FORMAT, CultureInfo.InvariantCulture);
}
else if (resolution == Resolution.HOUR)
{
- return date.ToString(HOUR_FORMAT, System.Globalization.CultureInfo.InvariantCulture);
+ return date.ToString(HOUR_FORMAT, CultureInfo.InvariantCulture);
}
else if (resolution == Resolution.MINUTE)
{
- return date.ToString(MINUTE_FORMAT, System.Globalization.CultureInfo.InvariantCulture);
+ return date.ToString(MINUTE_FORMAT, CultureInfo.InvariantCulture);
}
else if (resolution == Resolution.SECOND)
{
- return date.ToString(SECOND_FORMAT, System.Globalization.CultureInfo.InvariantCulture);
+ return date.ToString(SECOND_FORMAT, CultureInfo.InvariantCulture);
}
else if (resolution == Resolution.MILLISECOND)
{
- return date.ToString(MILLISECOND_FORMAT, System.Globalization.CultureInfo.InvariantCulture);
+ return date.ToString(MILLISECOND_FORMAT, CultureInfo.InvariantCulture);
}
throw new ArgumentException("unknown resolution " + resolution);
@@ -136,58 +137,58 @@ namespace Lucene.Net.Documents
DateTime date;
if (dateString.Length == 4)
{
- date = new DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
+ date = new DateTime(Convert.ToInt16(dateString.Substring(0, 4), CultureInfo.InvariantCulture),
1, 1, 0, 0, 0, 0);
}
else if (dateString.Length == 6)
{
- date = new DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
- Convert.ToInt16(dateString.Substring(4, 2)),
+ date = new DateTime(Convert.ToInt16(dateString.Substring(0, 4), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(4, 2), CultureInfo.InvariantCulture),
1, 0, 0, 0, 0);
}
else if (dateString.Length == 8)
{
- date = new DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
- Convert.ToInt16(dateString.Substring(4, 2)),
- Convert.ToInt16(dateString.Substring(6, 2)),
+ date = new DateTime(Convert.ToInt16(dateString.Substring(0, 4), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(4, 2), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(6, 2), CultureInfo.InvariantCulture),
0, 0, 0, 0);
}
else if (dateString.Length == 10)
{
- date = new DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
- Convert.ToInt16(dateString.Substring(4, 2)),
- Convert.ToInt16(dateString.Substring(6, 2)),
- Convert.ToInt16(dateString.Substring(8, 2)),
+ date = new DateTime(Convert.ToInt16(dateString.Substring(0, 4), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(4, 2), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(6, 2), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(8, 2), CultureInfo.InvariantCulture),
0, 0, 0);
}
else if (dateString.Length == 12)
{
- date = new DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
- Convert.ToInt16(dateString.Substring(4, 2)),
- Convert.ToInt16(dateString.Substring(6, 2)),
- Convert.ToInt16(dateString.Substring(8, 2)),
- Convert.ToInt16(dateString.Substring(10, 2)),
+ date = new DateTime(Convert.ToInt16(dateString.Substring(0, 4), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(4, 2), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(6, 2), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(8, 2), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(10, 2), CultureInfo.InvariantCulture),
0, 0);
}
else if (dateString.Length == 14)
{
- date = new DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
- Convert.ToInt16(dateString.Substring(4, 2)),
- Convert.ToInt16(dateString.Substring(6, 2)),
- Convert.ToInt16(dateString.Substring(8, 2)),
- Convert.ToInt16(dateString.Substring(10, 2)),
- Convert.ToInt16(dateString.Substring(12, 2)),
+ date = new DateTime(Convert.ToInt16(dateString.Substring(0, 4), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(4, 2), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(6, 2), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(8, 2), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(10, 2), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(12, 2), CultureInfo.InvariantCulture),
0);
}
else if (dateString.Length == 17)
{
- date = new DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
- Convert.ToInt16(dateString.Substring(4, 2)),
- Convert.ToInt16(dateString.Substring(6, 2)),
- Convert.ToInt16(dateString.Substring(8, 2)),
- Convert.ToInt16(dateString.Substring(10, 2)),
- Convert.ToInt16(dateString.Substring(12, 2)),
- Convert.ToInt16(dateString.Substring(14, 3)));
+ date = new DateTime(Convert.ToInt16(dateString.Substring(0, 4), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(4, 2), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(6, 2), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(8, 2), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(10, 2), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(12, 2), CultureInfo.InvariantCulture),
+ Convert.ToInt16(dateString.Substring(14, 3), CultureInfo.InvariantCulture));
}
else
{
diff --git a/src/Lucene.Net/Index/BufferedUpdates.cs b/src/Lucene.Net/Index/BufferedUpdates.cs
index cdc5ff4..f99e67e 100644
--- a/src/Lucene.Net/Index/BufferedUpdates.cs
+++ b/src/Lucene.Net/Index/BufferedUpdates.cs
@@ -148,7 +148,7 @@ namespace Lucene.Net.Index
/// <summary>
/// NOTE: This was MAX_INT in Lucene
/// </summary>
- public static readonly int MAX_INT32 = Convert.ToInt32(int.MaxValue);
+ public static readonly int MAX_INT32 = int.MaxValue;
internal readonly AtomicInt64 bytesUsed;
@@ -216,7 +216,7 @@ namespace Lucene.Net.Index
public virtual void AddDocID(int docID)
{
- docIDs.Add(Convert.ToInt32(docID));
+ docIDs.Add(docID);
bytesUsed.AddAndGet(BYTES_PER_DEL_DOCID);
}
@@ -236,7 +236,7 @@ namespace Lucene.Net.Index
return;
}
- terms[term] = Convert.ToInt32(docIDUpto);
+ terms[term] = docIDUpto;
// note that if current != null then it means there's already a buffered
// delete on that term, therefore we seem to over-count. this over-counting
// is done to respect IndexWriterConfig.setMaxBufferedDeleteTerms.
diff --git a/src/Lucene.Net/Index/CheckIndex.cs b/src/Lucene.Net/Index/CheckIndex.cs
index a562df6..b635704 100644
--- a/src/Lucene.Net/Index/CheckIndex.cs
+++ b/src/Lucene.Net/Index/CheckIndex.cs
@@ -979,7 +979,7 @@ namespace Lucene.Net.Index
}
catch (Exception e)
{
- Msg(infoStream, "ERROR [" + Convert.ToString(e.Message) + "]");
+ Msg(infoStream, "ERROR [" + e.Message + "]");
status.Error = e;
if (infoStream != null)
{
@@ -1750,7 +1750,7 @@ namespace Lucene.Net.Index
}
catch (Exception e)
{
- Msg(infoStream, "ERROR [" + Convert.ToString(e.Message) + "]");
+ Msg(infoStream, "ERROR [" + e.Message + "]");
status.Error = e;
if (infoStream != null)
{
@@ -1799,7 +1799,7 @@ namespace Lucene.Net.Index
}
catch (Exception e)
{
- Msg(infoStream, "ERROR [" + Convert.ToString(e.Message) + "]");
+ Msg(infoStream, "ERROR [" + e.Message + "]");
status.Error = e;
if (infoStream != null)
{
@@ -2325,7 +2325,7 @@ namespace Lucene.Net.Index
}
catch (Exception e)
{
- Msg(infoStream, "ERROR [" + Convert.ToString(e.Message) + "]");
+ Msg(infoStream, "ERROR [" + e.Message + "]");
status.Error = e;
if (infoStream != null)
{
diff --git a/src/Lucene.Net/Index/DocumentsWriterFlushControl.cs b/src/Lucene.Net/Index/DocumentsWriterFlushControl.cs
index 6549039..002d56b 100644
--- a/src/Lucene.Net/Index/DocumentsWriterFlushControl.cs
+++ b/src/Lucene.Net/Index/DocumentsWriterFlushControl.cs
@@ -417,7 +417,7 @@ namespace Lucene.Net.Index
dwpt = perThreadPool.Reset(perThread, closed);
Debug.Assert(!flushingWriters.ContainsKey(dwpt), "DWPT is already flushing");
// Record the flushing DWPT to reduce flushBytes in doAfterFlush
- flushingWriters[dwpt] = Convert.ToInt64(bytes);
+ flushingWriters[dwpt] = bytes;
numPending--; // write access synced
return dwpt;
}
@@ -753,7 +753,7 @@ namespace Lucene.Net.Index
blockedFlushes.Remove(node);
Debug.Assert(!flushingWriters.ContainsKey(blockedFlush.Dwpt), "DWPT is already flushing");
// Record the flushing DWPT to reduce flushBytes in doAfterFlush
- flushingWriters[blockedFlush.Dwpt] = Convert.ToInt64(blockedFlush.Bytes);
+ flushingWriters[blockedFlush.Dwpt] = blockedFlush.Bytes;
// don't decr pending here - its already done when DWPT is blocked
flushQueue.Enqueue(blockedFlush.Dwpt);
}
@@ -835,7 +835,7 @@ namespace Lucene.Net.Index
{
try
{
- flushingWriters[blockedFlush.Dwpt] = Convert.ToInt64(blockedFlush.Bytes);
+ flushingWriters[blockedFlush.Dwpt] = blockedFlush.Bytes;
documentsWriter.SubtractFlushedNumDocs(blockedFlush.Dwpt.NumDocsInRAM);
blockedFlush.Dwpt.Abort(newFiles);
}
diff --git a/src/Lucene.Net/Index/FieldInfos.cs b/src/Lucene.Net/Index/FieldInfos.cs
index c267ae1..a73d93f 100644
--- a/src/Lucene.Net/Index/FieldInfos.cs
+++ b/src/Lucene.Net/Index/FieldInfos.cs
@@ -252,7 +252,7 @@ namespace Lucene.Net.Index
nameToNumber.TryGetValue(fieldName, out fieldNumber);
if (fieldNumber == null)
{
- int? preferredBoxed = Convert.ToInt32(preferredFieldNumber);
+ int? preferredBoxed = preferredFieldNumber;
if (preferredFieldNumber != -1 && !numberToName.ContainsKey(preferredBoxed))
{
@@ -396,7 +396,7 @@ namespace Lucene.Net.Index
int fieldNumber = globalFieldNumbers.AddOrGet(name, preferredFieldNumber, docValues);
fi = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector, omitNorms, storePayloads, indexOptions, docValues, normType, null);
Debug.Assert(!byName.ContainsKey(fi.Name));
- Debug.Assert(globalFieldNumbers.ContainsConsistent(Convert.ToInt32(fi.Number), fi.Name, fi.DocValuesType));
+ Debug.Assert(globalFieldNumbers.ContainsConsistent(fi.Number, fi.Name, fi.DocValuesType));
byName[fi.Name] = fi;
}
else
diff --git a/src/Lucene.Net/Index/IndexCommit.cs b/src/Lucene.Net/Index/IndexCommit.cs
index f1f9fa0..87f91a8 100644
--- a/src/Lucene.Net/Index/IndexCommit.cs
+++ b/src/Lucene.Net/Index/IndexCommit.cs
@@ -108,7 +108,7 @@ namespace Lucene.Net.Index
public override int GetHashCode()
{
- return Directory.GetHashCode() + Convert.ToInt64(Generation).GetHashCode();
+ return Directory.GetHashCode() + Generation.GetHashCode();
}
/// <summary>
diff --git a/src/Lucene.Net/Index/NumericDocValuesFieldUpdates.cs b/src/Lucene.Net/Index/NumericDocValuesFieldUpdates.cs
index add4a1c..935e23e 100644
--- a/src/Lucene.Net/Index/NumericDocValuesFieldUpdates.cs
+++ b/src/Lucene.Net/Index/NumericDocValuesFieldUpdates.cs
@@ -81,7 +81,7 @@ namespace Lucene.Net.Index
else
{
// idx points to the "next" element
- value = Convert.ToInt64(values.Get(idx - 1));
+ value = values.Get(idx - 1);
}
return doc;
}
diff --git a/src/Lucene.Net/Index/PersistentSnapshotDeletionPolicy.cs b/src/Lucene.Net/Index/PersistentSnapshotDeletionPolicy.cs
index 659e066..730df12 100644
--- a/src/Lucene.Net/Index/PersistentSnapshotDeletionPolicy.cs
+++ b/src/Lucene.Net/Index/PersistentSnapshotDeletionPolicy.cs
@@ -1,6 +1,7 @@
using Lucene.Net.Support;
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.IO;
using System.Runtime.CompilerServices;
@@ -312,7 +313,7 @@ namespace Lucene.Net.Index
{
if (file.StartsWith(SNAPSHOTS_PREFIX, StringComparison.Ordinal))
{
- long gen = Convert.ToInt64(file.Substring(SNAPSHOTS_PREFIX.Length));
+ long gen = Convert.ToInt64(file.Substring(SNAPSHOTS_PREFIX.Length), CultureInfo.InvariantCulture);
if (genLoaded == -1 || gen > genLoaded)
{
snapshotFiles.Add(file);
diff --git a/src/Lucene.Net/Index/StandardDirectoryReader.cs b/src/Lucene.Net/Index/StandardDirectoryReader.cs
index dc5c746..5e50470 100644
--- a/src/Lucene.Net/Index/StandardDirectoryReader.cs
+++ b/src/Lucene.Net/Index/StandardDirectoryReader.cs
@@ -181,7 +181,7 @@ namespace Lucene.Net.Index
for (int i = 0, c = oldReaders.Count; i < c; i++)
{
SegmentReader sr = (SegmentReader)oldReaders[i];
- segmentReaders[sr.SegmentName] = Convert.ToInt32(i);
+ segmentReaders[sr.SegmentName] = i;
}
}
diff --git a/src/Lucene.Net/Search/FieldComparator.cs b/src/Lucene.Net/Search/FieldComparator.cs
index d3ba96f..53b7f5f 100644
--- a/src/Lucene.Net/Search/FieldComparator.cs
+++ b/src/Lucene.Net/Search/FieldComparator.cs
@@ -987,7 +987,7 @@ namespace Lucene.Net.Search
public override IComparable this[int slot]
{
- get { return Convert.ToSingle(scores[slot]); }
+ get { return scores[slot]; }
}
// Override because we sort reverse of natural Float order:
@@ -1058,7 +1058,7 @@ namespace Lucene.Net.Search
public override IComparable this[int slot]
{
- get { return Convert.ToInt32(docIDs[slot]); }
+ get { return docIDs[slot]; }
}
public override int CompareTop(int doc)
diff --git a/src/Lucene.Net/Search/MultiPhraseQuery.cs b/src/Lucene.Net/Search/MultiPhraseQuery.cs
index 5e36a95..4a51c27 100644
--- a/src/Lucene.Net/Search/MultiPhraseQuery.cs
+++ b/src/Lucene.Net/Search/MultiPhraseQuery.cs
@@ -138,7 +138,7 @@ namespace Lucene.Net.Search
}
termArrays.Add(terms);
- positions.Add(Convert.ToInt32(position));
+ positions.Add(position);
}
/// <summary>
diff --git a/src/Lucene.Net/Search/NumericRangeQuery.cs b/src/Lucene.Net/Search/NumericRangeQuery.cs
index 9b9b283..98e6dab 100644
--- a/src/Lucene.Net/Search/NumericRangeQuery.cs
+++ b/src/Lucene.Net/Search/NumericRangeQuery.cs
@@ -2,6 +2,7 @@ using Lucene.Net.Documents;
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Globalization;
using System.Text;
namespace Lucene.Net.Search
@@ -339,12 +340,12 @@ namespace Lucene.Net.Search
long minBound;
if (this.outerInstance.dataType == NumericType.INT64)
{
- minBound = (this.outerInstance.min == null) ? long.MinValue : Convert.ToInt64(this.outerInstance.min.Value);
+ minBound = (this.outerInstance.min == null) ? long.MinValue : Convert.ToInt64(this.outerInstance.min.Value, CultureInfo.InvariantCulture);
}
else
{
Debug.Assert(this.outerInstance.dataType == NumericType.DOUBLE);
- minBound = (this.outerInstance.min == null) ? INT64_NEGATIVE_INFINITY : NumericUtils.DoubleToSortableInt64(Convert.ToDouble(this.outerInstance.min.Value));
+ minBound = (this.outerInstance.min == null) ? INT64_NEGATIVE_INFINITY : NumericUtils.DoubleToSortableInt64(Convert.ToDouble(this.outerInstance.min.Value, CultureInfo.InvariantCulture));
}
if (!this.outerInstance.minInclusive && this.outerInstance.min != null)
{
@@ -359,12 +360,12 @@ namespace Lucene.Net.Search
long maxBound;
if (this.outerInstance.dataType == NumericType.INT64)
{
- maxBound = (this.outerInstance.max == null) ? long.MaxValue : Convert.ToInt64(this.outerInstance.max);
+ maxBound = (this.outerInstance.max == null) ? long.MaxValue : Convert.ToInt64(this.outerInstance.max, CultureInfo.InvariantCulture);
}
else
{
Debug.Assert(this.outerInstance.dataType == NumericType.DOUBLE);
- maxBound = (this.outerInstance.max == null) ? INT64_POSITIVE_INFINITY : NumericUtils.DoubleToSortableInt64(Convert.ToDouble(this.outerInstance.max));
+ maxBound = (this.outerInstance.max == null) ? INT64_POSITIVE_INFINITY : NumericUtils.DoubleToSortableInt64(Convert.ToDouble(this.outerInstance.max, CultureInfo.InvariantCulture));
}
if (!this.outerInstance.maxInclusive && this.outerInstance.max != null)
{
@@ -386,12 +387,12 @@ namespace Lucene.Net.Search
int minBound;
if (this.outerInstance.dataType == NumericType.INT32)
{
- minBound = (this.outerInstance.min == null) ? int.MinValue : Convert.ToInt32(this.outerInstance.min);
+ minBound = (this.outerInstance.min == null) ? int.MinValue : Convert.ToInt32(this.outerInstance.min, CultureInfo.InvariantCulture);
}
else
{
Debug.Assert(this.outerInstance.dataType == NumericType.SINGLE);
- minBound = (this.outerInstance.min == null) ? INT32_NEGATIVE_INFINITY : NumericUtils.SingleToSortableInt32(Convert.ToSingle(this.outerInstance.min));
+ minBound = (this.outerInstance.min == null) ? INT32_NEGATIVE_INFINITY : NumericUtils.SingleToSortableInt32(Convert.ToSingle(this.outerInstance.min, CultureInfo.InvariantCulture));
}
if (!this.outerInstance.minInclusive && this.outerInstance.min != null)
{
@@ -406,12 +407,12 @@ namespace Lucene.Net.Search
int maxBound;
if (this.outerInstance.dataType == NumericType.INT32)
{
- maxBound = (this.outerInstance.max == null) ? int.MaxValue : Convert.ToInt32(this.outerInstance.max);
+ maxBound = (this.outerInstance.max == null) ? int.MaxValue : Convert.ToInt32(this.outerInstance.max, CultureInfo.InvariantCulture);
}
else
{
Debug.Assert(this.outerInstance.dataType == NumericType.SINGLE);
- maxBound = (this.outerInstance.max == null) ? INT32_POSITIVE_INFINITY : NumericUtils.SingleToSortableInt32(Convert.ToSingle(this.outerInstance.max));
+ maxBound = (this.outerInstance.max == null) ? INT32_POSITIVE_INFINITY : NumericUtils.SingleToSortableInt32(Convert.ToSingle(this.outerInstance.max, CultureInfo.InvariantCulture));
}
if (!this.outerInstance.maxInclusive && this.outerInstance.max != null)
{
diff --git a/src/Lucene.Net/Search/PhraseQuery.cs b/src/Lucene.Net/Search/PhraseQuery.cs
index b56a886..db1f5f9 100644
--- a/src/Lucene.Net/Search/PhraseQuery.cs
+++ b/src/Lucene.Net/Search/PhraseQuery.cs
@@ -142,7 +142,7 @@ namespace Lucene.Net.Search
}
terms.Add(term);
- positions.Add(Convert.ToInt32(position));
+ positions.Add(position);
if (position > maxPosition)
{
maxPosition = position;
diff --git a/src/Lucene.Net/Store/FSDirectory.cs b/src/Lucene.Net/Store/FSDirectory.cs
index 6cc3caf..189b23e 100644
--- a/src/Lucene.Net/Store/FSDirectory.cs
+++ b/src/Lucene.Net/Store/FSDirectory.cs
@@ -2,6 +2,7 @@ using Lucene.Net.Support.IO;
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Globalization;
using System.IO;
using System.Linq;// Used only for WRITE_LOCK_NAME in deprecated create=true case:
@@ -408,7 +409,7 @@ namespace Lucene.Net.Store
char ch = dirName[charIDX];
digest = 31*digest + ch;
}
- return "lucene-" + digest.ToString("x");
+ return "lucene-" + digest.ToString("x", CultureInfo.InvariantCulture);
}
/// <summary>
diff --git a/src/Lucene.Net/Store/LockStressTest.cs b/src/Lucene.Net/Store/LockStressTest.cs
index c651587..1eab4c7 100644
--- a/src/Lucene.Net/Store/LockStressTest.cs
+++ b/src/Lucene.Net/Store/LockStressTest.cs
@@ -1,4 +1,5 @@
using System;
+using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
@@ -60,7 +61,7 @@ namespace Lucene.Net.Store
}
int arg = 0;
- int myID = Convert.ToInt32(args[arg++]);
+ int myID = Convert.ToInt32(args[arg++], CultureInfo.InvariantCulture);
if (myID < 0 || myID > 255)
{
@@ -70,11 +71,11 @@ namespace Lucene.Net.Store
}
string verifierHost = args[arg++];
- int verifierPort = Convert.ToInt32(args[arg++]);
+ int verifierPort = Convert.ToInt32(args[arg++], CultureInfo.InvariantCulture);
string lockFactoryClassName = args[arg++];
string lockDirName = args[arg++];
- int sleepTimeMS = Convert.ToInt32(args[arg++]);
- int count = Convert.ToInt32(args[arg++]);
+ int sleepTimeMS = Convert.ToInt32(args[arg++], CultureInfo.InvariantCulture);
+ int count = Convert.ToInt32(args[arg++], CultureInfo.InvariantCulture);
IPAddress[] addresses = Dns.GetHostAddressesAsync(verifierHost).Result;
IPAddress addr = addresses.FirstOrDefault();
diff --git a/src/Lucene.Net/Store/LockVerifyServer.cs b/src/Lucene.Net/Store/LockVerifyServer.cs
index 6963fd2..bf2dc83 100644
--- a/src/Lucene.Net/Store/LockVerifyServer.cs
+++ b/src/Lucene.Net/Store/LockVerifyServer.cs
@@ -66,7 +66,7 @@ namespace Lucene.Net.Store
Console.WriteLine("Listening on " + ((IPEndPoint)s.LocalEndPoint).Port.ToString() + "...");
// we set the port as a sysprop, so the ANT task can read it. For that to work, this server must run in-process:
- SystemProperties.SetProperty("lockverifyserver.port", ((IPEndPoint)s.LocalEndPoint).Port.ToString());
+ SystemProperties.SetProperty("lockverifyserver.port", ((IPEndPoint)s.LocalEndPoint).Port.ToString(CultureInfo.InvariantCulture));
object localLock = new object();
int[] lockedID = new int[1];
diff --git a/src/Lucene.Net/Store/RAMDirectory.cs b/src/Lucene.Net/Store/RAMDirectory.cs
index 6f67f68..91a6771 100644
--- a/src/Lucene.Net/Store/RAMDirectory.cs
+++ b/src/Lucene.Net/Store/RAMDirectory.cs
@@ -3,6 +3,7 @@ using Lucene.Net.Support.Compatibility;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
+using System.Globalization;
using System.IO;
using System.Linq;
@@ -113,7 +114,7 @@ namespace Lucene.Net.Store
public override string GetLockID()
{
- return "lucene-" + GetHashCode().ToString("x");
+ return "lucene-" + GetHashCode().ToString("x", CultureInfo.InvariantCulture);
}
public override sealed string[] ListAll()
diff --git a/src/Lucene.Net/Support/AssemblyUtils.cs b/src/Lucene.Net/Support/AssemblyUtils.cs
index 7805eca..977d9d6 100644
--- a/src/Lucene.Net/Support/AssemblyUtils.cs
+++ b/src/Lucene.Net/Support/AssemblyUtils.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using System.Reflection;
#if NETSTANDARD1_6
@@ -148,7 +149,7 @@ namespace Lucene.Net.Support
return false;
}
- var publicKeyToken = string.Concat(publicKey.Select(i => i.ToString("x2")));
+ var publicKeyToken = string.Concat(publicKey.Select(i => i.ToString("x2", CultureInfo.InvariantCulture)));
return s_microsoftKeys.Contains(publicKeyToken);
}
diff --git a/src/Lucene.Net/Support/AtomicInteger.cs b/src/Lucene.Net/Support/AtomicInteger.cs
index b3b2cca..8af0088 100644
--- a/src/Lucene.Net/Support/AtomicInteger.cs
+++ b/src/Lucene.Net/Support/AtomicInteger.cs
@@ -86,5 +86,20 @@ namespace Lucene.Net.Support
{
return Get().ToString();
}
+
+ public virtual string ToString(string format)
+ {
+ return Get().ToString(format);
+ }
+
+ public virtual string ToString(IFormatProvider provider)
+ {
+ return Get().ToString(provider);
+ }
+
+ public virtual string ToString(string format, IFormatProvider provider)
+ {
+ return Get().ToString(format, provider);
+ }
}
}
\ No newline at end of file
diff --git a/src/Lucene.Net/Support/AtomicLong.cs b/src/Lucene.Net/Support/AtomicLong.cs
index b74edda..43ec973 100644
--- a/src/Lucene.Net/Support/AtomicLong.cs
+++ b/src/Lucene.Net/Support/AtomicLong.cs
@@ -81,5 +81,20 @@ namespace Lucene.Net.Support
{
return Get().ToString();
}
+
+ public virtual string ToString(string format)
+ {
+ return Get().ToString(format);
+ }
+
+ public virtual string ToString(IFormatProvider provider)
+ {
+ return Get().ToString(provider);
+ }
+
+ public virtual string ToString(string format, IFormatProvider provider)
+ {
+ return Get().ToString(format, provider);
+ }
}
}
\ No newline at end of file
diff --git a/src/Lucene.Net/Support/Character.cs b/src/Lucene.Net/Support/Character.cs
index 0065f01..dae61af 100644
--- a/src/Lucene.Net/Support/Character.cs
+++ b/src/Lucene.Net/Support/Character.cs
@@ -21,6 +21,7 @@
using System;
using System.Globalization;
+using System.Text;
using Lucene.Net.Util;
namespace Lucene.Net.Support
@@ -314,6 +315,23 @@ namespace Lucene.Net.Support
- MIN_LOW_SURROGATE);
}
+ public static int CodePointAt(StringBuilder seq, int index)
+ {
+ char c1 = seq[index++];
+ if (char.IsHighSurrogate(c1))
+ {
+ if (index < seq.Length)
+ {
+ char c2 = seq[index];
+ if (char.IsLowSurrogate(c2))
+ {
+ return ToCodePoint(c1, c2);
+ }
+ }
+ }
+ return c1;
+ }
+
public static int CodePointAt(ICharSequence seq, int index)
{
char c1 = seq[index++];
diff --git a/src/Lucene.Net/Support/StringBuilderExtensions.cs b/src/Lucene.Net/Support/StringBuilderExtensions.cs
index d6d543b..de20820 100644
--- a/src/Lucene.Net/Support/StringBuilderExtensions.cs
+++ b/src/Lucene.Net/Support/StringBuilderExtensions.cs
@@ -129,7 +129,7 @@ namespace Lucene.Net.Support
{
throw new IndexOutOfRangeException();
}
- return Character.CodePointAt(text.ToString(), index);
+ return Character.CodePointAt(text, index);
}
/// <summary>
diff --git a/src/Lucene.Net/Util/Automaton/BasicAutomata.cs b/src/Lucene.Net/Util/Automaton/BasicAutomata.cs
index fcebb46..0bb2d66 100644
--- a/src/Lucene.Net/Util/Automaton/BasicAutomata.cs
+++ b/src/Lucene.Net/Util/Automaton/BasicAutomata.cs
@@ -1,6 +1,7 @@
using Lucene.Net.Support;
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Text;
/*
@@ -246,8 +247,8 @@ namespace Lucene.Net.Util.Automaton
public static Automaton MakeInterval(int min, int max, int digits)
{
Automaton a = new Automaton();
- string x = Convert.ToString(min);
- string y = Convert.ToString(max);
+ string x = Convert.ToString(min, CultureInfo.InvariantCulture);
+ string y = Convert.ToString(max, CultureInfo.InvariantCulture);
if (min > max || (digits > 0 && y.Length > digits))
{
throw new System.ArgumentException();
diff --git a/src/Lucene.Net/Util/Automaton/RegExp.cs b/src/Lucene.Net/Util/Automaton/RegExp.cs
index a6b5242..4e5ff14 100644
--- a/src/Lucene.Net/Util/Automaton/RegExp.cs
+++ b/src/Lucene.Net/Util/Automaton/RegExp.cs
@@ -1,6 +1,7 @@
using Lucene.Net.Support;
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Text;
/*
@@ -731,8 +732,8 @@ namespace Lucene.Net.Util.Automaton
break;
case Kind.REGEXP_INTERVAL:
- string s1 = Convert.ToString(min);
- string s2 = Convert.ToString(max);
+ string s1 = Convert.ToString(min, CultureInfo.InvariantCulture);
+ string s2 = Convert.ToString(max, CultureInfo.InvariantCulture);
b.Append("<");
if (digits > 0)
{
@@ -1068,7 +1069,7 @@ namespace Lucene.Net.Util.Automaton
{
throw new System.ArgumentException("integer expected at position " + pos);
}
- int n = Convert.ToInt32(b.Substring(start, pos - start));
+ int n = Convert.ToInt32(b.Substring(start, pos - start), CultureInfo.InvariantCulture);
int m = -1;
if (Match(','))
{
@@ -1079,7 +1080,7 @@ namespace Lucene.Net.Util.Automaton
}
if (start != pos)
{
- m = Convert.ToInt32(b.Substring(start, pos - start));
+ m = Convert.ToInt32(b.Substring(start, pos - start), CultureInfo.InvariantCulture);
}
}
else
@@ -1239,8 +1240,8 @@ namespace Lucene.Net.Util.Automaton
}
string smin = s.Substring(0, i);
string smax = s.Substring(i + 1, s.Length - (i + 1));
- int imin = Convert.ToInt32(smin);
- int imax = Convert.ToInt32(smax);
+ int imin = Convert.ToInt32(smin, CultureInfo.InvariantCulture);
+ int imax = Convert.ToInt32(smax, CultureInfo.InvariantCulture);
int digits;
if (smin.Length == smax.Length)
{
diff --git a/src/Lucene.Net/Util/Automaton/Transition.cs b/src/Lucene.Net/Util/Automaton/Transition.cs
index 50bae03..8076d81 100644
--- a/src/Lucene.Net/Util/Automaton/Transition.cs
+++ b/src/Lucene.Net/Util/Automaton/Transition.cs
@@ -2,6 +2,7 @@ using Lucene.Net.Support;
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Globalization;
using System.Text;
/*
@@ -166,7 +167,7 @@ namespace Lucene.Net.Util.Automaton
else
{
b.Append("\\\\U");
- string s = c.ToString("x");
+ string s = c.ToString("x", CultureInfo.InvariantCulture);
if (c < 0x10)
{
b.Append("0000000").Append(s);
diff --git a/src/Lucene.Net/Util/Fst/PositiveIntOutputs.cs b/src/Lucene.Net/Util/Fst/PositiveIntOutputs.cs
index bf343ed..e2d18d2 100644
--- a/src/Lucene.Net/Util/Fst/PositiveIntOutputs.cs
+++ b/src/Lucene.Net/Util/Fst/PositiveIntOutputs.cs
@@ -139,7 +139,7 @@ namespace Lucene.Net.Util.Fst
public override string OutputToString(long? output)
{
- return output.ToString();
+ return output.ToString(); // LUCENENET TODO: Invariant Culture?
}
public override string ToString()
diff --git a/src/Lucene.Net/Util/Fst/Util.cs b/src/Lucene.Net/Util/Fst/Util.cs
index b206948..201ee3e 100644
--- a/src/Lucene.Net/Util/Fst/Util.cs
+++ b/src/Lucene.Net/Util/Fst/Util.cs
@@ -3,6 +3,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Globalization;
using System.IO;
namespace Lucene.Net.Util.Fst
@@ -975,7 +976,7 @@ namespace Lucene.Net.Util.Fst
{
return char.ToString((char)label);
}
- return "0x" + label.ToString("x");
+ return "0x" + label.ToString("x", CultureInfo.InvariantCulture);
}
/// <summary>
diff --git a/src/Lucene.Net/Util/RamUsageEstimator.cs b/src/Lucene.Net/Util/RamUsageEstimator.cs
index b4a37a8..9e552d8 100644
--- a/src/Lucene.Net/Util/RamUsageEstimator.cs
+++ b/src/Lucene.Net/Util/RamUsageEstimator.cs
@@ -220,7 +220,7 @@ namespace Lucene.Net.Util
//{
// Method getVMOptionMethod = beanClazz.GetMethod("getVMOption", typeof(string));
// object vmOption = getVMOptionMethod.invoke(hotSpotBean, "ObjectAlignmentInBytes");
- // objectAlignment = Convert.ToInt32(vmOption.GetType().GetMethod("getValue").invoke(vmOption).ToString());
+ // objectAlignment = Convert.ToInt32(vmOption.GetType().GetMethod("getValue").invoke(vmOption).ToString(), CultureInfo.InvariantCulture);
//}
//}
//catch (Exception e)