formatClassName method
Formats the extracted filename
First letter needs to be capitalited All occurences of underscores needs to be replaced with an empty string
First letter appearing after each underscore also uppercase Example: three_named_component -> class ThreeNamedComponent ...
Implementation
String formatClassName(final bool verbose, final String filename) {
String className = filename.capitalize();
String name = EMPTY_STRING;
if (className.contains(UNDERSCORE)) {
/// Build [name] char by char
for (int i = 0; i < className.length; i++) {
final String char = className[i];
if (char == UNDERSCORE) {
// Capitalize the next index and skip it
name += className[i + 1].capitalize();
i++;
} else {
// Add normally
name += char;
}
}
// Finally replace all occurences
name = name.replaceAll(UNDERSCORE, EMPTY_STRING);
} else {
name = className;
}
VerboseLogger.logFormattedClassname(verbose, filename, name);
return name;
}