Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Camelize() does not respect acronyms #1301

Open
iikuzmychov opened this issue Nov 6, 2023 · 0 comments
Open

[Bug] Camelize() does not respect acronyms #1301

iikuzmychov opened this issue Nov 6, 2023 · 0 comments

Comments

@iikuzmychov
Copy link

iikuzmychov commented Nov 6, 2023

Issue

I have an issue using Camelize() method. It works not exactly as I expected.

Example

The next code

"IOModule".Camelize()

will return

"iOModule"

while I'm expecting

"ioModule"

I think it's a bug, we do need respect acronyms on camelizing strings.

Proposed solution

I took the original code of Camelize() method and reworked it a bit:

public static string CamelizeRespectingAcronyms(this string input)
{
  var pascalized = input.Pascalize();
  
  if (pascalized.Length == 0)
  {
    return pascalized;
  }

  var firstUpperSymbolsCount = pascalized.TakeWhile(char.IsUpper).Count();

  if (firstUpperSymbolsCount > 2)
  {
    var acronymLength = firstUpperSymbolsCount - 1;

    return pascalized[..acronymLength].ToLower() + pascalized[acronymLength..];
  }

  return pascalized[..1].ToLower() + pascalized[1..];
}

The update method is returning

"ioModule"

for

"IOModule".Capitilize()
@iikuzmychov iikuzmychov changed the title [Bug/Propose] Respect acronyms in Camelize() [Bug/Propose] Camelize() does not respect acronyms Nov 8, 2023
@iikuzmychov iikuzmychov changed the title [Bug/Propose] Camelize() does not respect acronyms [Bug] Camelize() does not respect acronyms Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant