-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add string to pascal case extension (#643)
PR: #643
- Loading branch information
1 parent
510c0ae
commit 6b4a5a8
Showing
2 changed files
with
23 additions
and
1 deletion.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
generator/openapi/src/main/kotlin/com/expediagroup/sdk/generators/openapi/Extensions.kt
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,22 @@ | ||
package com.expediagroup.sdk.generators.openapi | ||
|
||
/** | ||
* This extension function converts a string to PascalCase. | ||
* PascalCase is a type of identifier that consists of compound words or phrases such that each word or abbreviation begins with a capital letter. | ||
* Non-alphabetic characters are ignored, and the next alphabetic character after them is capitalized. | ||
* | ||
* @receiver String The string to be converted to PascalCase. | ||
* @return String The string converted to PascalCase. | ||
*/ | ||
fun String.pascalCase(): String { | ||
var capitalizeNext = true | ||
val builder = StringBuilder() | ||
forEach { char -> | ||
when { | ||
char.isLetterOrDigit().and(capitalizeNext) -> builder.append(char.uppercaseChar()) | ||
char.isLetterOrDigit() -> builder.append(char) | ||
} | ||
capitalizeNext = char.isLetter().not().or(builder.isEmpty()) | ||
} | ||
return builder.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