-
Notifications
You must be signed in to change notification settings - Fork 578
Add support for lossy format strings #1693
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1693 +/- ##
==========================================
- Coverage 90.67% 90.61% -0.07%
==========================================
Files 38 38
Lines 16874 16945 +71
==========================================
+ Hits 15301 15354 +53
- Misses 1573 1591 +18 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
src/format/strftime.rs
Outdated
macro_rules! error { | ||
() => { | ||
if self.lossy { Item::Literal(&original[..error_len]) } else { Item::Error } | ||
}; | ||
($ch:expr, _) => { | ||
if self.lossy { | ||
error_len -= $ch.len_utf8(); | ||
remainder = &original[error_len..]; | ||
} | ||
}; | ||
($ch:expr) => {{ | ||
error!($ch, _); | ||
error!() | ||
}}; | ||
} | ||
|
||
macro_rules! return_error { | ||
() => { | ||
return Some((remainder, error!())) | ||
}; | ||
($ch:expr) => { | ||
error!($ch, _); | ||
return_error!(); | ||
}; | ||
} |
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.
Sorry, I don't want all this macro mess here -- there's probably too much already. Can you figure out a better way?
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.
The most recent commit should be good. The coverage dropped because uncovered paths that used to be one line are now several.
b9980ec
to
6e382d2
Compare
6e382d2
to
e578eb4
Compare
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.
That's much better, thanks!
Wondering if lossy
is the best name for this... maybe lenient
or copy_invalid
? Any thoughts/suggestions?
I agree that lossy isn't a great name, and lenient has parity with something like Java's |
I don't think lenient formatting is important enough to earn API exposure on every type, please confine it to the format module. |
b061027
to
80a6532
Compare
Fixed. |
closes #1692
@djc You described a
parse_lossy
function, but I ended up writing anew_lossy
function. If you think it's better to setlossy
at parse time, I'm happy to change it. However, it seems better to be able to set it for theIterator
directly.