toLowerCaseUnderscore static method
Transforms s
to lower-case using underscore (_
)
before the upper-case letters.
- If
simple
istrue
removes non-letters and non-digits.
Implementation
static String toLowerCaseUnderscore(String s, {bool simple = false}) {
if (simple) {
s = s.replaceAll(_regexpNotLettersAndDigits, '_');
}
var str = StringBuffer();
String? prevChar;
for (var rune in s.runes) {
var char = String.fromCharCode(rune);
if (prevChar != null && isUpperCase(char) && isLetterOrDigit(char)) {
if (char != '_' && prevChar != '_') {
str.write('_');
}
}
str.write(char.toLowerCase());
prevChar = char;
}
return str.toString();
}