@@ -4234,6 +4234,29 @@ namespace ts {
4234
4234
// Firefox has Object.prototype.watch
4235
4235
return options . watch && options . hasOwnProperty ( "watch" ) ;
4236
4236
}
4237
+
4238
+ export function levenshtein ( s1 : string , s2 : string ) : number {
4239
+ let previous : number [ ] = new Array ( s2 . length + 1 ) ;
4240
+ let current : number [ ] = new Array ( s2 . length + 1 ) ;
4241
+ for ( let i = 0 ; i < s2 . length + 1 ; i ++ ) {
4242
+ previous [ i ] = i ;
4243
+ current [ i ] = - 1 ;
4244
+ }
4245
+ for ( let i = 1 ; i < s1 . length + 1 ; i ++ ) {
4246
+ current [ 0 ] = i ;
4247
+ for ( let j = 1 ; j < s2 . length + 1 ; j ++ ) {
4248
+ current [ j ] = Math . min (
4249
+ previous [ j ] + 1 ,
4250
+ current [ j - 1 ] + 1 ,
4251
+ previous [ j - 1 ] + ( s1 [ i - 1 ] === s2 [ j - 1 ] ? 0 : 2 ) ) ;
4252
+ }
4253
+ // shift current back to previous, and then reuse previous' array
4254
+ const tmp = previous ;
4255
+ previous = current ;
4256
+ current = tmp ;
4257
+ }
4258
+ return previous [ previous . length - 1 ] ;
4259
+ }
4237
4260
}
4238
4261
4239
4262
namespace ts {
@@ -4664,27 +4687,4 @@ namespace ts {
4664
4687
export function unescapeIdentifier ( identifier : string ) : string {
4665
4688
return identifier . length >= 3 && identifier . charCodeAt ( 0 ) === CharacterCodes . _ && identifier . charCodeAt ( 1 ) === CharacterCodes . _ && identifier . charCodeAt ( 2 ) === CharacterCodes . _ ? identifier . substr ( 1 ) : identifier ;
4666
4689
}
4667
-
4668
- export function levenshtein ( s1 : string , s2 : string ) : number {
4669
- let previous : number [ ] = new Array ( s2 . length + 1 ) ;
4670
- let current : number [ ] = new Array ( s2 . length + 1 ) ;
4671
- for ( let i = 0 ; i < s2 . length + 1 ; i ++ ) {
4672
- previous [ i ] = i ;
4673
- current [ i ] = - 1 ;
4674
- }
4675
- for ( let i = 1 ; i < s1 . length + 1 ; i ++ ) {
4676
- current [ 0 ] = i ;
4677
- for ( let j = 1 ; j < s2 . length + 1 ; j ++ ) {
4678
- current [ j ] = Math . min (
4679
- previous [ j ] + 1 ,
4680
- current [ j - 1 ] + 1 ,
4681
- previous [ j - 1 ] + ( s1 [ i - 1 ] === s2 [ j - 1 ] ? 0 : 2 ) ) ;
4682
- }
4683
- // shift current back to previous, and then reuse previous' array
4684
- const tmp = previous ;
4685
- previous = current ;
4686
- current = tmp ;
4687
- }
4688
- return previous [ previous . length - 1 ] ;
4689
- }
4690
4690
}
0 commit comments