mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 22:30:03 -04:00
use map_or and map_or_else
This commit is contained in:
@@ -150,8 +150,7 @@ fn remove_leading_indentation(code: &str) -> String {
|
||||
let start = first_line_indent.min(indent);
|
||||
let end = code
|
||||
.find('\n')
|
||||
.map(|endline| endline + 1)
|
||||
.unwrap_or_else(|| code.len());
|
||||
.map_or_else(|| code.len(), |endline| endline + 1);
|
||||
out += &code[start..end];
|
||||
code = &code[end..];
|
||||
}
|
||||
|
||||
@@ -49,11 +49,7 @@ impl super::View for MultiTouch {
|
||||
ui.separator();
|
||||
ui.label("Try touch gestures Pinch/Stretch, Rotation, and Pressure with 2+ fingers.");
|
||||
|
||||
let num_touches = ui
|
||||
.input()
|
||||
.multi_touch()
|
||||
.map(|mt| mt.num_touches)
|
||||
.unwrap_or(0);
|
||||
let num_touches = ui.input().multi_touch().map_or(0, |mt| mt.num_touches);
|
||||
ui.label(format!("Current touches: {}", num_touches));
|
||||
|
||||
Frame::dark_canvas(ui.style()).show(ui, |ui| {
|
||||
|
||||
@@ -28,10 +28,7 @@ pub fn highlight_easymark(visuals: &egui::Visuals, mut text: &str) -> egui::text
|
||||
|
||||
while !text.is_empty() {
|
||||
if start_of_line && text.starts_with("```") {
|
||||
let end = text
|
||||
.find("\n```")
|
||||
.map(|i| i + 4)
|
||||
.unwrap_or_else(|| text.len());
|
||||
let end = text.find("\n```").map_or_else(|| text.len(), |i| i + 4);
|
||||
job.append(
|
||||
&text[..end],
|
||||
0.0,
|
||||
@@ -52,8 +49,7 @@ pub fn highlight_easymark(visuals: &egui::Visuals, mut text: &str) -> egui::text
|
||||
style.code = true;
|
||||
let end = text[1..]
|
||||
.find(&['`', '\n'][..])
|
||||
.map(|i| i + 2)
|
||||
.unwrap_or_else(|| text.len());
|
||||
.map_or_else(|| text.len(), |i| i + 2);
|
||||
job.append(&text[..end], 0.0, format_from_style(visuals, &style));
|
||||
text = &text[end..];
|
||||
style.code = false;
|
||||
@@ -112,12 +108,10 @@ pub fn highlight_easymark(visuals: &egui::Visuals, mut text: &str) -> egui::text
|
||||
// Swallow everything up to the next special character:
|
||||
let line_end = text[skip..]
|
||||
.find('\n')
|
||||
.map(|i| (skip + i + 1))
|
||||
.unwrap_or_else(|| text.len());
|
||||
.map_or_else(|| text.len(), |i| (skip + i + 1));
|
||||
let end = text[skip..]
|
||||
.find(&['*', '`', '~', '_', '/', '$', '^', '\\', '<', '['][..])
|
||||
.map(|i| (skip + i).max(1)) // make sure we swallow at least one character
|
||||
.unwrap_or_else(|| text.len());
|
||||
.map_or_else(|| text.len(), |i| (skip + i).max(1));
|
||||
|
||||
if line_end <= end {
|
||||
job.append(&text[..line_end], 0.0, format_from_style(visuals, &style));
|
||||
|
||||
@@ -319,8 +319,7 @@ impl<'a> Iterator for Parser<'a> {
|
||||
let end = self
|
||||
.s
|
||||
.find(&['*', '`', '~', '_', '/', '$', '^', '\\', '<', '[', '\n'][..])
|
||||
.map(|special| special.max(1)) // make sure we swallow at least one character
|
||||
.unwrap_or_else(|| self.s.len());
|
||||
.map_or_else(|| self.s.len(), |special| special.max(1));
|
||||
|
||||
let item = Item::Text(self.style, &self.s[..end]);
|
||||
self.s = &self.s[end..];
|
||||
|
||||
@@ -416,8 +416,7 @@ impl Highligher {
|
||||
} else if text.starts_with(|c: char| c.is_ascii_alphanumeric()) {
|
||||
let end = text[1..]
|
||||
.find(|c: char| !c.is_ascii_alphanumeric())
|
||||
.map(|i| i + 1)
|
||||
.unwrap_or_else(|| text.len());
|
||||
.map_or_else(|| text.len(), |i| i + 1);
|
||||
let word = &text[..end];
|
||||
let tt = if is_keyword(word) {
|
||||
TokenType::Keyword
|
||||
@@ -429,8 +428,7 @@ impl Highligher {
|
||||
} else if text.starts_with(|c: char| c.is_ascii_whitespace()) {
|
||||
let end = text[1..]
|
||||
.find(|c: char| !c.is_ascii_whitespace())
|
||||
.map(|i| i + 1)
|
||||
.unwrap_or_else(|| text.len());
|
||||
.map_or_else(|| text.len(), |i| i + 1);
|
||||
job.append(&text[..end], 0.0, theme.formats[TokenType::Whitespace]);
|
||||
text = &text[end..];
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user