mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-30 23:27:22 +00:00

Updated the version from 1.1 to 1.2 Renamed the header to "Slint Royalty-free Desktop, Mobile, and Web Applications License" Added definition of "Mobile Application" and grant of right Moved "Limitations" to 3rd section and "License Conditions - Attributions" to 2nd section Added flexibility to choose between showing "MadeWithSlint" as a dialog/splash screen or on a public webpage Moved the para on copyright notices to section under "Limitations"
39 lines
1.2 KiB
Rust
39 lines
1.2 KiB
Rust
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.2 OR LicenseRef-Slint-commercial
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
|
pub enum BreakOpportunity {
|
|
Allowed,
|
|
Mandatory,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct LineBreakIterator<'a> {
|
|
it: core::str::CharIndices<'a>,
|
|
}
|
|
|
|
impl<'a> LineBreakIterator<'a> {
|
|
pub fn new(text: &'a str) -> Self {
|
|
Self { it: text.char_indices() }
|
|
}
|
|
}
|
|
|
|
impl<'a> Iterator for LineBreakIterator<'a> {
|
|
type Item = (usize, BreakOpportunity);
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
while let Some((byte_offset, char)) = self.it.next() {
|
|
let maybe_opportunity = match char {
|
|
'\u{2028}' | '\u{2029}' => Some(BreakOpportunity::Mandatory), // unicode line- and paragraph separators
|
|
'\n' => Some(BreakOpportunity::Mandatory), // ascii line break
|
|
_ if char.is_ascii_whitespace() => Some(BreakOpportunity::Allowed),
|
|
_ => None,
|
|
};
|
|
if let Some(opportunity) = maybe_opportunity {
|
|
return Some((byte_offset + 1, opportunity));
|
|
}
|
|
}
|
|
|
|
None
|
|
}
|
|
}
|