From 92590b2f677b86c1056942e3f4b625e7fff08db9 Mon Sep 17 00:00:00 2001 From: "Michael W. Aziz" Date: Fri, 13 Jun 2025 20:42:45 +0300 Subject: [PATCH] [Feat] added String camelcase to title extension. --- debug.log | 2 ++ lib/src/string_extensions.dart | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100644 debug.log diff --git a/debug.log b/debug.log new file mode 100644 index 0000000..8b390c5 --- /dev/null +++ b/debug.log @@ -0,0 +1,2 @@ +[0330/121753.404:ERROR:crashpad_client_win.cc(811)] not connected +[0330/121753.573:ERROR:crashpad_client_win.cc(811)] not connected diff --git a/lib/src/string_extensions.dart b/lib/src/string_extensions.dart index 050d38c..c38c424 100644 --- a/lib/src/string_extensions.dart +++ b/lib/src/string_extensions.dart @@ -16,4 +16,14 @@ extension StringExtensions on String { String get capitalize { return (length > 1) ? this[0].toUpperCase() + substring(1) : toUpperCase(); } + + /// Convert CamelCase to a capitalized space separated title. + String camelCaseToTitle(String input) { + final spaced = input.replaceAllMapped( + RegExp(r'([a-z])([A-Z])'), + (match) => '${match.group(1)} ${match.group(2)}', + ); + + return spaced.split(' ').map((word) => word[0].toUpperCase() + word.substring(1)).join(' '); + } }