MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / unescape_string

Function unescape_string

tests/integration.rs:164–188  ·  view source on GitHub ↗
(s: &str)

Source from the content-addressed store, hash-verified

162}
163
164fn unescape_string(s: &str) -> String {
165 let mut result = String::with_capacity(s.len());
166 let mut chars = s.chars().peekable();
167
168 while let Some(ch) = chars.next() {
169 if ch == '\\' {
170 match chars.next() {
171 Some('n') => result.push('\n'),
172 Some('t') => result.push('\t'),
173 Some('r') => result.push('\r'),
174 Some('\\') => result.push('\\'),
175 Some('"') => result.push('"'),
176 Some('\'') => result.push('\''),
177 Some(c) => {
178 result.push('\\');
179 result.push(c);
180 }
181 None => result.push('\\'),
182 }
183 } else {
184 result.push(ch);
185 }
186 }
187 result
188}

Callers 1

parse_expected_stringFunction · 0.85

Calls 3

lenMethod · 0.80
pushMethod · 0.80
nextMethod · 0.45

Tested by

no test coverage detected