apache / lucenenet

Apache Lucene.NET
https://lucenenet.apache.org/
Apache License 2.0
2.24k stars 639 forks source link

Convert UTF8toUTF16 to TryUTF8toUTF16 #1024

Open paulirwin opened 1 week ago

paulirwin commented 1 week ago

I also noticed when searching for IndexOutOfRangeException that UTF8toUTF16 can throw it, also. This is unusual to have to deal with, so we should change this method to TryUTF8toUTF16 so we can eliminate this exception that is clearly exclusively meant for control flow when the UTF8 format is invalid. It is caught in several places to do a fallback, and we should fix this. Note that we will most likely be converting the byte[] overload to use ReadOnlySpan<byte> and getting rid of the offset and length parameters.

_Originally posted by @NightOwl888 in https://github.com/apache/lucenenet/pull/1018#discussion_r1842253910_