├── .gitignore
├── LICENSE
├── Minerals.StringCases.Benchmarks
├── Minerals.StringCases.Benchmarks.csproj
├── Program.cs
├── StringExtensionsBenchmarks.cs
└── StringExtensionsComparison.cs
├── Minerals.StringCases.Tests
├── Minerals.StringCases.Tests.csproj
└── StringExtensionsTests.cs
├── Minerals.StringCases.sln
├── Minerals.StringCases
├── Minerals.StringCases.csproj
├── README.md
└── StringExtensions.cs
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from `dotnet new gitignore`
5 |
6 | # dotenv files
7 | .env
8 |
9 | # User-specific files
10 | *.rsuser
11 | *.suo
12 | *.user
13 | *.userosscache
14 | *.sln.docstates
15 |
16 | # User-specific files (MonoDevelop/Xamarin Studio)
17 | *.userprefs
18 |
19 | # Mono auto generated files
20 | mono_crash.*
21 |
22 | # Build results
23 | [Dd]ebug/
24 | [Dd]ebugPublic/
25 | [Rr]elease/
26 | [Rr]eleases/
27 | x64/
28 | x86/
29 | [Ww][Ii][Nn]32/
30 | [Aa][Rr][Mm]/
31 | [Aa][Rr][Mm]64/
32 | bld/
33 | [Bb]in/
34 | [Oo]bj/
35 | [Ll]og/
36 | [Ll]ogs/
37 |
38 | # Visual Studio 2015/2017 cache/options directory
39 | .vs/
40 | # Uncomment if you have tasks that create the project's static files in wwwroot
41 | #wwwroot/
42 |
43 | # Visual Studio 2017 auto generated files
44 | Generated\ Files/
45 |
46 | # MSTest test Results
47 | [Tt]est[Rr]esult*/
48 | [Bb]uild[Ll]og.*
49 |
50 | # NUnit
51 | *.VisualState.xml
52 | TestResult.xml
53 | nunit-*.xml
54 |
55 | # Build Results of an ATL Project
56 | [Dd]ebugPS/
57 | [Rr]eleasePS/
58 | dlldata.c
59 |
60 | # Benchmark Results
61 | BenchmarkDotNet.Artifacts/
62 |
63 | # .NET
64 | project.lock.json
65 | project.fragment.lock.json
66 | artifacts/
67 |
68 | # Tye
69 | .tye/
70 |
71 | # ASP.NET Scaffolding
72 | ScaffoldingReadMe.txt
73 |
74 | # StyleCop
75 | StyleCopReport.xml
76 |
77 | # Files built by Visual Studio
78 | *_i.c
79 | *_p.c
80 | *_h.h
81 | *.ilk
82 | *.meta
83 | *.obj
84 | *.iobj
85 | *.pch
86 | *.pdb
87 | *.ipdb
88 | *.pgc
89 | *.pgd
90 | *.rsp
91 | *.sbr
92 | *.tlb
93 | *.tli
94 | *.tlh
95 | *.tmp
96 | *.tmp_proj
97 | *_wpftmp.csproj
98 | *.log
99 | *.tlog
100 | *.vspscc
101 | *.vssscc
102 | .builds
103 | *.pidb
104 | *.svclog
105 | *.scc
106 |
107 | # Chutzpah Test files
108 | _Chutzpah*
109 |
110 | # Visual C++ cache files
111 | ipch/
112 | *.aps
113 | *.ncb
114 | *.opendb
115 | *.opensdf
116 | *.sdf
117 | *.cachefile
118 | *.VC.db
119 | *.VC.VC.opendb
120 |
121 | # Visual Studio profiler
122 | *.psess
123 | *.vsp
124 | *.vspx
125 | *.sap
126 |
127 | # Visual Studio Trace Files
128 | *.e2e
129 |
130 | # TFS 2012 Local Workspace
131 | $tf/
132 |
133 | # Guidance Automation Toolkit
134 | *.gpState
135 |
136 | # ReSharper is a .NET coding add-in
137 | _ReSharper*/
138 | *.[Rr]e[Ss]harper
139 | *.DotSettings.user
140 |
141 | # TeamCity is a build add-in
142 | _TeamCity*
143 |
144 | # DotCover is a Code Coverage Tool
145 | *.dotCover
146 |
147 | # AxoCover is a Code Coverage Tool
148 | .axoCover/*
149 | !.axoCover/settings.json
150 |
151 | # Coverlet is a free, cross platform Code Coverage Tool
152 | coverage*.json
153 | coverage*.xml
154 | coverage*.info
155 |
156 | # Visual Studio code coverage results
157 | *.coverage
158 | *.coveragexml
159 |
160 | # NCrunch
161 | _NCrunch_*
162 | .*crunch*.local.xml
163 | nCrunchTemp_*
164 |
165 | # MightyMoose
166 | *.mm.*
167 | AutoTest.Net/
168 |
169 | # Web workbench (sass)
170 | .sass-cache/
171 |
172 | # Installshield output folder
173 | [Ee]xpress/
174 |
175 | # DocProject is a documentation generator add-in
176 | DocProject/buildhelp/
177 | DocProject/Help/*.HxT
178 | DocProject/Help/*.HxC
179 | DocProject/Help/*.hhc
180 | DocProject/Help/*.hhk
181 | DocProject/Help/*.hhp
182 | DocProject/Help/Html2
183 | DocProject/Help/html
184 |
185 | # Click-Once directory
186 | publish/
187 |
188 | # Publish Web Output
189 | *.[Pp]ublish.xml
190 | *.azurePubxml
191 | # Note: Comment the next line if you want to checkin your web deploy settings,
192 | # but database connection strings (with potential passwords) will be unencrypted
193 | *.pubxml
194 | *.publishproj
195 |
196 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
197 | # checkin your Azure Web App publish settings, but sensitive information contained
198 | # in these scripts will be unencrypted
199 | PublishScripts/
200 |
201 | # NuGet Packages
202 | *.nupkg
203 | # NuGet Symbol Packages
204 | *.snupkg
205 | # The packages folder can be ignored because of Package Restore
206 | **/[Pp]ackages/*
207 | # except build/, which is used as an MSBuild target.
208 | !**/[Pp]ackages/build/
209 | # Uncomment if necessary however generally it will be regenerated when needed
210 | #!**/[Pp]ackages/repositories.config
211 | # NuGet v3's project.json files produces more ignorable files
212 | *.nuget.props
213 | *.nuget.targets
214 |
215 | # Microsoft Azure Build Output
216 | csx/
217 | *.build.csdef
218 |
219 | # Microsoft Azure Emulator
220 | ecf/
221 | rcf/
222 |
223 | # Windows Store app package directories and files
224 | AppPackages/
225 | BundleArtifacts/
226 | Package.StoreAssociation.xml
227 | _pkginfo.txt
228 | *.appx
229 | *.appxbundle
230 | *.appxupload
231 |
232 | # Visual Studio cache files
233 | # files ending in .cache can be ignored
234 | *.[Cc]ache
235 | # but keep track of directories ending in .cache
236 | !?*.[Cc]ache/
237 |
238 | # Others
239 | ClientBin/
240 | ~$*
241 | *~
242 | *.dbmdl
243 | *.dbproj.schemaview
244 | *.jfm
245 | *.pfx
246 | *.publishsettings
247 | orleans.codegen.cs
248 |
249 | # Including strong name files can present a security risk
250 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
251 | #*.snk
252 |
253 | # Since there are multiple workflows, uncomment next line to ignore bower_components
254 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
255 | #bower_components/
256 |
257 | # RIA/Silverlight projects
258 | Generated_Code/
259 |
260 | # Backup & report files from converting an old project file
261 | # to a newer Visual Studio version. Backup files are not needed,
262 | # because we have git ;-)
263 | _UpgradeReport_Files/
264 | Backup*/
265 | UpgradeLog*.XML
266 | UpgradeLog*.htm
267 | ServiceFabricBackup/
268 | *.rptproj.bak
269 |
270 | # SQL Server files
271 | *.mdf
272 | *.ldf
273 | *.ndf
274 |
275 | # Business Intelligence projects
276 | *.rdl.data
277 | *.bim.layout
278 | *.bim_*.settings
279 | *.rptproj.rsuser
280 | *- [Bb]ackup.rdl
281 | *- [Bb]ackup ([0-9]).rdl
282 | *- [Bb]ackup ([0-9][0-9]).rdl
283 |
284 | # Microsoft Fakes
285 | FakesAssemblies/
286 |
287 | # GhostDoc plugin setting file
288 | *.GhostDoc.xml
289 |
290 | # Node.js Tools for Visual Studio
291 | .ntvs_analysis.dat
292 | node_modules/
293 |
294 | # Visual Studio 6 build log
295 | *.plg
296 |
297 | # Visual Studio 6 workspace options file
298 | *.opt
299 |
300 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
301 | *.vbw
302 |
303 | # Visual Studio 6 auto-generated project file (contains which files were open etc.)
304 | *.vbp
305 |
306 | # Visual Studio 6 workspace and project file (working project files containing files to include in project)
307 | *.dsw
308 | *.dsp
309 |
310 | # Visual Studio 6 technical files
311 | *.ncb
312 | *.aps
313 |
314 | # Visual Studio LightSwitch build output
315 | **/*.HTMLClient/GeneratedArtifacts
316 | **/*.DesktopClient/GeneratedArtifacts
317 | **/*.DesktopClient/ModelManifest.xml
318 | **/*.Server/GeneratedArtifacts
319 | **/*.Server/ModelManifest.xml
320 | _Pvt_Extensions
321 |
322 | # Paket dependency manager
323 | .paket/paket.exe
324 | paket-files/
325 |
326 | # FAKE - F# Make
327 | .fake/
328 |
329 | # CodeRush personal settings
330 | .cr/personal
331 |
332 | # Python Tools for Visual Studio (PTVS)
333 | __pycache__/
334 | *.pyc
335 |
336 | # Cake - Uncomment if you are using it
337 | # tools/**
338 | # !tools/packages.config
339 |
340 | # Tabs Studio
341 | *.tss
342 |
343 | # Telerik's JustMock configuration file
344 | *.jmconfig
345 |
346 | # BizTalk build output
347 | *.btp.cs
348 | *.btm.cs
349 | *.odx.cs
350 | *.xsd.cs
351 |
352 | # OpenCover UI analysis results
353 | OpenCover/
354 |
355 | # Azure Stream Analytics local run output
356 | ASALocalRun/
357 |
358 | # MSBuild Binary and Structured Log
359 | *.binlog
360 |
361 | # NVidia Nsight GPU debugger configuration file
362 | *.nvuser
363 |
364 | # MFractors (Xamarin productivity tool) working folder
365 | .mfractor/
366 |
367 | # Local History for Visual Studio
368 | .localhistory/
369 |
370 | # Visual Studio History (VSHistory) files
371 | .vshistory/
372 |
373 | # BeatPulse healthcheck temp database
374 | healthchecksdb
375 |
376 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
377 | MigrationBackup/
378 |
379 | # Ionide (cross platform F# VS Code tools) working folder
380 | .ionide/
381 |
382 | # Fody - auto-generated XML schema
383 | FodyWeavers.xsd
384 |
385 | # VS Code files for those working on multiple tools
386 | .vscode/*
387 | !.vscode/tasks.json
388 | !.vscode/launch.json
389 | *.code-workspace
390 |
391 | # Local History for Visual Studio Code
392 | .history/
393 |
394 | # Windows Installer files from build outputs
395 | *.cab
396 | *.msi
397 | *.msix
398 | *.msm
399 | *.msp
400 |
401 | # JetBrains Rider
402 | *.sln.iml
403 | .idea
404 |
405 | ##
406 | ## Visual studio for Mac
407 | ##
408 |
409 |
410 | # globs
411 | Makefile.in
412 | *.userprefs
413 | *.usertasks
414 | config.make
415 | config.status
416 | aclocal.m4
417 | install-sh
418 | autom4te.cache/
419 | *.tar.gz
420 | tarballs/
421 | test-results/
422 |
423 | # Mac bundle stuff
424 | *.dmg
425 | *.app
426 |
427 | # content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
428 | # General
429 | .DS_Store
430 | .AppleDouble
431 | .LSOverride
432 |
433 | # Icon must end with two \r
434 | Icon
435 |
436 |
437 | # Thumbnails
438 | ._*
439 |
440 | # Files that might appear in the root of a volume
441 | .DocumentRevisions-V100
442 | .fseventsd
443 | .Spotlight-V100
444 | .TemporaryItems
445 | .Trashes
446 | .VolumeIcon.icns
447 | .com.apple.timemachine.donotpresent
448 |
449 | # Directories potentially created on remote AFP share
450 | .AppleDB
451 | .AppleDesktop
452 | Network Trash Folder
453 | Temporary Items
454 | .apdisk
455 |
456 | # content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
457 | # Windows thumbnail cache files
458 | Thumbs.db
459 | ehthumbs.db
460 | ehthumbs_vista.db
461 |
462 | # Dump file
463 | *.stackdump
464 |
465 | # Folder config file
466 | [Dd]esktop.ini
467 |
468 | # Recycle Bin used on file shares
469 | $RECYCLE.BIN/
470 |
471 | # Windows Installer files
472 | *.cab
473 | *.msi
474 | *.msix
475 | *.msm
476 | *.msp
477 |
478 | # Windows shortcuts
479 | *.lnk
480 |
481 | # Vim temporary swap files
482 | *.swp
483 |
484 | # USER
485 | *.received.*
486 | !*.verified.*
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Szymon Hałucha
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Minerals.StringCases.Benchmarks/Minerals.StringCases.Benchmarks.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0;net9.0
6 | enable
7 | 12
8 | enable
9 | false
10 | true
11 | Minerals.StringCases.Benchmarks
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Minerals.StringCases.Benchmarks/Program.cs:
--------------------------------------------------------------------------------
1 | using BenchmarkDotNet.Environments;
2 | using BenchmarkDotNet.Diagnosers;
3 | using BenchmarkDotNet.Validators;
4 | using BenchmarkDotNet.Running;
5 | using BenchmarkDotNet.Configs;
6 | using BenchmarkDotNet.Order;
7 | using BenchmarkDotNet.Jobs;
8 |
9 | namespace Minerals.StringCases.Benchmarks
10 | {
11 | public static class Program
12 | {
13 | public static void Main()
14 | {
15 | // BenchmarkRunner.Run
16 | BenchmarkRunner.Run
17 | (
18 | DefaultConfig.Instance
19 | .WithOrderer(new DefaultOrderer(SummaryOrderPolicy.FastestToSlowest))
20 | .AddJob(Job.Default.WithRuntime(CoreRuntime.Core80))
21 | .AddJob(Job.Default.WithRuntime(CoreRuntime.Core90))
22 | .AddValidator(JitOptimizationsValidator.FailOnError)
23 | .AddDiagnoser(MemoryDiagnoser.Default)
24 | );
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/Minerals.StringCases.Benchmarks/StringExtensionsBenchmarks.cs:
--------------------------------------------------------------------------------
1 | using BenchmarkDotNet.Attributes;
2 |
3 | namespace Minerals.StringCases.Benchmarks
4 | {
5 | public class StringExtensionsBenchmarks
6 | {
7 | private const string SampleText = " _ example Variable - - Name 321";
8 |
9 | [Benchmark]
10 | public void PascalCase_FromSampleText()
11 | {
12 | string text = Minerals.StringCases.StringExtensions.ToPascalCase(SampleText);
13 | }
14 |
15 | [Benchmark]
16 | public void CamelCase_FromSampleText()
17 | {
18 | string text = Minerals.StringCases.StringExtensions.ToCamelCase(SampleText);
19 | }
20 |
21 | [Benchmark]
22 | public void UnderscoreCamelCase_FromSampleText()
23 | {
24 | string text = Minerals.StringCases.StringExtensions.ToUnderscoreCamelCase(SampleText);
25 | }
26 |
27 | [Benchmark]
28 | public void KebabCase_FromSampleText()
29 | {
30 | string text = Minerals.StringCases.StringExtensions.ToKebabCase(SampleText);
31 | }
32 |
33 | [Benchmark]
34 | public void SnakeCase_FromSampleText()
35 | {
36 | string text = Minerals.StringCases.StringExtensions.ToSnakeCase(SampleText);
37 | }
38 |
39 | [Benchmark]
40 | public void MacroCase_FromSampleText()
41 | {
42 | string text = Minerals.StringCases.StringExtensions.ToMacroCase(SampleText);
43 | }
44 |
45 | [Benchmark]
46 | public void TrainCase_FromSampleText()
47 | {
48 | string text = Minerals.StringCases.StringExtensions.ToTrainCase(SampleText);
49 | }
50 |
51 | [Benchmark]
52 | public void TitleCase_FromSampleText()
53 | {
54 | string text = Minerals.StringCases.StringExtensions.ToTitleCase(SampleText);
55 | }
56 | }
57 | }
--------------------------------------------------------------------------------
/Minerals.StringCases.Benchmarks/StringExtensionsComparison.cs:
--------------------------------------------------------------------------------
1 | using BenchmarkDotNet.Attributes;
2 |
3 | namespace Minerals.StringCases.Benchmarks
4 | {
5 | public class StringExtensionsComparison
6 | {
7 | private const string SampleText = " _ example Variable - - Name 321";
8 |
9 | // Minerals.StringCases (https://www.nuget.org/packages/Minerals.StringCases/)
10 | [Benchmark]
11 | public void PascalCase_Minerals_StringCases()
12 | {
13 | string text = Minerals.StringCases.StringExtensions.ToPascalCase(SampleText);
14 | }
15 |
16 | [Benchmark]
17 | public void CamelCase_Minerals_StringCases()
18 | {
19 | string text = Minerals.StringCases.StringExtensions.ToCamelCase(SampleText);
20 | }
21 |
22 | [Benchmark]
23 | public void KebabCase_Minerals_StringCases()
24 | {
25 | string text = Minerals.StringCases.StringExtensions.ToKebabCase(SampleText);
26 | }
27 |
28 | [Benchmark]
29 | public void SnakeCase_Minerals_StringCases()
30 | {
31 | string text = Minerals.StringCases.StringExtensions.ToSnakeCase(SampleText);
32 | }
33 |
34 | [Benchmark]
35 | public void TrainCase_Minerals_StringCases()
36 | {
37 | string text = Minerals.StringCases.StringExtensions.ToTrainCase(SampleText);
38 | }
39 |
40 | // CaseExtensions (https://www.nuget.org/packages/CaseExtensions/)
41 | [Benchmark]
42 | public void PascalCase_CaseExtensions()
43 | {
44 | string text = CaseExtensions.StringExtensions.ToPascalCase(SampleText);
45 | }
46 |
47 | [Benchmark]
48 | public void CamelCase_CaseExtensions()
49 | {
50 | string text = CaseExtensions.StringExtensions.ToCamelCase(SampleText);
51 | }
52 |
53 | [Benchmark]
54 | public void KebabCase_CaseExtensions()
55 | {
56 | string text = CaseExtensions.StringExtensions.ToKebabCase(SampleText);
57 | }
58 |
59 | [Benchmark]
60 | public void SnakeCase_CaseExtensions()
61 | {
62 | string text = CaseExtensions.StringExtensions.ToSnakeCase(SampleText);
63 | }
64 |
65 | [Benchmark]
66 | public void TrainCase_CaseExtensions()
67 | {
68 | string text = CaseExtensions.StringExtensions.ToTrainCase(SampleText);
69 | }
70 | }
71 | }
--------------------------------------------------------------------------------
/Minerals.StringCases.Tests/Minerals.StringCases.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0;net9.0
5 | enable
6 | 12
7 | enable
8 | false
9 | true
10 | Minerals.StringCases.Tests
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Minerals.StringCases.Tests/StringExtensionsTests.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using FluentAssertions;
3 |
4 | namespace Minerals.StringCases.Tests
5 | {
6 | [TestClass]
7 | public class StringExtensionsTests
8 | {
9 | private const string PascalCase1 = "ExampleVariableName321TestA";
10 | private const string CamelCase1 = "exampleVariableName321TestA";
11 | private const string UnderscoreCamelCase1 = "_exampleVariableName321TestA";
12 | private const string KebabCase1 = "example-variable-name-321-test-a";
13 | private const string SnakeCase1 = "example_variable_name_321_test_a";
14 | private const string MacroCase1 = "EXAMPLE_VARIABLE_NAME_321_TEST_A";
15 | private const string TrainCase1 = "Example-Variable-Name-321-Test-A";
16 | private const string TitleCase1 = "Example Variable Name 321 Test A";
17 | private const string SampleText1 = " _ example Variable - - Name 321 TestA";
18 |
19 | [TestMethod]
20 | public void PascalCase_FromSampleText1()
21 | {
22 | Minerals.StringCases.StringExtensions.ToPascalCase(SampleText1).Should().Be(PascalCase1);
23 | }
24 |
25 | [TestMethod]
26 | public void CamelCase_FromSampleText1()
27 | {
28 | Minerals.StringCases.StringExtensions.ToCamelCase(SampleText1).Should().Be(CamelCase1);
29 | }
30 |
31 | [TestMethod]
32 | public void UnderscoreCamelCase_FromSampleText1()
33 | {
34 | Minerals.StringCases.StringExtensions.ToUnderscoreCamelCase(SampleText1).Should().Be(UnderscoreCamelCase1);
35 | }
36 |
37 | [TestMethod]
38 | public void KebabCase_FromSampleText1()
39 | {
40 | Minerals.StringCases.StringExtensions.ToKebabCase(SampleText1).Should().Be(KebabCase1);
41 | }
42 |
43 | [TestMethod]
44 | public void SnakeCase_FromSampleText1()
45 | {
46 | Minerals.StringCases.StringExtensions.ToSnakeCase(SampleText1).Should().Be(SnakeCase1);
47 | }
48 |
49 | [TestMethod]
50 | public void MacroCase_FromSampleText1()
51 | {
52 | Minerals.StringCases.StringExtensions.ToMacroCase(SampleText1).Should().Be(MacroCase1);
53 | }
54 |
55 | [TestMethod]
56 | public void TrainCase_FromSampleText1()
57 | {
58 | Minerals.StringCases.StringExtensions.ToTrainCase(SampleText1).Should().Be(TrainCase1);
59 | }
60 |
61 | [TestMethod]
62 | public void TitleCase_FromSampleText1()
63 | {
64 | Minerals.StringCases.StringExtensions.ToTitleCase(SampleText1).Should().Be(TitleCase1);
65 | }
66 |
67 | private const string PascalCase2 = "ExampleVariableNameAbCd321";
68 | private const string CamelCase2 = "exampleVariableNameAbCd321";
69 | private const string UnderscoreCamelCase2 = "_exampleVariableNameAbCd321";
70 | private const string KebabCase2 = "example-variable-name-ab-cd-321";
71 | private const string SnakeCase2 = "example_variable_name_ab_cd_321";
72 | private const string MacroCase2 = "EXAMPLE_VARIABLE_NAME_AB_CD_321";
73 | private const string TrainCase2 = "Example-Variable-Name-Ab-Cd-321";
74 | private const string TitleCase2 = "Example Variable Name Ab Cd 321";
75 | private const string SampleText2 = " _ example VARIABLE - - Name AbCd 321";
76 |
77 | [TestMethod]
78 | public void PascalCase_FromSampleText2()
79 | {
80 | Minerals.StringCases.StringExtensions.ToPascalCase(SampleText2).Should().Be(PascalCase2);
81 | }
82 |
83 | [TestMethod]
84 | public void CamelCase_FromSampleText2()
85 | {
86 | Minerals.StringCases.StringExtensions.ToCamelCase(SampleText2).Should().Be(CamelCase2);
87 | }
88 |
89 | [TestMethod]
90 | public void UnderscoreCamelCase_FromSampleText2()
91 | {
92 | Minerals.StringCases.StringExtensions.ToUnderscoreCamelCase(SampleText2).Should().Be(UnderscoreCamelCase2);
93 | }
94 |
95 | [TestMethod]
96 | public void KebabCase_FromSampleText2()
97 | {
98 | Minerals.StringCases.StringExtensions.ToKebabCase(SampleText2).Should().Be(KebabCase2);
99 | }
100 |
101 | [TestMethod]
102 | public void SnakeCase_FromSampleText2()
103 | {
104 | Minerals.StringCases.StringExtensions.ToSnakeCase(SampleText2).Should().Be(SnakeCase2);
105 | }
106 |
107 | [TestMethod]
108 | public void MacroCase_FromSampleText2()
109 | {
110 | Minerals.StringCases.StringExtensions.ToMacroCase(SampleText2).Should().Be(MacroCase2);
111 | }
112 |
113 | [TestMethod]
114 | public void TrainCase_FromSampleText2()
115 | {
116 | Minerals.StringCases.StringExtensions.ToTrainCase(SampleText2).Should().Be(TrainCase2);
117 | }
118 |
119 | [TestMethod]
120 | public void TitleCase_FromSampleText2()
121 | {
122 | Minerals.StringCases.StringExtensions.ToTitleCase(SampleText2).Should().Be(TitleCase2);
123 | }
124 | }
125 | }
--------------------------------------------------------------------------------
/Minerals.StringCases.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.5.002.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Minerals.StringCases", "Minerals.StringCases\Minerals.StringCases.csproj", "{C6B72EAD-216F-4D8E-BD33-2CF63F1E7A80}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Minerals.StringCases.Benchmarks", "Minerals.StringCases.Benchmarks\Minerals.StringCases.Benchmarks.csproj", "{D34BBC31-455F-462F-9D99-8B39C350507B}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Minerals.StringCases.Tests", "Minerals.StringCases.Tests\Minerals.StringCases.Tests.csproj", "{8CAE5104-4050-4AB3-A346-15649C1C8AE7}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {C6B72EAD-216F-4D8E-BD33-2CF63F1E7A80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {C6B72EAD-216F-4D8E-BD33-2CF63F1E7A80}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {C6B72EAD-216F-4D8E-BD33-2CF63F1E7A80}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {C6B72EAD-216F-4D8E-BD33-2CF63F1E7A80}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {D34BBC31-455F-462F-9D99-8B39C350507B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {D34BBC31-455F-462F-9D99-8B39C350507B}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {D34BBC31-455F-462F-9D99-8B39C350507B}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {D34BBC31-455F-462F-9D99-8B39C350507B}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {8CAE5104-4050-4AB3-A346-15649C1C8AE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {8CAE5104-4050-4AB3-A346-15649C1C8AE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {8CAE5104-4050-4AB3-A346-15649C1C8AE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {8CAE5104-4050-4AB3-A346-15649C1C8AE7}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | GlobalSection(ExtensibilityGlobals) = postSolution
35 | SolutionGuid = {1AB7D6D9-404D-4FC4-9DB5-468AAF3DC8E8}
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/Minerals.StringCases/Minerals.StringCases.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0;net9.0;netstandard2.0
5 | enable
6 | 12
7 | enable
8 | true
9 | Minerals.StringCases
10 |
11 |
12 |
13 | 0.2.2
14 | StringCases
15 | Szymon Hałucha
16 | StringCases
17 | Optimized NuGet package with minimum memory allocation designed to help you convert strings to name cases such as Pascal, Camel, Kebab, Snake, Macro, Train and Title
18 | Copyright © Szymon Hałucha 2025
19 |
20 |
21 |
22 | Minerals.StringCases
23 | MIT
24 | https://github.com/SzymonHalucha/Minerals.StringCases
25 | string, extension, transformation, pascal, camel, kebab, snake, macro, train, title, case
26 | README.md
27 | Updated dependencies
28 |
29 |
30 |
31 | https://github.com/SzymonHalucha/Minerals.StringCases.git
32 | true
33 | v$(Version)
34 | git
35 |
36 |
37 |
38 | true
39 |
40 |
41 |
42 | true
43 | true
44 | true
45 | true
46 | true
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/Minerals.StringCases/README.md:
--------------------------------------------------------------------------------
1 | # Minerals.StringCases
2 |
3 | Optimized NuGet package with minimum memory allocation designed to help you convert strings to names cases such as Pascal, Camel, Kebab, Snake, Macro, Train and Title.
4 |
5 | ## Features
6 |
7 | - **Wide choice of cases:** PascalCase, camelCase, _underscoreCamelCase, kebab-case, snake_case, MACRO_CASE, Train-Case, Title Case.
8 | - **Performance:** The package is optimized for speed and memory allocation.
9 | - **Universal:** Convert from any freely formatted string.
10 | - **Compatible with .NET Standard 2.0:** Works on a wide range of platforms and development environments.
11 |
12 | ## Installation
13 |
14 | Add the Minerals.StringCases nuget package to your C# project using the following methods:
15 |
16 | ### 1. Project file definition
17 |
18 | ```xml
19 |
20 | ```
21 |
22 | ### 2. dotnet command
23 |
24 | ```bat
25 | dotnet add package Minerals.StringCases
26 | ```
27 |
28 | ## Usage
29 |
30 | ```csharp
31 | using Minerals.StringCases;
32 |
33 | string sampleText = " _ example Variable - - Name 321";
34 |
35 | string pascalCase = sampleText.ToPascalCase();
36 | // ExampleVariableName321
37 |
38 | string camelCase = sampleText.ToCamelCase();
39 | // exampleVariableName321
40 |
41 | string underscoreCamelCase = sampleText.ToUnderscoreCamelCase();
42 | // _exampleVariableName321
43 |
44 | string kebabCase = sampleText.ToKebabCase();
45 | // example-variable-name-321
46 |
47 | string snakeCase = sampleText.ToSnakeCase();
48 | // example_variable_name_321
49 |
50 | string macroCase = sampleText.ToMacroCase();
51 | // EXAMPLE_VARIABLE_NAME_321
52 |
53 | string trainCase = sampleText.ToTrainCase();
54 | // Example-Variable-Name-321
55 |
56 | string titleCase = sampleText.ToTitleCase();
57 | // Example Variable Name 321
58 | ```
59 |
60 | ## Performance and comparison
61 |
62 | Here is a comparison of the speed and amount of memory allocation with the most popular NuGet package similar to [Minerals.StringCases](https://www.nuget.org/packages/Minerals.StringCases/) version 0.2.0 - [CaseExtesions](https://www.nuget.org/packages/CaseExtensions/) version 1.1.0.
63 |
64 | String used to perform the comparison:
65 |
66 | ```csharp
67 | string sampleText = " _ example Variable - - Name 321";
68 | ```
69 |
70 | ### Results
71 |
72 | ```log
73 | BenchmarkDotNet v0.13.12, Windows 10 (10.0.19045.4412/22H2/2022Update)
74 | AMD Ryzen 5 2600, 1 CPU, 12 logical and 6 physical cores
75 | .NET SDK 8.0.301
76 | [Host] : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX2
77 | Job-KUHBVV : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX2
78 |
79 | Runtime=.NET 8.0
80 | ```
81 |
82 | | Method | Mean | Error | StdDev | Gen0 | Allocated |
83 | |---------------------------------|---------:|--------:|--------:|-------:|----------:|
84 | | PascalCase_Minerals_StringCases | 158.4 ns | 0.95 ns | 0.79 ns | 0.0343 | 144 B |
85 | | CamelCase_Minerals_StringCases | 167.4 ns | 1.94 ns | 1.72 ns | 0.0343 | 144 B |
86 | | SnakeCase_Minerals_StringCases | 182.4 ns | 0.71 ns | 0.63 ns | 0.0362 | 152 B |
87 | | KebabCase_Minerals_StringCases | 196.0 ns | 1.75 ns | 1.55 ns | 0.0362 | 152 B |
88 | | TrainCase_Minerals_StringCases | 206.1 ns | 2.62 ns | 2.46 ns | 0.0362 | 152 B |
89 | | - | - | - | - | - | - |
90 | | PascalCase_CaseExtensions | 505.9 ns | 1.83 ns | 1.71 ns | 0.0973 | 408 B |
91 | | KebabCase_CaseExtensions | 506.1 ns | 1.68 ns | 1.49 ns | 0.0992 | 416 B |
92 | | CamelCase_CaseExtensions | 520.6 ns | 4.91 ns | 4.59 ns | 0.0973 | 408 B |
93 | | SnakeCase_CaseExtensions | 525.1 ns | 3.05 ns | 2.55 ns | 0.0992 | 416 B |
94 | | TrainCase_CaseExtensions | 527.3 ns | 2.47 ns | 2.06 ns | 0.0992 | 416 B |
95 |
96 | ## Versioning
97 |
98 | We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [branches on this repository](https://github.com/SzymonHalucha/Minerals.StringCases/branches).
99 |
100 | ## Authors
101 |
102 | - **Szymon Hałucha** - Maintainer
103 |
104 | See also the list of [contributors](https://github.com/SzymonHalucha/Minerals.StringCases/contributors) who participated in this project.
105 |
106 | ## License
107 |
108 | This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
109 |
--------------------------------------------------------------------------------
/Minerals.StringCases/StringExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 | using System.Globalization;
3 |
4 | namespace Minerals.StringCases
5 | {
6 | public static class StringExtensions
7 | {
8 | public static string ToPascalCase(this string value)
9 | {
10 | int newIndex = 0;
11 | bool insertSeparator = true;
12 | UnicodeCategory previous;
13 | UnicodeCategory current = UnicodeCategory.OtherSymbol;
14 | char[] newString = new char[value.Length + CalculateSpanSizeForPascalOrCamelCase(value)];
15 | for (int i = 0; i < value.Length; i++)
16 | {
17 | previous = current;
18 | current = char.GetUnicodeCategory(value[i]);
19 | insertSeparator = (previous != current && (current is UnicodeCategory.UppercaseLetter || current is UnicodeCategory.DecimalDigitNumber)) || insertSeparator;
20 | if (!IsSpecialCharacter(current))
21 | {
22 | newString[newIndex] = insertSeparator
23 | ? char.ToUpperInvariant(value[i])
24 | : char.ToLowerInvariant(value[i]);
25 | insertSeparator = false;
26 | newIndex++;
27 | }
28 | }
29 | return new(newString);
30 | }
31 |
32 | public static string ToCamelCase(this string value)
33 | {
34 | int newIndex = 0;
35 | bool insertSeparator = false;
36 | bool isFirstCharacter = true;
37 | UnicodeCategory previous;
38 | UnicodeCategory current = UnicodeCategory.OtherSymbol;
39 | char[] newString = new char[value.Length + CalculateSpanSizeForPascalOrCamelCase(value)];
40 | for (int i = 0; i < value.Length; i++)
41 | {
42 | previous = current;
43 | current = char.GetUnicodeCategory(value[i]);
44 | insertSeparator = (previous != current && (current is UnicodeCategory.UppercaseLetter || current is UnicodeCategory.DecimalDigitNumber)) || insertSeparator;
45 | if (!IsSpecialCharacter(current))
46 | {
47 | newString[newIndex] = insertSeparator && !isFirstCharacter
48 | ? char.ToUpperInvariant(value[i])
49 | : char.ToLowerInvariant(value[i]);
50 | isFirstCharacter = false;
51 | insertSeparator = false;
52 | newIndex++;
53 | }
54 | }
55 | return new(newString);
56 | }
57 |
58 | public static string ToUnderscoreCamelCase(this string value)
59 | {
60 | int newIndex = 1;
61 | bool insertSeparator = false;
62 | bool isFirstCharacter = true;
63 | UnicodeCategory previous;
64 | UnicodeCategory current = UnicodeCategory.OtherSymbol;
65 | char[] newString = new char[value.Length + CalculateSpanSizeForPascalOrCamelCase(value) + 1];
66 | newString[0] = '_';
67 | for (int i = 1; i < value.Length; i++)
68 | {
69 | previous = current;
70 | current = char.GetUnicodeCategory(value[i]);
71 | insertSeparator = (previous != current && (current is UnicodeCategory.UppercaseLetter || current is UnicodeCategory.DecimalDigitNumber)) || insertSeparator;
72 | if (!IsSpecialCharacter(current))
73 | {
74 | newString[newIndex] = insertSeparator && !isFirstCharacter
75 | ? char.ToUpperInvariant(value[i])
76 | : char.ToLowerInvariant(value[i]);
77 | isFirstCharacter = false;
78 | insertSeparator = false;
79 | newIndex++;
80 | }
81 | }
82 | return new(newString);
83 | }
84 |
85 | public static string ToKebabCase(this string value)
86 | {
87 | int newIndex = 0;
88 | bool insertSeparator = true;
89 | bool isFirstCharacter = true;
90 | UnicodeCategory previous;
91 | UnicodeCategory current = UnicodeCategory.OtherSymbol;
92 | char[] newString = new char[value.Length + CalculateSpanSizeForKebabOrSnakeCase(value)];
93 | for (int i = 0; i < value.Length; i++)
94 | {
95 | previous = current;
96 | current = char.GetUnicodeCategory(value[i]);
97 | insertSeparator = (previous != current && (current is UnicodeCategory.UppercaseLetter || current is UnicodeCategory.DecimalDigitNumber)) || insertSeparator;
98 | if (!IsSpecialCharacter(current))
99 | {
100 | if (insertSeparator && !isFirstCharacter)
101 | {
102 | newString[newIndex] = '-';
103 | newIndex++;
104 | }
105 | newString[newIndex] = char.ToLowerInvariant(value[i]);
106 | isFirstCharacter = false;
107 | insertSeparator = false;
108 | newIndex++;
109 | }
110 | }
111 | return new(newString);
112 | }
113 |
114 | public static string ToSnakeCase(this string value)
115 | {
116 | int newIndex = 0;
117 | bool insertSeparator = true;
118 | bool isFirstCharacter = true;
119 | UnicodeCategory previous;
120 | UnicodeCategory current = UnicodeCategory.OtherSymbol;
121 | char[] newString = new char[value.Length + CalculateSpanSizeForKebabOrSnakeCase(value)];
122 | for (int i = 0; i < value.Length; i++)
123 | {
124 | previous = current;
125 | current = char.GetUnicodeCategory(value[i]);
126 | insertSeparator = (previous != current && (current is UnicodeCategory.UppercaseLetter || current is UnicodeCategory.DecimalDigitNumber)) || insertSeparator;
127 | if (!IsSpecialCharacter(current))
128 | {
129 | if (insertSeparator && !isFirstCharacter)
130 | {
131 | newString[newIndex] = '_';
132 | newIndex++;
133 | }
134 | newString[newIndex] = char.ToLowerInvariant(value[i]);
135 | isFirstCharacter = false;
136 | insertSeparator = false;
137 | newIndex++;
138 | }
139 | }
140 | return new(newString);
141 | }
142 |
143 | public static string ToMacroCase(this string value)
144 | {
145 | int newIndex = 0;
146 | bool insertSeparator = true;
147 | bool isFirstCharacter = true;
148 | UnicodeCategory previous;
149 | UnicodeCategory current = UnicodeCategory.OtherSymbol;
150 | char[] newString = new char[value.Length + CalculateSpanSizeForKebabOrSnakeCase(value)];
151 | for (int i = 0; i < value.Length; i++)
152 | {
153 | previous = current;
154 | current = char.GetUnicodeCategory(value[i]);
155 | insertSeparator = (previous != current && (current is UnicodeCategory.UppercaseLetter || current is UnicodeCategory.DecimalDigitNumber)) || insertSeparator;
156 | if (!IsSpecialCharacter(current))
157 | {
158 | if (insertSeparator && !isFirstCharacter)
159 | {
160 | newString[newIndex] = '_';
161 | newIndex++;
162 | }
163 | newString[newIndex] = char.ToUpperInvariant(value[i]);
164 | isFirstCharacter = false;
165 | insertSeparator = false;
166 | newIndex++;
167 | }
168 | }
169 | return new(newString);
170 | }
171 |
172 | public static string ToTrainCase(this string value)
173 | {
174 | int newIndex = 0;
175 | bool insertSeparator = true;
176 | bool isFirstCharacter = true;
177 | UnicodeCategory previous;
178 | UnicodeCategory current = UnicodeCategory.OtherSymbol;
179 | char[] newString = new char[value.Length + CalculateSpanSizeForKebabOrSnakeCase(value)];
180 | for (int i = 0; i < value.Length; i++)
181 | {
182 | previous = current;
183 | current = char.GetUnicodeCategory(value[i]);
184 | insertSeparator = (previous != current && (current is UnicodeCategory.UppercaseLetter || current is UnicodeCategory.DecimalDigitNumber)) || insertSeparator;
185 | if (!IsSpecialCharacter(current))
186 | {
187 | if (insertSeparator && !isFirstCharacter)
188 | {
189 | newString[newIndex] = '-';
190 | newIndex++;
191 | }
192 | newString[newIndex] = insertSeparator
193 | ? char.ToUpperInvariant(value[i])
194 | : char.ToLowerInvariant(value[i]);
195 | isFirstCharacter = false;
196 | insertSeparator = false;
197 | newIndex++;
198 | }
199 | }
200 | return new(newString);
201 | }
202 |
203 | public static string ToTitleCase(this string value)
204 | {
205 | int newIndex = 0;
206 | bool insertSeparator = true;
207 | bool isFirstCharacter = true;
208 | UnicodeCategory previous;
209 | UnicodeCategory current = UnicodeCategory.OtherSymbol;
210 | char[] newString = new char[value.Length + CalculateSpanSizeForKebabOrSnakeCase(value)];
211 | for (int i = 0; i < value.Length; i++)
212 | {
213 | previous = current;
214 | current = char.GetUnicodeCategory(value[i]);
215 | insertSeparator = (previous != current && (current is UnicodeCategory.UppercaseLetter || current is UnicodeCategory.DecimalDigitNumber)) || insertSeparator;
216 | if (!IsSpecialCharacter(current))
217 | {
218 | if (insertSeparator && !isFirstCharacter)
219 | {
220 | newString[newIndex] = ' ';
221 | newIndex++;
222 | }
223 | newString[newIndex] = insertSeparator
224 | ? char.ToUpperInvariant(value[i])
225 | : char.ToLowerInvariant(value[i]);
226 | isFirstCharacter = false;
227 | insertSeparator = false;
228 | newIndex++;
229 | }
230 | }
231 | return new(newString);
232 | }
233 |
234 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
235 | private static int CalculateSpanSizeForKebabOrSnakeCase(string text)
236 | {
237 | UnicodeCategory previous = char.GetUnicodeCategory(text[0]);
238 | UnicodeCategory current;
239 | int skips = IsSpecialCharacter(previous) ? 1 : 0;
240 | int divs = 0;
241 | for (int i = 1; i < text.Length; i++)
242 | {
243 | current = char.GetUnicodeCategory(text[i]);
244 | skips += IsSpecialCharacter(current) ? 1 : 0;
245 | divs += previous != current && (current is UnicodeCategory.UppercaseLetter || current is UnicodeCategory.DecimalDigitNumber) ? 1 : 0;
246 | previous = current;
247 | }
248 | return divs - skips;
249 | }
250 |
251 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
252 | private static int CalculateSpanSizeForPascalOrCamelCase(string text)
253 | {
254 | UnicodeCategory current;
255 | int skips = 0;
256 | for (int i = 0; i < text.Length - 1; i++)
257 | {
258 | current = char.GetUnicodeCategory(text[i]);
259 | skips -= IsSpecialCharacter(current) ? 1 : 0;
260 | }
261 | return skips;
262 | }
263 |
264 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
265 | private static bool IsSpecialCharacter(UnicodeCategory category)
266 | {
267 | return category is not UnicodeCategory.UppercaseLetter
268 | and not UnicodeCategory.LowercaseLetter
269 | and not UnicodeCategory.DecimalDigitNumber;
270 | }
271 | }
272 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Minerals.StringCases
2 |
3 | 
4 | 
5 | 
6 |
7 | [Package on nuget.org](https://www.nuget.org/packages/Minerals.StringCases/)
8 |
9 | Optimized NuGet package with minimum memory allocation designed to help you convert strings to names cases such as Pascal, Camel, Kebab, Snake, Macro, Train and Title.
10 |
11 | ## Features
12 |
13 | - **Wide choice of cases:** PascalCase, camelCase, _underscoreCamelCase, kebab-case, snake_case, MACRO_CASE, Train-Case, Title Case.
14 | - **Performance:** The package is optimized for speed and memory allocation.
15 | - **Universal:** Convert from any freely formatted string.
16 | - **Compatible with .NET Standard 2.0:** Works on a wide range of platforms and development environments.
17 |
18 | ## Installation
19 |
20 | Add the Minerals.StringCases nuget package to your C# project using the following methods:
21 |
22 | ### 1. Project file definition
23 |
24 | ```xml
25 |
26 | ```
27 |
28 | ### 2. dotnet command
29 |
30 | ```bat
31 | dotnet add package Minerals.StringCases
32 | ```
33 |
34 | ## Usage
35 |
36 | ```csharp
37 | using Minerals.StringCases;
38 |
39 | string sampleText = " _ example Variable - - Name 321";
40 |
41 | string pascalCase = sampleText.ToPascalCase();
42 | // ExampleVariableName321
43 |
44 | string camelCase = sampleText.ToCamelCase();
45 | // exampleVariableName321
46 |
47 | string underscoreCamelCase = sampleText.ToUnderscoreCamelCase();
48 | // _exampleVariableName321
49 |
50 | string kebabCase = sampleText.ToKebabCase();
51 | // example-variable-name-321
52 |
53 | string snakeCase = sampleText.ToSnakeCase();
54 | // example_variable_name_321
55 |
56 | string macroCase = sampleText.ToMacroCase();
57 | // EXAMPLE_VARIABLE_NAME_321
58 |
59 | string trainCase = sampleText.ToTrainCase();
60 | // Example-Variable-Name-321
61 |
62 | string titleCase = sampleText.ToTitleCase();
63 | // Example Variable Name 321
64 | ```
65 |
66 | ## Performance and comparison
67 |
68 | Here is a comparison of the speed and amount of memory allocation with the most popular NuGet package similar to [Minerals.StringCases](https://www.nuget.org/packages/Minerals.StringCases/) version 0.2.0 - [CaseExtesions](https://www.nuget.org/packages/CaseExtensions/) version 1.1.0.
69 |
70 | String used to perform the comparison:
71 |
72 | ```csharp
73 | string sampleText = " _ example Variable - - Name 321";
74 | ```
75 |
76 | ### Results
77 |
78 | ```log
79 | BenchmarkDotNet v0.13.12, Windows 10 (10.0.19045.4412/22H2/2022Update)
80 | AMD Ryzen 5 2600, 1 CPU, 12 logical and 6 physical cores
81 | .NET SDK 8.0.301
82 | [Host] : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX2
83 | Job-KUHBVV : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX2
84 |
85 | Runtime=.NET 8.0
86 | ```
87 |
88 | | Method | Mean | Error | StdDev | Gen0 | Allocated |
89 | |---------------------------------|---------:|--------:|--------:|-------:|----------:|
90 | | PascalCase_Minerals_StringCases | 158.4 ns | 0.95 ns | 0.79 ns | 0.0343 | 144 B |
91 | | CamelCase_Minerals_StringCases | 167.4 ns | 1.94 ns | 1.72 ns | 0.0343 | 144 B |
92 | | SnakeCase_Minerals_StringCases | 182.4 ns | 0.71 ns | 0.63 ns | 0.0362 | 152 B |
93 | | KebabCase_Minerals_StringCases | 196.0 ns | 1.75 ns | 1.55 ns | 0.0362 | 152 B |
94 | | TrainCase_Minerals_StringCases | 206.1 ns | 2.62 ns | 2.46 ns | 0.0362 | 152 B |
95 | | - | - | - | - | - | - |
96 | | PascalCase_CaseExtensions | 505.9 ns | 1.83 ns | 1.71 ns | 0.0973 | 408 B |
97 | | KebabCase_CaseExtensions | 506.1 ns | 1.68 ns | 1.49 ns | 0.0992 | 416 B |
98 | | CamelCase_CaseExtensions | 520.6 ns | 4.91 ns | 4.59 ns | 0.0973 | 408 B |
99 | | SnakeCase_CaseExtensions | 525.1 ns | 3.05 ns | 2.55 ns | 0.0992 | 416 B |
100 | | TrainCase_CaseExtensions | 527.3 ns | 2.47 ns | 2.06 ns | 0.0992 | 416 B |
101 |
102 | ## Versioning
103 |
104 | We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [branches on this repository](https://github.com/SzymonHalucha/Minerals.StringCases/branches).
105 |
106 | ## Authors
107 |
108 | - **Szymon Hałucha** - Maintainer
109 |
110 | See also the list of [contributors](https://github.com/SzymonHalucha/Minerals.StringCases/contributors) who participated in this project.
111 |
112 | ## License
113 |
114 | This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
115 |
--------------------------------------------------------------------------------