-
Notifications
You must be signed in to change notification settings - Fork 13.9k
unicode_data
refactors
#147622
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
Open
Kmeakin
wants to merge
4
commits into
rust-lang:master
Choose a base branch
from
Kmeakin:km/unicode-data/refactors
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
unicode_data
refactors
#147622
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use std::fmt; | ||
|
||
// Convenience macros for writing and unwrapping. | ||
#[macro_export] | ||
macro_rules! writeln { | ||
($($args:tt)*) => {{ | ||
use std::fmt::Write as _; | ||
std::writeln!($($args)*).unwrap(); | ||
}}; | ||
} | ||
#[macro_export] | ||
macro_rules! write { | ||
($($args:tt)*) => {{ | ||
use std::fmt::Write as _; | ||
std::write!($($args)*).unwrap(); | ||
}}; | ||
} | ||
|
||
pub fn fmt_list<V: fmt::Debug>(values: impl IntoIterator<Item = V>) -> String { | ||
let pieces = values.into_iter().map(|b| format!("{b:?}, ")); | ||
let mut out = String::new(); | ||
let mut line = String::from("\n "); | ||
for piece in pieces { | ||
if line.len() + piece.len() < 98 { | ||
line.push_str(&piece); | ||
} else { | ||
writeln!(out, "{}", line.trim_end()); | ||
line = format!(" {piece}"); | ||
} | ||
} | ||
writeln!(out, "{}", line.trim_end()); | ||
out | ||
} | ||
|
||
/// Wrapper type for formatting a `T` using its `Binary` implementation. | ||
#[derive(Copy, Clone)] | ||
pub struct Bin<T>(pub T); | ||
|
||
impl<T: fmt::Binary> fmt::Debug for Bin<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let bits = size_of::<T>() * 8; | ||
std::write!(f, "0b{:0bits$b}", self.0) | ||
} | ||
} | ||
|
||
impl<T: fmt::Binary> fmt::Display for Bin<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
fmt::Debug::fmt(self, f) | ||
} | ||
} | ||
|
||
/// Wrapper type for formatting a `char` using `escape_default`. | ||
#[derive(Copy, Clone)] | ||
pub struct CharEscape(pub char); | ||
|
||
impl fmt::Debug for CharEscape { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
std::write!(f, "'{}'", self.0.escape_default()) | ||
} | ||
} | ||
|
||
impl fmt::Display for CharEscape { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
fmt::Debug::fmt(self, f) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is
INDEX_MASK
guaranteed to stay constant? Otherwise, I wouldn't duplicate the definition here, this is likely to go out of sync.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.
It is constant as long as the algorithm doesn't change (the 22nd bit will always be free for our use because Unicode codepoints only go up to 0x10FFFF). I could move both
INDEX_MASK
andto_lowercase
/to_uppercase
tort.rs
if you prefer