-
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cheng-wei
committed
Nov 27, 2019
1 parent
eff636e
commit 7214646
Showing
6 changed files
with
73 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/GUI/ReverseEngineer20/ReverseEngineer/StringExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Text; | ||
|
||
namespace ReverseEngineer20.ReverseEngineer | ||
{ | ||
public static class StringExtension | ||
{ | ||
public static string ToPascalCase(this string value) | ||
{ | ||
var candidateStringBuilder = new StringBuilder(); | ||
var previousLetterCharInWordIsLowerCase = false; | ||
var isFirstCharacterInWord = true; | ||
|
||
foreach (var c in value) | ||
{ | ||
var isNotLetterOrDigit = !char.IsLetterOrDigit(c); | ||
if (isNotLetterOrDigit | ||
|| (previousLetterCharInWordIsLowerCase && char.IsUpper(c))) | ||
{ | ||
isFirstCharacterInWord = true; | ||
previousLetterCharInWordIsLowerCase = false; | ||
if (isNotLetterOrDigit) | ||
{ | ||
continue; | ||
} | ||
} | ||
|
||
candidateStringBuilder.Append( | ||
isFirstCharacterInWord ? char.ToUpperInvariant(c) : char.ToLowerInvariant(c)); | ||
isFirstCharacterInWord = false; | ||
if (char.IsLower(c)) | ||
{ | ||
previousLetterCharInWordIsLowerCase = true; | ||
} | ||
} | ||
|
||
return candidateStringBuilder.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters