-
Notifications
You must be signed in to change notification settings - Fork 58
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
Identifiers starting with numbers when combining swiftIdentifier
and snakeToCamelCase
#30
Comments
This is a duplicate of SwiftGen/SwiftGen#289. While it is the right place for this issue, most of the discussion already happened there. |
I'm reopening this, as it's still not fixed, and we should discuss what the best solution would be. |
swiftIdentifier
and snakeToCamelCase
Given an input of "25 Ultra Light" and depending on the order, we get:
|
Should we just use the 2nd case (don't strip leading underscores)? Or modify the function to accept an enum:
I think we'll probably use the |
From a logical standpoint, I think we should apply What I don't understand is why, once transformed |
Side note: we should add some examples containing spaces in that filter's documentation to make it clear of its behaviour with spaces. I think that's actually the core of the issue (and imho |
Not sure about that though, we'd lose information if the name was "25 ultra light". |
And, |
How so? |
snakeCaseToCamelCase only thinks in terms of underscores, it doesn't (and shouldn't) care about other characters. if try containsAnyLowercasedChar(string) {
let comps = string.components(separatedBy: "_")
unprefixed = comps.map { titlecase($0) }.joined(separator: "")
} |
Currently, the code does this which doesn't take spaces into account. So |
Ok, so let's apply |
Well, that's why we have Maybe we should |
I woulnd't go with the replace filter, it's too limited for future swift changes. What do we do with other invalid characters? |
No, Let's take more convoluted examples to look at what could be logically right What about "12 @ 34 % 56 + 78 Hello world", I think we want to get "_12_34_56_78_Hello_world" as a result? Because spaces should not be turned to underscores by snakeToCameCalse? Or maybe we would prefer "_12___34___56___78_Hello_world"? Or would we want "12 @ 34 % 56 + 78 Hello world" to result to "_12345678HelloWorld" ? Or to "_12_34_56_78HelloWorld" (but what would be the rule of removing underscores generated from invalid chars vs one from spaces vs ones that would avoid numbers next to each others be glued together?) |
Right, no idea what's the ideal solution. personally as a end result I'd expect "_25UltraLight". For those other examples, not a clue. Template writer shouldn't have to worry about all these edge cases, I'm starting to think the Edit: such a filter could even accept an (optional) swift version. |
It's definitely not the role of Maybe the rule should be: (1) replace " [a-z]" (space followed by lowercase letter) with "[A-Z]" (remove space and uppercase first letter), then just apply the current version of
So in practice, it could make sense to make |
item 1: we also have a Should that convenience filter also apply the We could add this as a variation of the |
The more I think about it, the more I think making the Making that parameter a string describing the "mode" (e.g. The first variant that we'd want to implement will probably be equivalent to the current NB: In any case, I don't think it would be the job of the |
Generated output example:
...enum UniversLTStd: String, FontConvertible {
case 65Bold = "UniversLTStd-Bold"
case 67BoldCondensed = "UniversLTStd-BoldCn"
case 57Condensed = "UniversLTStd-Cn"
case 47LightCondensed = "UniversLTStd-LightCn"
case 47LightCondensedOblique = "UniversLTStd-LightCnObl"
case 59UltraCondensed = "UniversLTStd-UltraCn"
}...
The text was updated successfully, but these errors were encountered: