@@ -49,15 +49,15 @@ public class JaroWinkler : INormalizedStringSimilarity, INormalizedStringDistanc
4949 /// The current value of the threshold used for adding the Winkler bonus. The default value is 0.7.
5050 /// </summary>
5151 private double Threshold { get ; }
52-
52+
5353 /// <summary>
5454 /// Creates a new instance with default threshold (0.7)
5555 /// </summary>
5656 public JaroWinkler ( )
5757 {
5858 Threshold = DEFAULT_THRESHOLD ;
5959 }
60-
60+
6161 /// <summary>
6262 /// Creates a new instance with given threshold to determine when Winkler bonus should
6363 /// be used. Set threshold to a negative value to get the Jaro distance.
@@ -77,10 +77,20 @@ public JaroWinkler(double threshold)
7777 /// <exception cref="ArgumentNullException">If s1 or s2 is null.</exception>
7878 public double Similarity ( string s1 , string s2 )
7979 => Similarity ( s1 . AsSpan ( ) , s2 . AsSpan ( ) ) ;
80-
80+
8181 public double Similarity < T > ( ReadOnlySpan < T > s1 , ReadOnlySpan < T > s2 )
8282 where T : IEquatable < T >
8383 {
84+ if ( s1 == null )
85+ {
86+ throw new ArgumentNullException ( nameof ( s1 ) ) ;
87+ }
88+
89+ if ( s2 == null )
90+ {
91+ throw new ArgumentNullException ( nameof ( s2 ) ) ;
92+ }
93+
8494 if ( s1 . SequenceEqual ( s2 ) )
8595 {
8696 return 1f ;
@@ -112,7 +122,7 @@ public double Similarity<T>(ReadOnlySpan<T> s1, ReadOnlySpan<T> s2)
112122 /// <exception cref="ArgumentNullException">If s1 or s2 is null.</exception>
113123 public double Distance ( string s1 , string s2 )
114124 => 1.0 - Similarity ( s1 , s2 ) ;
115-
125+
116126 public double Distance < T > ( ReadOnlySpan < T > s1 , ReadOnlySpan < T > s2 )
117127 where T : IEquatable < T >
118128 => 1.0 - Similarity ( s1 , s2 ) ;
@@ -192,7 +202,7 @@ private static int[] Matches<T>(ReadOnlySpan<T> s1, ReadOnlySpan<T> s2)
192202 break ;
193203 }
194204 }
195- return [ matches , transpositions / 2 , prefix , max . Length ] ;
205+ return new [ ] { matches , transpositions / 2 , prefix , max . Length } ;
196206 }
197207 }
198208}
0 commit comments