1use crate::util::{ParseNumber, ParseNumberError};
2
3pub trait StrExt {
5 fn trim_comment(&self) -> &str;
7
8 fn parse_num<N: ParseNumber>(&self) -> Result<N, ParseNumberError>;
12
13 fn parse_with_limits<N: ParseNumber>(&self, limit: N) -> Result<N, ParseNumberError>;
15
16 fn to_standardized_path(&self) -> String;
18
19 fn clean_filename(&self) -> String;
21}
22
23impl StrExt for str {
24 fn trim_comment(&self) -> &str {
25 self.find("//").map_or(self, |i| &self[..i]).trim_end()
26 }
27
28 fn parse_num<N: ParseNumber>(&self) -> Result<N, ParseNumberError> {
29 N::parse(self)
30 }
31
32 fn parse_with_limits<N: ParseNumber>(&self, limit: N) -> Result<N, ParseNumberError> {
33 N::parse_with_limits(self, limit)
34 }
35
36 fn to_standardized_path(&self) -> String {
37 self.replace('\\', "/")
38 }
39
40 fn clean_filename(&self) -> String {
41 self.trim_matches('"')
42 .replace("\\\\", "\\")
43 .to_standardized_path()
44 }
45}