if ($next === false) {
return;
}
+ $original = substr($text, $next, strlen($word));
+ $replacement = self::fixLetterCase($correct_word, $original);
$this->raiseLintAtOffset(
$next,
$severity,
"Possible spelling error. You wrote '%s', but did you mean '%s'?",
$word,
$correct_word
- )
+ ),
+ $original,
+ $replacement
);
$pos = $next + 1;
}
return;
}
foreach ($matches[0] as $match) {
+ $original = $match[0];
+ $replacement = self::fixLetterCase($correct_word, $original);
$this->raiseLintAtOffset(
$match[1],
$severity,
"Possible spelling error. You wrote '%s', but did you mean '%s'?",
$word,
$correct_word
- )
+ ),
+ $original,
+ $replacement
);
}
}
+
+ public static function fixLetterCase($string, $case) {
+ if ($case == strtolower($case)) {
+ return strtolower($string);
+ }
+ if ($case == strtoupper($case)) {
+ return strtoupper($string);
+ }
+ if ($case == ucwords(strtolower($case))) {
+ return ucwords(strtolower($string));
+ }
+ return null;
+ }
+
}
$working_copy);
}
+ public function testFixLetterCase() {
+ $tests = array(
+ 'tst' => 'test',
+ 'Tst' => 'Test',
+ 'TST' => 'TEST',
+ 'tSt' => null,
+ );
+ foreach ($tests as $case => $expect) {
+ foreach (array('test', 'TEST') as $string) {
+ $result = ArcanistSpellingLinter::fixLetterCase($string, $case);
+ $this->assertEqual($expect, $result, $case);
+ }
+ }
+ }
+
}