- Null `String`s being manipulated should return `null` instead of an empty `String`

Signed-off-by: Hans Kokx <hans.kokx@hackberry.se>
This commit is contained in:
Hans Kokx
2024-11-06 12:46:18 +01:00
parent 8b9842e664
commit 92f475a8c7
3 changed files with 11 additions and 7 deletions
+6 -6
View File
@@ -87,8 +87,8 @@ extension TextManipulation on String? {
/// String text = "hello";
/// String capitalized = text.capitalize; // "Hello"
/// ```
String get capitalize {
if (isNullOrEmpty) return "";
String? get capitalize {
if (isNullOrEmpty) return null;
return "${this![0].toUpperCase()}${this!.substring(1).toLowerCase()}";
}
@@ -102,8 +102,8 @@ extension TextManipulation on String? {
/// String text = "hello world";
/// String capitalizedWords = text.capitalizeWords; // "Hello World"
/// ```
String get capitalizeWords {
if (isNullOrEmpty) return "";
String? get capitalizeWords {
if (isNullOrEmpty) return null;
final strings = this!.split(" ");
return strings.map((s) => s.capitalize).join(" ");
}
@@ -120,8 +120,8 @@ extension TextManipulation on String? {
/// String text = "ArcaneHelperUtils";
/// String spaced = text.spacePascalCase; // "Arcane Helper Utils"
/// ```
String get spacePascalCase {
if (isNullOrEmpty) return "";
String? get spacePascalCase {
if (isNullOrEmpty) return null;
final List<String> strings = this!.split(
"",
);