File tree Expand file tree Collapse file tree 4 files changed +60
-5
lines changed
Expand file tree Collapse file tree 4 files changed +60
-5
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
1010Nothing yet.
1111
12+ ## [ 1.20.4] - 2025-04-16
13+
14+ ### Added
15+
16+ - Method ` StringExtensions.Humanize ` .
17+
1218## [ 1.20.3] - 2025-04-16
1319
1420### Fixed
@@ -281,7 +287,8 @@ Nothing yet.
281287
282288- Implemented StringExtensions.
283289
284- [ unreleased ] : https://github.com/Logitar/Logitar.NET/compare/v1.20.3...HEAD
290+ [ unreleased ] : https://github.com/Logitar/Logitar.NET/compare/v1.20.4...HEAD
291+ [ 1.20.4 ] : https://github.com/Logitar/Logitar.NET/compare/v1.20.3...v1.20.4
285292[ 1.20.3 ] : https://github.com/Logitar/Logitar.NET/compare/v1.20.2...v1.20.3
286293[ 1.20.2 ] : https://github.com/Logitar/Logitar.NET/compare/v1.20.1...v1.20.2
287294[ 1.20.1 ] : https://github.com/Logitar/Logitar.NET/compare/v1.20.0...v1.20.1
Original file line number Diff line number Diff line change 1515 <PackageReadmeFile >README.md</PackageReadmeFile >
1616 <RepositoryType >git</RepositoryType >
1717 <RepositoryUrl >https://github.com/Logitar/Logitar.NET</RepositoryUrl >
18- <AssemblyVersion >7.0 .0.0</AssemblyVersion >
18+ <AssemblyVersion >7.1 .0.0</AssemblyVersion >
1919 <FileVersion >$(AssemblyVersion)</FileVersion >
2020 <PackageLicenseFile >LICENSE</PackageLicenseFile >
2121 <PackageRequireLicenseAcceptance >True</PackageRequireLicenseAcceptance >
22- <Version >7.0 .0</Version >
22+ <Version >7.1 .0</Version >
2323 <NeutralLanguage >en-CA</NeutralLanguage >
2424 <GenerateDocumentationFile >True</GenerateDocumentationFile >
25- <PackageReleaseNotes >Removed `ExceptionDetail` and dependency from `System.Text.Json` .</PackageReleaseNotes >
25+ <PackageReleaseNotes >Added `StringExtensions.Humanize` method .</PackageReleaseNotes >
2626 <PackageTags >logitar net framework</PackageTags >
2727 <PackageProjectUrl >https://github.com/Logitar/Logitar.NET/tree/dev/src/Logitar</PackageProjectUrl >
2828 </PropertyGroup >
Original file line number Diff line number Diff line change 1- namespace Logitar ;
1+ using System . Text ;
2+
3+ namespace Logitar ;
24
35/// <summary>
46/// Provides extension methods for <see cref="string"/> instances.
@@ -33,6 +35,41 @@ public static string FromUriSafeBase64(this string s)
3335 /// <returns>The Uri-safe base6 version of the string.</returns>
3436 public static string ToUriSafeBase64 ( this string s ) => s . Replace ( '+' , '-' ) . Replace ( '/' , '_' ) . TrimEnd ( '=' ) ;
3537
38+ /// <summary>
39+ /// Humanizes the specified string by inserting spaces between words. Words are separated by case-change, such as in camelCase and PascalCase.
40+ /// </summary>
41+ /// <param name="s">The camelCase or PascalCase string.</param>
42+ /// <returns>The humanized string.</returns>
43+ public static string Humanize ( this string s )
44+ {
45+ List < string > words = new ( capacity : s . Length ) ;
46+
47+ StringBuilder word = new ( ) ;
48+ for ( int i = 0 ; i < s . Length ; i ++ )
49+ {
50+ char ? previous = ( i > 0 ) ? s [ i - 1 ] : null ;
51+ char current = s [ i ] ;
52+ char ? next = ( i < s . Length - 1 ) ? s [ i + 1 ] : null ;
53+
54+ if ( char . IsUpper ( current ) && ( ( previous . HasValue && char . IsLower ( previous . Value ) ) || ( next . HasValue && char . IsLower ( next . Value ) ) ) )
55+ {
56+ if ( word . Length > 0 )
57+ {
58+ words . Add ( word . ToString ( ) ) ;
59+ word . Clear ( ) ;
60+ }
61+ }
62+
63+ word . Append ( current ) ;
64+ }
65+ if ( word . Length > 0 )
66+ {
67+ words . Add ( word . ToString ( ) ) ;
68+ }
69+
70+ return string . Join ( ' ' , words ) ;
71+ }
72+
3673 /// <summary>
3774 /// Returns a new string where every character of the specified string has been replaced by the specified mask character (defaults to '*').
3875 /// </summary>
Original file line number Diff line number Diff line change @@ -31,6 +31,17 @@ public void FromUriSafeBase64_uri_safe_base64_is_correctly_parsed(string base64)
3131 Assert . Equal ( bytes , other ) ;
3232 }
3333
34+ [ Theory ( DisplayName = "Humanize: it should return the correct humanized string." ) ]
35+ [ InlineData ( "" , "" ) ]
36+ [ InlineData ( " " , " " ) ]
37+ [ InlineData ( "helloWorld" , "hello World" ) ]
38+ [ InlineData ( "HelloWorld1!" , "Hello World1!" ) ]
39+ [ InlineData ( "UserID" , "User ID" ) ]
40+ public void Humanize_it_returns_the_correct_humanized_string ( string input , string expected )
41+ {
42+ Assert . Equal ( expected , input . Humanize ( ) ) ;
43+ }
44+
3445 [ Theory ( DisplayName = "Mask: it returns the correct masked string." ) ]
3546 [ InlineData ( " " ) ]
3647 [ InlineData ( "P@s$W0rD" , '-' ) ]
You can’t perform that action at this time.
0 commit comments