-
Notifications
You must be signed in to change notification settings - Fork 84
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
enhance splitIdentifierByCaseAndSeparators to support non-case-sensitive languages #170
enhance splitIdentifierByCaseAndSeparators to support non-case-sensitive languages #170
Conversation
51f3da2
to
dd06caa
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #170 +/- ##
==========================================
+ Coverage 75.89% 76.51% +0.61%
==========================================
Files 24 24
Lines 1871 1882 +11
==========================================
+ Hits 1420 1440 +20
+ Misses 361 353 -8
+ Partials 90 89 -1 ☔ View full report in Codecov by Sentry. |
dd06caa
to
7a55cec
Compare
…ive languages - Refactored the function to accurately handle languages without case distinction (e.g., Korean, Chinese) while maintaining functionality for case-sensitive languages. - Implemented rune-based string processing for better multi-language support. - Preserved original logic for case distinction where applicable.
7a55cec
to
2975b1b
Compare
hi @zrma , thanks a lot for the contribution! I will try to take a look at it over the xmas/nye holidays and hopefully merge it! 🙏 |
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.
Hi, thanks again for the contribution and for the patience in waiting for the review! 🙏
The code looks good to me: if you could just push those little naming fixes I added to the PR I can then merge it! 🥂
Unfortunately I have no knowledge of non-case-sensitive languages, but if any user who does will find any bug we could fix it when the need arises. ✌️
internal/x/text/cases.go
Outdated
@@ -77,39 +86,43 @@ func splitIdentifierByCaseAndSeparators(s string) []string { | |||
stateNothing state = iota | |||
stateLower | |||
stateUpper | |||
stateNonCase |
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.
stateNonCase | |
stateNoCase |
internal/x/text/cases.go
Outdated
nextState = stateDelimiter | ||
|
||
default: // Non-case sensitive letters. | ||
nextState = stateNonCase |
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.
nextState = stateNonCase | |
nextState = stateNoCase |
internal/x/text/cases.go
Outdated
} | ||
|
||
return ident | ||
} | ||
|
||
func isNoneCaseSensitiveLetter(r rune) bool { |
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.
func isNoneCaseSensitiveLetter(r rune) bool { | |
func isNotCaseSensitiveLetter(r rune) bool { |
internal/x/text/cases.go
Outdated
ident = "A" + ident | ||
rIdent := []rune(ident) | ||
if len(rIdent) > 0 { | ||
if !unicode.IsLetter(rIdent[0]) || isNoneCaseSensitiveLetter(rIdent[0]) { |
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.
if !unicode.IsLetter(rIdent[0]) || isNoneCaseSensitiveLetter(rIdent[0]) { | |
if !unicode.IsLetter(rIdent[0]) || isNotCaseSensitiveLetter(rIdent[0]) { |
I've made the suggested naming changes as per your review. |
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.
LGTM
This PR includes modifications to the
splitIdentifierByCaseAndSeparators
function, aiming to extend its compatibility to non-case-sensitive languages such as Korean, Chinese, and Japanese, among others.Key Points:
However, I faced difficulties in augmenting the test suite to include these new language scenarios. My limited experience with the current test structure hindered my ability to confidently implement new test cases for these languages.
In an attempt to modify the tests, I utilized the go-jsonschema binary, executing the following command:
./go-jsonschema --capitalization HtMl,ID,URL -p test tests/data/misc/capitalization/capitalization.json -o tests/data/misc/capitalization/capitalization.go
This process resulted in struct names being generated as CapitalizationJson instead of Capitalization. Consequently, I manually adjusted the names.
I am uncertain about the correctness of these steps and would greatly appreciate any advice or guidance. Your feedback or suggestions for improving this feature expansion and the addition of test cases would be invaluable.
Thank you.