File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- namespace UnicodeHelper
1+ using System . Diagnostics . CodeAnalysis ;
2+
3+ namespace UnicodeHelper
24{
35 [ TestClass ]
46 public class DotNetStringExtensionsTests
@@ -17,6 +19,19 @@ public void Codepoints(string dotNetString)
1719 {
1820 Assert . That . SequenceEqual ( new UString ( dotNetString ) , dotNetString . Codepoints ( ) ) ;
1921 }
22+
23+ [ TestMethod ]
24+ [ DynamicData ( nameof ( CodepointsTestData ) ) ]
25+ [ SuppressMessage ( "ReSharper" , "PossibleMultipleEnumeration" ) ]
26+ public void Codepoints_MultipleIterations ( string dotNetString )
27+ {
28+ UString expectedResult = new ( dotNetString ) ;
29+ IEnumerable < UCodepoint > codepoints = dotNetString . Codepoints ( ) ;
30+
31+ Assert . That . SequenceEqual ( expectedResult , codepoints ) ;
32+ Assert . That . SequenceEqual ( expectedResult , codepoints ) ;
33+ Assert . That . SequenceEqual ( expectedResult , codepoints ) ;
34+ }
2035 #endregion
2136 }
2237}
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ public static IEnumerable<UCodepoint> Codepoints(this string dotNetString)
2222 #region DotNetStringEnumerator class
2323 private sealed class DotNetStringEnumerator : IEnumerator < UCodepoint > , IEnumerable < UCodepoint >
2424 {
25- private string _dotNetString ;
25+ private readonly string _dotNetString ;
2626 private int _index = - 1 ;
2727 private UCodepoint _current ;
2828
@@ -33,9 +33,7 @@ public DotNetStringEnumerator(string dotNetString)
3333
3434 public void Dispose ( )
3535 {
36- if ( _dotNetString != null )
37- _index = _dotNetString . Length ;
38- _dotNetString = null ;
36+ _index = _dotNetString . Length ;
3937 }
4038
4139 public UCodepoint Current
@@ -54,10 +52,7 @@ public UCodepoint Current
5452
5553 public bool MoveNext ( )
5654 {
57- _index ++ ;
58- if ( _current > 0xFFFF )
59- _index ++ ;
60-
55+ _index += ( _current <= 0xFFFF ) ? 1 : 2 ;
6156 if ( _index >= _dotNetString . Length )
6257 return false ;
6358
@@ -73,6 +68,7 @@ public void Reset()
7368
7469 public IEnumerator < UCodepoint > GetEnumerator ( )
7570 {
71+ Reset ( ) ;
7672 return this ;
7773 }
7874
Original file line number Diff line number Diff line change 77 <RunAnalyzersDuringLiveAnalysis >False</RunAnalyzersDuringLiveAnalysis >
88 <GeneratePackageOnBuild >True</GeneratePackageOnBuild >
99 <Title >Unicode Helper</Title >
10- <Version >0.6.1 </Version >
10+ <Version >0.6.2 </Version >
1111 <Authors >FoolRunning</Authors >
1212 <Description >.Net library to get information about Unicode codepoints and to better handle the upper planes (1-16) of Unicode.</Description >
1313 <Copyright >© 2024 Tim Steenwyk</Copyright >
You can’t perform that action at this time.
0 commit comments