* Given two strings, compute a score representing whether the internal * boundary falls on logical boundaries. * Scores range from 6 (best) to 0 (worst). * Closure, but does not reference any external variables. * @param {string} one First string. * @param {string} two Second string.
(one: string, two: string)
| 303 | * @private |
| 304 | */ |
| 305 | function diff_cleanupSemanticScore_(one: string, two: string): number { |
| 306 | if (!one || !two) { |
| 307 | // Edges are the best. |
| 308 | return 6; |
| 309 | } |
| 310 | |
| 311 | // Each port of this function behaves slightly differently due to |
| 312 | // subtle differences in each language's definition of things like |
| 313 | // 'whitespace'. Since this function's purpose is largely cosmetic, |
| 314 | // the choice has been made to use each language's native features |
| 315 | // rather than force total conformity. |
| 316 | var char1 = one.charAt(one.length - 1); |
| 317 | var char2 = two.charAt(0); |
| 318 | var nonAlphaNumeric1 = char1.match(nonAlphaNumericRegex_); |
| 319 | var nonAlphaNumeric2 = char2.match(nonAlphaNumericRegex_); |
| 320 | var whitespace1 = nonAlphaNumeric1 && |
| 321 | char1.match(whitespaceRegex_); |
| 322 | var whitespace2 = nonAlphaNumeric2 && |
| 323 | char2.match(whitespaceRegex_); |
| 324 | var lineBreak1 = whitespace1 && |
| 325 | char1.match(linebreakRegex_); |
| 326 | var lineBreak2 = whitespace2 && |
| 327 | char2.match(linebreakRegex_); |
| 328 | var blankLine1 = lineBreak1 && |
| 329 | one.match(blanklineEndRegex_); |
| 330 | var blankLine2 = lineBreak2 && |
| 331 | two.match(blanklineStartRegex_); |
| 332 | |
| 333 | if (blankLine1 || blankLine2) { |
| 334 | // Five points for blank lines. |
| 335 | return 5; |
| 336 | } else if (lineBreak1 || lineBreak2) { |
| 337 | // Four points for line breaks. |
| 338 | return 4; |
| 339 | } else if (nonAlphaNumeric1 && !whitespace1 && whitespace2) { |
| 340 | // Three points for end of sentences. |
| 341 | return 3; |
| 342 | } else if (whitespace1 || whitespace2) { |
| 343 | // Two points for whitespace. |
| 344 | return 2; |
| 345 | } else if (nonAlphaNumeric1 || nonAlphaNumeric2) { |
| 346 | // One point for non-alphanumeric. |
| 347 | return 1; |
| 348 | } |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | var pointer = 1; |
| 353 | // Intentionally ignore the first and last element (don't need checking). |
no test coverage detected