mxmlextrema_as3parser/
util.rs

1//! Miscellaneous.
2
3mod arena;
4pub use arena::*;
5
6pub use by_address::ByAddress as NodeAsKey;
7
8mod character_reader;
9pub use character_reader::*;
10
11mod escaping;
12pub use escaping::*;
13
14mod css;
15pub use css::*;
16
17pub use std::cell::{Cell, RefCell};
18pub use std::collections::{HashMap, HashSet};
19pub use std::rc::{Rc, Weak};
20
21pub fn default<T: Default>() -> T {
22    T::default()
23}
24
25/// Counts the first whitespace characters of a string.
26pub fn count_first_whitespace_characters(input: &str) -> usize {
27    input.chars().count() - input.trim_start().chars().count()
28}
29
30/// Decreases the last offset of a range without ever going behind the first offset.
31pub fn decrease_last_offset(first_offset: usize, mut last_offset: usize, count: usize) -> usize {
32    for _ in 0..count {
33        last_offset = if first_offset < last_offset { last_offset - 1 } else { last_offset };
34    }
35    last_offset
36}