1-
1+
22using System . Buffers ;
33using System . Runtime . CompilerServices ;
44using System . Runtime . InteropServices ;
@@ -12,7 +12,7 @@ public static SplitEnumerator Split(ReadOnlySpan<byte> source, byte separator, U
1212 const Utf8StringSplitOptions AllOptions = Utf8StringSplitOptions . TrimEntries | Utf8StringSplitOptions . RemoveEmptyEntries ;
1313 if ( ( splitOptions & ~ AllOptions ) != 0 )
1414 {
15- throw new ArgumentException ( " Utf8StringSplitOptions Value is Invalid .") ;
15+ ArgumentExceptionEx . Throw ( "The specified ' Utf8StringSplitOptions' value is not valid .") ;
1616 }
1717
1818 return new SplitEnumerator ( source , separator , splitOptions ) ;
@@ -23,7 +23,7 @@ public static SplitEnumerator Split(ReadOnlySpan<byte> source, ReadOnlySpan<byte
2323 const Utf8StringSplitOptions AllOptions = Utf8StringSplitOptions . TrimEntries | Utf8StringSplitOptions . RemoveEmptyEntries ;
2424 if ( ( splitOptions & ~ AllOptions ) != 0 )
2525 {
26- throw new ArgumentException ( " Utf8StringSplitOptions Value is Invalid .") ;
26+ ArgumentExceptionEx . Throw ( "The specified ' Utf8StringSplitOptions' value is not valid .") ;
2727 }
2828
2929 return new SplitEnumerator ( source , separator , splitOptions ) ;
@@ -34,7 +34,7 @@ public static SplitAnyEnumerator SplitAny(ReadOnlySpan<byte> source, ReadOnlySpa
3434 const Utf8StringSplitOptions AllOptions = Utf8StringSplitOptions . TrimEntries | Utf8StringSplitOptions . RemoveEmptyEntries ;
3535 if ( ( splitOptions & ~ AllOptions ) != 0 )
3636 {
37- throw new ArgumentException ( " Utf8StringSplitOptions Value is Invalid .") ;
37+ ArgumentExceptionEx . Throw ( "The specified ' Utf8StringSplitOptions' value is not valid .") ;
3838 }
3939
4040 switch ( separatorOptions )
@@ -43,7 +43,8 @@ public static SplitAnyEnumerator SplitAny(ReadOnlySpan<byte> source, ReadOnlySpa
4343 case Utf8StringSeparatorOptions . Bytes :
4444 return new SplitAnyEnumerator ( source , separators , splitOptions , separatorOptions ) ;
4545 default :
46- throw new ArgumentException ( "Utf8StringSeparatorOptions Value is Invalid." ) ;
46+ ArgumentExceptionEx . Throw ( "The specified 'Utf8StringSeparatorOptions' value is not valid." ) ;
47+ return default ; // It will not reach here.
4748 }
4849 }
4950}
@@ -105,7 +106,7 @@ internal SplitEnumerator(ReadOnlySpan<byte> source, ReadOnlySpan<byte> separator
105106
106107 public readonly SplitEnumerator GetEnumerator ( ) => this ;
107108
108- internal readonly int sourceLength => source . Length ;
109+ internal readonly int SourceLength => source . Length ;
109110
110111 public bool MoveNext ( )
111112 {
@@ -122,7 +123,7 @@ public bool MoveNext()
122123
123124 public readonly byte [ ] [ ] ToArray ( )
124125 {
125- var writer = new ExtendableArray < byte [ ] > ( sourceLength ) ;
126+ var writer = new ExtendableArray < byte [ ] > ( SourceLength ) ;
126127 foreach ( var i in this )
127128 {
128129 writer . Add ( i . ToArray ( ) ) ;
@@ -133,7 +134,7 @@ public readonly byte[][] ToArray()
133134
134135 public readonly string [ ] ToUtf16Array ( )
135136 {
136- var writer = new ExtendableArray < string > ( sourceLength ) ;
137+ var writer = new ExtendableArray < string > ( SourceLength ) ;
137138 foreach ( var i in this )
138139 {
139140 writer . Add ( UTF8Ex . GetString ( i ) ) ;
@@ -207,8 +208,6 @@ private bool MoveNextInternalWithOptions(scoped ReadOnlySpan<byte> separator)
207208 var index = source . IndexOf ( separator ) ;
208209 if ( index < 0 || separator . Length == 0 ) // end
209210 {
210- ( startIndex , endIndex ) = Utf8StringUtility . TrimSplitEntries ( source , startIndex , endIndex ) ;
211-
212211 if ( trimEntries )
213212 {
214213 if ( source . Length == 1 && source [ 0 ] == 0x20 )
@@ -217,6 +216,7 @@ private bool MoveNextInternalWithOptions(scoped ReadOnlySpan<byte> separator)
217216 }
218217 else
219218 {
219+ ( startIndex , endIndex ) = Utf8StringUtility . TrimSplitEntries ( source , startIndex , endIndex ) ;
220220 source = source [ startIndex ..endIndex ] ;
221221 }
222222 }
@@ -235,13 +235,13 @@ private bool MoveNextInternalWithOptions(scoped ReadOnlySpan<byte> separator)
235235 source = source [ index ..] ;
236236 if ( trimEntries )
237237 {
238- ( startIndex , endIndex ) = Utf8StringUtility . TrimSplitEntries ( current , 0 , current . Length ) ;
239238 if ( current . Length == 1 && current [ 0 ] == 0x20 )
240239 {
241240 current = ReadOnlySpan < byte > . Empty ;
242241 }
243242 else
244243 {
244+ ( startIndex , endIndex ) = Utf8StringUtility . TrimSplitEntries ( current , 0 , current . Length ) ;
245245 current = current [ startIndex ..endIndex ] ;
246246 }
247247 }
@@ -255,8 +255,6 @@ private bool MoveNextInternalWithOptions(scoped ReadOnlySpan<byte> separator)
255255 index = source . IndexOf ( separator ) ;
256256 if ( index < 0 ) // end
257257 {
258- ( startIndex , endIndex ) = Utf8StringUtility . TrimSplitEntries ( source , 0 , source . Length ) ;
259-
260258 if ( trimEntries )
261259 {
262260 if ( source . Length == 1 && source [ 0 ] == 0x20 )
@@ -265,6 +263,7 @@ private bool MoveNextInternalWithOptions(scoped ReadOnlySpan<byte> separator)
265263 }
266264 else
267265 {
266+ ( startIndex , endIndex ) = Utf8StringUtility . TrimSplitEntries ( source , 0 , source . Length ) ;
268267 source = source [ startIndex ..endIndex ] ;
269268 }
270269 }
@@ -283,13 +282,13 @@ private bool MoveNextInternalWithOptions(scoped ReadOnlySpan<byte> separator)
283282 source = source [ index ..] ;
284283 if ( trimEntries )
285284 {
286- ( startIndex , endIndex ) = Utf8StringUtility . TrimSplitEntries ( current , 0 , current . Length ) ;
287285 if ( current . Length == 1 && current [ 0 ] == 0x20 )
288286 {
289287 current = ReadOnlySpan < byte > . Empty ;
290288 }
291289 else
292290 {
291+ ( startIndex , endIndex ) = Utf8StringUtility . TrimSplitEntries ( current , 0 , current . Length ) ;
293292 current = current [ startIndex ..endIndex ] ;
294293 }
295294 }
@@ -437,8 +436,6 @@ private bool MoveNextWithOptions()
437436 }
438437 if ( index < 0 ) // end
439438 {
440- ( startIndex , endIndex ) = Utf8StringUtility . TrimSplitEntries ( target , startIndex , endIndex ) ;
441-
442439 if ( trimEntries )
443440 {
444441 if ( target . Length == 1 && target [ 0 ] == 0x20 )
@@ -447,6 +444,7 @@ private bool MoveNextWithOptions()
447444 }
448445 else
449446 {
447+ ( startIndex , endIndex ) = Utf8StringUtility . TrimSplitEntries ( target , startIndex , endIndex ) ;
450448 target = target [ startIndex ..endIndex ] ;
451449 }
452450 }
@@ -465,13 +463,13 @@ private bool MoveNextWithOptions()
465463 target = target [ index ..] ;
466464 if ( trimEntries )
467465 {
468- ( startIndex , endIndex ) = Utf8StringUtility . TrimSplitEntries ( current , 0 , current . Length ) ;
469466 if ( current . Length == 1 && current [ 0 ] == 0x20 )
470467 {
471468 current = ReadOnlySpan < byte > . Empty ;
472469 }
473470 else
474471 {
472+ ( startIndex , endIndex ) = Utf8StringUtility . TrimSplitEntries ( current , 0 , current . Length ) ;
475473 current = current [ startIndex ..endIndex ] ;
476474 }
477475 }
@@ -495,8 +493,6 @@ private bool MoveNextWithOptions()
495493 }
496494 if ( index < 0 ) // end
497495 {
498- ( startIndex , endIndex ) = Utf8StringUtility . TrimSplitEntries ( target , 0 , target . Length ) ;
499-
500496 if ( trimEntries )
501497 {
502498 if ( target . Length == 1 && target [ 0 ] == 0x20 )
@@ -505,6 +501,7 @@ private bool MoveNextWithOptions()
505501 }
506502 else
507503 {
504+ ( startIndex , endIndex ) = Utf8StringUtility . TrimSplitEntries ( target , 0 , target . Length ) ;
508505 target = target [ startIndex ..endIndex ] ;
509506 }
510507 }
@@ -523,13 +520,13 @@ private bool MoveNextWithOptions()
523520 target = target [ index ..] ;
524521 if ( trimEntries )
525522 {
526- ( startIndex , endIndex ) = Utf8StringUtility . TrimSplitEntries ( current , 0 , current . Length ) ;
527523 if ( current . Length == 1 && current [ 0 ] == 0x20 )
528524 {
529525 current = ReadOnlySpan < byte > . Empty ;
530526 }
531527 else
532528 {
529+ ( startIndex , endIndex ) = Utf8StringUtility . TrimSplitEntries ( current , 0 , current . Length ) ;
533530 current = current [ startIndex ..endIndex ] ;
534531 }
535532 }
0 commit comments