Skip to content

Commit a367eb9

Browse files
committed
Directory.Build.targets: Removed FEATURE_UTF8_TOUTF16 since it is now supported on all target frameworks
1 parent 49e778b commit a367eb9

2 files changed

Lines changed: 5 additions & 22 deletions

File tree

Directory.Build.targets

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
<PropertyGroup Condition=" $(TargetFramework.StartsWith('net8.')) Or $(TargetFramework.StartsWith('net9.')) ">
4848

4949
<DefineConstants>$(DefineConstants);FEATURE_ASPNETCORE_TESTHOST</DefineConstants>
50-
<DefineConstants>$(DefineConstants);FEATURE_UTF8_TOUTF16</DefineConstants>
5150

5251
</PropertyGroup>
5352

src/Lucene.Net/Index/Term.cs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using J2N.Text;
2-
using Lucene.Net.Support;
32
using Lucene.Net.Support.Buffers;
4-
using Lucene.Net.Support.Text;
3+
using Lucene.Net.Util;
54
using System;
65
using System.Buffers;
7-
using System.Text;
86

97
namespace 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

Comments
 (0)