normalizeCasingOfParagraph function
Normalizes the casing of the input string by processing each sentence.
This function takes a String input and returns a new string with the casing
normalized. It processes the input by breaking it into sentences, and then
applies casing rules to each sentence.
The function handles various sentence-ending characters (., !, ?, \n)
and preserves any non-letter characters in the input.
Implementation
String normalizeCasingOfParagraph(final String input) {
if (input.isEmpty) {
return input;
}
// Define sentence-ending characters
const List<String> sentenceEndings = ['.', '!', '?', '\n'];
StringBuffer result = StringBuffer();
StringBuffer currentSentence = StringBuffer();
for (int i = 0; i < input.length; i++) {
String char = input[i];
currentSentence.write(char);
// If the character is a sentence-ending character, process the sentence
if (sentenceEndings.contains(char)) {
result.write(normalizeCasingOfSentence(currentSentence.toString()));
currentSentence.clear();
}
}
// Process any remaining sentence
if (currentSentence.isNotEmpty) {
result.write(normalizeCasingOfSentence(currentSentence.toString()));
}
return result.toString();
}