Skip to content

Instantly share code, notes, and snippets.

@xeno-by
Created December 5, 2011 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xeno-by/1433353 to your computer and use it in GitHub Desktop.
Save xeno-by/1433353 to your computer and use it in GitHub Desktop.
Func<String, String> x = name => {
var buf = new StringBuilder();
for (var i = 0; i < name.Length; ++i) {
var prev = i == 0 ? '\0' : name[i - 1];
var curr = name[i];
var next = i == name.Length - 1 ? '\0' : name[i + 1];
if (Char.IsLower(prev) && Char.IsUpper(curr) && !Char.IsUpper(next)) {
buf.Append("-");
buf.Append(Char.ToLower(curr));
} else {
buf.Append(curr);
}
}
return buf.ToString();
};
x("test").Dump(); // prints "test"
x("compileTest").Dump(); // prints "compile-test"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment