pascalToSnake function

String pascalToSnake(
  1. String input
)

Implementation

String pascalToSnake(String input) {
  if (input.isEmpty) return '';
  StringBuffer result = StringBuffer();
  for (int i = 0; i < input.length; i++) {
    if (i != 0 && input[i] != '_' && input[i].toUpperCase() == input[i]) {
      result.write('_');
    }
    result.write(input[i].toLowerCase());
  }
  return result.toString();
}