Conversation
This commit introduces two new variants of the UpperCaseFirst function: - UpperCaseFirstWithErr: Returns the modified string and an error if the first rune is invalid. - MustUpperCaseFirst: Panics if the first rune is invalid. It also introduces ErrRune to explicitly identify invalid rune errors. These additions provide more control over UTF-8 decoding errors compared to the silent failure of the original UpperCaseFirst function. Tests are added to cover these new functions. Co-authored-by: arran4 <111667+arran4@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
@jules there should be complete support for this and we should see greater code reuse please.
There was a problem hiding this comment.
I've refactored the code to use a shared internal helper performCaseFirst to eliminate duplication between the UpperCaseFirst variants.
To provide complete support, I've also implemented the symmetric LowerCaseFirst, LowerCaseFirstWithErr, and MustLowerCaseFirst functions. Additionally, I've updated ToFormattedCase to use LowerCaseFirst when OptionFirstLower is used, which also fixes a bug where multibyte characters were handled incorrectly.
- Introduced `performCaseFirst` internal helper to reduce duplication in casing functions. - Added `LowerCaseFirst`, `LowerCaseFirstWithErr`, and `MustLowerCaseFirst` for symmetry with `UpperCaseFirst` variants. - Updated `ToFormattedCase` to use `LowerCaseFirst`, fixing incorrect handling of multibyte characters when `OptionFirstLower` is used. - Added comprehensive tests for new functions and bug fix. Co-authored-by: arran4 <111667+arran4@users.noreply.github.com>
| "unicode/utf8" | ||
| ) | ||
|
|
||
| var ErrRune = errors.New("invalid rune") |
There was a problem hiding this comment.
Yes, ErrRune is the only error condition explicitly handled here, which corresponds to utf8.RuneError occurring with a non-zero size (indicating invalid UTF-8).
Empty strings are treated as valid no-ops (returning the empty string without error), which is consistent with the behavior of standard library functions like strings.ToUpper.
- Introduced `performCaseFirst` helper to unify casing logic. - Added `LowerCaseFirst`, `LowerCaseFirstWithErr`, and `MustLowerCaseFirst`. - Updated `ToFormattedCase` to use `LowerCaseFirst` for correctness with multibyte characters. - Validated `ErrRune` scope; empty strings are valid no-ops. - Added comprehensive tests. Co-authored-by: arran4 <111667+arran4@users.noreply.github.com>
|
@jules go format |
I have run |
- Ran `go fmt ./...` to fix formatting issues in `benchmark_test.go` and `types_test.go`. - Removed temporary file `verify_utf8.go`. Co-authored-by: arran4 <111667+arran4@users.noreply.github.com>
|
@jules go format needs to be run as per: |
I have run |
- Formatted `benchmark_test.go` and `types_test.go`. - Note: `metadata_test.go` was not found and thus not formatted. Co-authored-by: arran4 <111667+arran4@users.noreply.github.com>
Added
UpperCaseFirstWithErrandMustUpperCaseFirsttotypes.goalong withErrRune. Added corresponding tests intypes_test.go.PR created automatically by Jules for task 14880112615616114181 started by @arran4