-
Notifications
You must be signed in to change notification settings - Fork 734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bring back all the pluralization #1879
Merged
calvincestari
merged 6 commits into
release/1.0-alpha-incubating
from
bring-back-all-the-pluralization
Jul 21, 2021
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2cefd14
Revert "Remove inflection option, pluralizer and dependency"
calvincestari ce12238
Move from InflectorKit fork to origin with 1.0.0 minimum
calvincestari 1e14337
Update to comply with InflectorKit 1.0.0 deprecations
calvincestari 4bdc3b5
Enable code generation options to accept additional inflection rules
calvincestari c7f720f
Update PluralizerTest function names to match #1849
calvincestari d6413e2
Shuffle parameter documentation order to match parameter input order
calvincestari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 9 additions & 0 deletions
9
Apollo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Foundation | ||
import InflectorKit | ||
|
||
/// The types of inflection rules that can be used to customize pluralization. | ||
public enum InflectionRule { | ||
|
||
/// A pluralization rule that allows taking a singular word and pluralizing it. | ||
/// - singularRegex: A regular expression representing the single version of the word | ||
/// - replacementRegex: A regular expression representing how to replace the singular version. | ||
case pluralization(singularRegex: String, replacementRegex: String) | ||
|
||
/// A singularization rule that allows taking a plural word and singularizing it. | ||
/// - pluralRegex: A regular expression represeinting the plural version of the word | ||
/// - replacementRegex: A regular expression representing how to replace the singular version | ||
case singularization(pluralRegex: String, replacementRegex: String) | ||
|
||
/// A definition of an irregular pluralization rule not easily captured by regex - for example "person" and "people". | ||
/// - singular: The singular version of the word | ||
/// - plural: The plural version of the word. | ||
case irregular(singular: String, plural: String) | ||
|
||
/// A definition of a word that should never be pluralized or de-pluralized because it's the same no matter what the count - for example, "fish". | ||
/// - word: The word that should never be adjusted. | ||
case uncountable(word: String) | ||
} | ||
|
||
struct Pluralizer { | ||
|
||
private let inflector: StringInflector | ||
|
||
init(rules: [InflectionRule] = []) { | ||
let inflector = StringInflector.default | ||
for rule in rules { | ||
switch rule { | ||
case .pluralization(let pluralRegex, let replacementRegex): | ||
inflector.addPluralRule(pluralRegex, replacement: replacementRegex) | ||
case .singularization(let singularRegex, let replacementRegex): | ||
inflector.addSingularRule(singularRegex, replacement: replacementRegex) | ||
case .irregular(let singular, let plural): | ||
inflector.addIrregular(singular: singular, plural: plural) | ||
case .uncountable(let word): | ||
inflector.addUncountable(word) | ||
} | ||
} | ||
|
||
self.inflector = inflector | ||
} | ||
|
||
func singularize(_ string: String) -> String { | ||
self.inflector.singularize(string) | ||
} | ||
|
||
func pluralize(_ string: String) -> String { | ||
self.inflector.pluralize(string) | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine for now. I think when we release the swift codegen, we will need to keep support for legacy codegen for a while, but that it should probably have its own set of options entirely so we can diverge more easily. But that's not a concern for today.