swiftlang / swiftlang/swift-experimental-string-processing
trimmingPrefixOrNil
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 308
- Forks
- 52
- Avg merge
- 12h 45m
- Merged PRs (30d)
- 2
Description
Motivation
The current trimmingPrefx drops the information about whether the prefix was matched. I often do something like:
if x.starts(with: "foo") { doSomething(with: x.dropFirst("foo".count)) }
Proposed solution
if let y = x.trimmingPrefixOrNil("foo") { doSomething(with: y) }
Would be more expressive, less error prone, and more efficient. I don't love the name; maybe something better can be found. Frankly I think trimmingPrefix would have been a better name for the functionality I want. After all if "foo" can't be trimmed off the front of x, then x with the prefix "foo" trimmed is not a thing, and nil is an appropriate response.
Alternatives considered
No response
Additional information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing trimmingPrefx implementation and any tests covering prefix trimming. Compare the proposed optional-returning behavior and naming alternatives, then verify that matching prefixes return the trimmed value and non-matching prefixes return nil.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- api
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100