Merge pull request #119373 from wdesgardin/fix/replace-pattern-preserve-case
fix(search): preserve case when match start with lowercase char
This commit is contained in:
commit
6349f37d80
2 changed files with 10 additions and 2 deletions
|
@ -20,6 +20,8 @@ export function buildReplaceStringWithCasePreserved(matches: string[] | null, pa
|
|||
return pattern.toLowerCase();
|
||||
} else if (strings.containsUppercaseCharacter(matches[0][0]) && pattern.length > 0) {
|
||||
return pattern[0].toUpperCase() + pattern.substr(1);
|
||||
} else if (matches[0][0].toUpperCase() !== matches[0][0] && pattern.length > 0) {
|
||||
return pattern[0].toLowerCase() + pattern.substr(1);
|
||||
} else {
|
||||
// we don't understand its pattern yet.
|
||||
return pattern;
|
||||
|
|
|
@ -200,13 +200,16 @@ suite('Replace Pattern test', () => {
|
|||
assertReplace(['abc', 'Abc'], 'Def', 'def');
|
||||
assertReplace(['Abc', 'abc'], 'Def', 'Def');
|
||||
assertReplace(['ABC', 'abc'], 'Def', 'DEF');
|
||||
assertReplace(['aBc', 'abc'], 'Def', 'def');
|
||||
assertReplace(['AbC'], 'Def', 'Def');
|
||||
assertReplace(['aBC'], 'Def', 'Def');
|
||||
assertReplace(['aBC'], 'Def', 'def');
|
||||
assertReplace(['aBc'], 'DeF', 'deF');
|
||||
assertReplace(['Foo-Bar'], 'newfoo-newbar', 'Newfoo-Newbar');
|
||||
assertReplace(['Foo-Bar-Abc'], 'newfoo-newbar-newabc', 'Newfoo-Newbar-Newabc');
|
||||
assertReplace(['Foo-Bar-abc'], 'newfoo-newbar', 'Newfoo-newbar');
|
||||
assertReplace(['foo-Bar'], 'newfoo-newbar', 'newfoo-Newbar');
|
||||
assertReplace(['foo-BAR'], 'newfoo-newbar', 'newfoo-NEWBAR');
|
||||
assertReplace(['foO-BAR'], 'NewFoo-NewBar', 'newFoo-NEWBAR');
|
||||
assertReplace(['Foo_Bar'], 'newfoo_newbar', 'Newfoo_Newbar');
|
||||
assertReplace(['Foo_Bar_Abc'], 'newfoo_newbar_newabc', 'Newfoo_Newbar_Newabc');
|
||||
assertReplace(['Foo_Bar_abc'], 'newfoo_newbar', 'Newfoo_newbar');
|
||||
|
@ -228,13 +231,16 @@ suite('Replace Pattern test', () => {
|
|||
assertReplace(['abc', 'Abc'], 'Def', 'def');
|
||||
assertReplace(['Abc', 'abc'], 'Def', 'Def');
|
||||
assertReplace(['ABC', 'abc'], 'Def', 'DEF');
|
||||
assertReplace(['aBc', 'abc'], 'Def', 'def');
|
||||
assertReplace(['AbC'], 'Def', 'Def');
|
||||
assertReplace(['aBC'], 'Def', 'Def');
|
||||
assertReplace(['aBC'], 'Def', 'def');
|
||||
assertReplace(['aBc'], 'DeF', 'deF');
|
||||
assertReplace(['Foo-Bar'], 'newfoo-newbar', 'Newfoo-Newbar');
|
||||
assertReplace(['Foo-Bar-Abc'], 'newfoo-newbar-newabc', 'Newfoo-Newbar-Newabc');
|
||||
assertReplace(['Foo-Bar-abc'], 'newfoo-newbar', 'Newfoo-newbar');
|
||||
assertReplace(['foo-Bar'], 'newfoo-newbar', 'newfoo-Newbar');
|
||||
assertReplace(['foo-BAR'], 'newfoo-newbar', 'newfoo-NEWBAR');
|
||||
assertReplace(['foO-BAR'], 'NewFoo-NewBar', 'newFoo-NEWBAR');
|
||||
assertReplace(['Foo_Bar'], 'newfoo_newbar', 'Newfoo_Newbar');
|
||||
assertReplace(['Foo_Bar_Abc'], 'newfoo_newbar_newabc', 'Newfoo_Newbar_Newabc');
|
||||
assertReplace(['Foo_Bar_abc'], 'newfoo_newbar', 'Newfoo_newbar');
|
||||
|
|
Loading…
Reference in a new issue