Skip to content

Commit 8536fc9

Browse files
committed
Clarified the renaming of members.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 3917ca2 commit 8536fc9

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/Generator/Passes/RenamePass.cs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -362,20 +362,7 @@ static string ConvertCaseString(Declaration decl, RenameCasePattern pattern)
362362
if (sb[0] == '@')
363363
sb.Remove(0, 1);
364364

365-
for (int i = sb.Length - 1; i >= 0; i--)
366-
{
367-
if (sb[i] != '_' ||
368-
// lower case intentional if the first character is already upper case
369-
(i + 1 < sb.Length && char.IsLower(sb[i + 1]) && char.IsUpper(sb[0])) ||
370-
// don't end up with more capitals or digits in a row than before
371-
(i > 0 && (char.IsUpper(sb[i - 1]) ||
372-
(i < sb.Length - 1 && char.IsDigit(sb[i + 1]) && char.IsDigit(sb[i - 1])))))
373-
continue;
374-
375-
if (i < sb.Length - 1)
376-
sb[i + 1] = char.ToUpperInvariant(sb[i + 1]);
377-
sb.Remove(i, 1);
378-
}
365+
RemoveUnderscores(sb);
379366

380367
var @class = decl as Class;
381368
switch (pattern)
@@ -396,6 +383,24 @@ static string ConvertCaseString(Declaration decl, RenameCasePattern pattern)
396383

397384
return sb.ToString();
398385
}
386+
387+
private static void RemoveUnderscores(StringBuilder sb)
388+
{
389+
for (int i = sb.Length - 1; i >= 0; i--)
390+
{
391+
if (sb[i] != '_' ||
392+
// lower case intentional if the first character is already upper case
393+
(i + 1 < sb.Length && char.IsLower(sb[i + 1]) && char.IsUpper(sb[0])) ||
394+
// don't end up with more capitals or digits in a row than before
395+
(i > 0 && (char.IsUpper(sb[i - 1]) ||
396+
(i < sb.Length - 1 && char.IsDigit(sb[i + 1]) && char.IsDigit(sb[i - 1])))))
397+
continue;
398+
399+
if (i < sb.Length - 1)
400+
sb[i + 1] = char.ToUpperInvariant(sb[i + 1]);
401+
sb.Remove(i, 1);
402+
}
403+
}
399404
}
400405

401406
public static class RenamePassExtensions

0 commit comments

Comments
 (0)