11using J2N . Text ;
2- using Lucene . Net . Support ;
32using Lucene . Net . Support . Buffers ;
4- using Lucene . Net . Support . Text ;
3+ using Lucene . Net . Util ;
54using System ;
65using System . Buffers ;
7- using System . Text ;
86
97namespace Lucene . Net . Index
108{
@@ -25,8 +23,6 @@ namespace Lucene.Net.Index
2523 * limitations under the License.
2624 */
2725
28- using BytesRef = Lucene . Net . Util . BytesRef ;
29-
3026 /// <summary>
3127 /// A <see cref="Term"/> represents a word from text. This is the unit of search. It is
3228 /// composed of two elements, the text of the word, as a string, and the name of
@@ -37,9 +33,7 @@ namespace Lucene.Net.Index
3733 /// </summary>
3834 public sealed class Term : IComparable < Term > , IEquatable < Term > // LUCENENET specific - class implements IEquatable<T>
3935 {
40- #if FEATURE_UTF8_TOUTF16
4136 private const int CharStackBufferSize = 64 ;
42- #endif
4337
4438 /// <summary>
4539 /// Constructs a <see cref="Term"/> with the given field and bytes.
@@ -100,9 +94,11 @@ public static string ToString(BytesRef termText)
10094 {
10195 if ( termText is null )
10296 throw new ArgumentNullException ( nameof ( termText ) ) ; // LUCENENET: Added guard clause
103- #if FEATURE_UTF8_TOUTF16
97+
98+ // the term might not be text, but usually is. so we make a best effort
99+
104100 // View the relevant portion of the byte array
105- ReadOnlySpan < byte > utf8Span = new ReadOnlySpan < byte > ( termText . Bytes , termText . Offset , termText . Length ) ;
101+ ReadOnlySpan < byte > utf8Span = termText . AsSpan ( ) ;
106102
107103 // Allocate a buffer for the maximum possible UTF-16 output
108104 int maxChars = utf8Span . Length ; // Worst case: 1 byte -> 1 char (ASCII)
@@ -136,18 +132,6 @@ public static string ToString(BytesRef termText)
136132
137133 // Fallback to the default string representation if decoding fails
138134 return termText . ToString ( ) ;
139- #else
140- // the term might not be text, but usually is. so we make a best effort
141- Encoding decoder = StandardCharsets . UTF_8 . WithDecoderExceptionFallback ( ) ;
142- try
143- {
144- return decoder . GetString ( termText . Bytes , termText . Offset , termText . Length ) ;
145- }
146- catch ( DecoderFallbackException )
147- {
148- return termText . ToString ( ) ;
149- }
150- #endif
151135 }
152136#nullable restore
153137
0 commit comments