/**
 * The namespace for string-specific algorithms.
 */ export namespace StringExt { param source param query param start returns export function findIndices ( source , query , start = 0 ) { let indices = new Array < number > ( query . length ) ; for ( let i = 0 , j = start , n = query . length ; i < n ; ++ i , ++ j ) { j = source . indexOf ( query [ i ] , j ) ; if ( j === - 1 ) { return null ; } indices [ i ] = j ; } return indices ; } /**
     * The result of a string match function.
     */ export interface IMatchResult { /**
         * A score which indicates the strength of the match.
         *
         * The documentation of a given match function should specify
         * whether a lower or higher score is a stronger match.
         */ score : number ; /**
         * The indices of the matched characters in the source text.
         *
         * The indices will appear in increasing order.
         */ indices : number [ ] ; } param source param query param start returns export function matchSumOfSquares ( source , query , start = 0 ) { let indices = findIndices ( source , query , start ) ; if ( ! indices ) { return null ; } let score = 0 ; for ( let i = 0 , n = indices . length ; i < n ; ++ i ) { let j = indices [ i ] - start ; score += j * j ; } return { score , indices } ; } param source param query param start returns export function matchSumOfDeltas ( source , query , start = 0 ) { let indices = findIndices ( source , query , start ) ; if ( ! indices ) { return null ; } let score = 0 ; let last = start - 1 ; for ( let i = 0 , n = indices . length ; i < n ; ++ i ) { let j = indices [ i ] ; score += j - last - 1 ; last = j ; } return { score , indices } ; } param source param indices param fn returns export function highlight < T > ( source , indices , fn ) { let result = [ ] ; let k = 0 ; let last = 0 ; let n = indices . length ; while ( k < n ) { let i = indices [ k ] ; let j = indices [ k ] ; while ( ++ k < n && indices [ k ] === j + 1 ) { j ++ ; } if ( last < i ) { result . push ( source . slice ( last , i ) ) ; } if ( i < j + 1 ) { result . push ( fn ( source . slice ( i , j + 1 ) ) ) ; } last = j + 1 ; } if ( last < source . length ) { result . push ( source . slice ( last ) ) ; } return result ; } param a param b returns export function cmp ( a , b ) { return a < b ? - 1 : a > b ? 1 : 0 ; } }