Last active
August 29, 2015 14:12
-
-
Save mnstrspeed/81e2547f4d09ec67a05d to your computer and use it in GitHub Desktop.
CamelCase-enizer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CamelCase { | |
public static void main(String[] args) { | |
String line = "if at lake and lake has not been probed, blink lights, probe lake, steer away from obstacles"; | |
System.out.println(toCamelCase(line) + "Rule"); | |
// IfAtLakeAndLakeHasNotBeenProbedThenBlinkLightsThenProbeLakeThenSteerAwayFromObstaclesRule | |
} | |
private static String toCamelCase(String line) { | |
StringBuilder builder = new StringBuilder(); | |
boolean nextUpper = true; | |
for (char c : line.toCharArray()) { | |
if (Character.isAlphabetic(c)) { | |
builder.append(nextUpper ? Character.toUpperCase(c) : Character.toLowerCase(c)); | |
nextUpper = false; | |
} else if (c == ',') { | |
builder.append("Then"); | |
nextUpper = false; | |
} else if (Character.isWhitespace(c)) { | |
nextUpper = true; | |
} | |
} | |
return builder.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment