transform method
Transforms a String to the given CaseStyle
Implementation
String transform(String text) {
var style = this;
if (style == null) {
return text;
} else {
// Leading, trailing and repeated separators produce empty words.
// Dropping them avoids empty keys and stray separators.
var words = text.split(_splitter).where((w) => w.isNotEmpty).toList();
if (words.isEmpty) {
return '';
}
if (style.head != null) {
words = [
style.head.transform(words[0]),
...words.skip(1).map((w) => style.tail.transform(w)),
];
} else if (style.tail != null) {
words = words.map((w) => style.tail.transform(w)).toList();
}
return words.join(style.separator);
}
}