[Feat] added String camelcase to title extension.
This commit is contained in:
@@ -17,13 +17,13 @@ extension StringExtensions on String {
|
|||||||
return (length > 1) ? this[0].toUpperCase() + substring(1) : toUpperCase();
|
return (length > 1) ? this[0].toUpperCase() + substring(1) : toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert CamelCase to a capitalized space separated title.
|
/// Convert CamelCase to a capitalized space separated title.
|
||||||
String camelCaseToTitle(String input) {
|
String camelCaseToTitle(String input) {
|
||||||
final spaced = input.replaceAllMapped(
|
final String spaced = input.replaceAllMapped(
|
||||||
RegExp(r'([a-z])([A-Z])'),
|
RegExp(r'([a-z])([A-Z])'),
|
||||||
(match) => '${match.group(1)} ${match.group(2)}',
|
(Match match) => '${match.group(1)} ${match.group(2)}',
|
||||||
);
|
);
|
||||||
|
|
||||||
return spaced.split(' ').map((word) => word[0].toUpperCase() + word.substring(1)).join(' ');
|
return spaced.split(' ').map((String word) => word[0].toUpperCase() + word.substring(1)).join(' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user