toLowerCamelCase method
Anything with word separation to lowerCamelCase. Example: Hello, Santiago! How are you? Are you 28 years old? Ya-Yo! Become: helloSantiagoHowAreYouAreYou28YearsOldYaYo
But string hellosantiagohowareyou becomes itself, because no word separation present.
Implementation
String toLowerCamelCase() {
final classes = _wordCharacterClasses.map((clas) => r'\p{' '$clas}').join();
final nonLetterManyThenOneLetter = RegExp(
'[^' '$classes]+[$classes]',
unicode: true,
);
final firstLetter = RegExp(
'^[ $classes]{1}',
unicode: true,
);
final badEnd = RegExp(
'[^ $classes' r']$',
unicode: true,
);
return replaceAllMapped(nonLetterManyThenOneLetter, (match) {
/// We found substring ending with a letter.
final string = match.group(0)!;
return string.characters.last.toUpperCase();
})
.replaceFirstMapped(
firstLetter, (match) => match.group(0)!.toLowerCase())
.replaceAll(badEnd, '');
}