getOriginal function
- String input
Implementation
String getOriginal(String input) {
// Return the original variable name (before the transformation) given the
// supplied variable name after the transformation.
// Find the index of the first underscore.
int firstUnderscoreIndex = input.indexOf('_');
// If no underscore is found, return the original string.
if (firstUnderscoreIndex == -1) {
return input;
}
// Extract the prefix from the input string.
String prefix = input.substring(0, firstUnderscoreIndex);
// Remove everything before and including the first underscore.
String result = input.substring(firstUnderscoreIndex + 1);
// If the prefix is in the list of special prefixes, handle the suffix.
if (specialPrefixes.contains(prefix)) {
int lastUnderscoreIndex = result.lastIndexOf('_');
if (lastUnderscoreIndex != -1) {
// Remove the last underscore and everything after it.
result = result.substring(0, lastUnderscoreIndex);
}
}
return result;
}