Skip to content

Commit

Permalink
Treat mixed-case constants special.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhx committed Jan 19, 2024
1 parent f6d0cb1 commit fc223da
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions Sources/libgir2swift/utilities/String+Substring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,20 @@ public extension StringProtocol {

/// Converts *snake_CASE* to *camelCase*
@inlinable var snakeCASE2camelCase: String {
split(separator: "_").map {
$0.count > 1 && $0 == $0.uppercased() ? $0.lowercased() : String($0)
}.joined(separator: "_").cameliseConstant { $0 == "_" }
let idiomaticName: String
if count == 1 {
idiomaticName = lowercased()
} else if self == uppercased() {
idiomaticName = split(separator: "_").map {
$0.count > 1 ? $0.lowercased() : String($0)
}.joined(separator: "_").cameliseConstant { $0 == "_" }
} else {
idiomaticName = split(separator: "_").enumerated().map {
$0.offset == 0 && $0.element.count > 1 && $0.element == $0.element.uppercased() ?
$0.element.lowercased() : String($0.element)
}.joined()
}
return idiomaticName
}

/// Convers combination of *snake_case* and *kebab-case* to *camelCase*
Expand Down

0 comments on commit fc223da

Please sign in to comment.