Skip to content

Commit

Permalink
feature: update the implementation of CapitalizationRule to be more f…
Browse files Browse the repository at this point in the history
…lexible
  • Loading branch information
tonyarnold committed Aug 25, 2024
1 parent 8272e9f commit 0cda6f0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase {
),
options: .init(
additionalCapitalizationRules: [
.uppercase(regex: "[Ii]d")
CapitalizationRule(term: .regex("[Ii]d"), strategy: .upper)
],
additionalInflectionRules: [
.pluralization(singularRegex: "animal", replacementRegex: "animals")
Expand Down Expand Up @@ -105,8 +105,11 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase {
"options" : {
"additionalCapitalizationRules" : [
{
"uppercase" : {
"regex" : "[Ii]d"
"strategy" : "upper",
"term" : {
"regex" : {
"_0" : "[Ii]d"
}
}
}
],
Expand Down
26 changes: 20 additions & 6 deletions apollo-ios-codegen/Sources/ApolloCodegenLib/Capitalizer.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import Foundation

public enum CapitalizationRule: Codable, Equatable {
case uppercase(regex: String)
case lowercase(regex: String)
case titlecase(regex: String)
case camelcase(regex: String)
case pascalcase(regex: String)
public struct CapitalizationRule: Codable, Equatable, Sendable {
public enum Term: Codable, Equatable, Sendable {
case string(String)
case regex(String)
}

public enum CaseStrategy: String, Codable, Equatable, Sendable {
case upper
case lower
case camel
case pascal
}

public let term: Term
public let strategy: CaseStrategy

public init(term: Term, strategy: CaseStrategy) {
self.term = term
self.strategy = strategy
}
}

0 comments on commit 0cda6f0

Please sign in to comment.