camelCaseToUpperUnderscore static method

String camelCaseToUpperUnderscore(
  1. String s
)

Transfers the given String s from camcelCase to upperCaseUnderscore Example : helloWorld => HELLO_WORLD

Implementation

static String camelCaseToUpperUnderscore(String s) {
  var sb = StringBuffer();
  var first = true;
  s.runes.forEach((int rune) {
    var char = String.fromCharCode(rune);
    if (isUpperCase(char) && !first) {
      sb.write('_');
      sb.write(char.toUpperCase());
    } else {
      first = false;
      sb.write(char.toUpperCase());
    }
  });
  return sb.toString();
}