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

Method escape_string

aiscript-lexer/src/lib.rs:811–839  ·  view source on GitHub ↗
(&mut self, input: &str)

Source from the content-addressed store, hash-verified

809 }
810
811 pub fn escape_string(&mut self, input: &str) -> Option<String> {
812 let mut escaped_string = String::new();
813 let mut chars = input.chars();
814 while let Some(ch) = chars.next() {
815 if ch == '\\' {
816 let c = match chars.next() {
817 Some('n') => '\n',
818 Some('r') => '\r',
819 Some('t') => '\t',
820 Some('\\') => '\\',
821 Some('\'') => '\'',
822 Some('\"') => '\"',
823 Some('0') => '\0',
824 Some(ch) => {
825 self.error(&format!("Invalid escape sequence: \\{}", ch));
826 return None;
827 }
828 None => {
829 self.error("Unterminated escape sequence");
830 return None;
831 }
832 };
833 escaped_string.push(c);
834 } else {
835 escaped_string.push(ch);
836 }
837 }
838 Some(escaped_string)
839 }
840
841 pub fn advance(&mut self) {
842 self.previous = mem::take(&mut self.current);

Callers 3

stringMethod · 0.80
parse_fstring_contentMethod · 0.80
parse_valueMethod · 0.80

Calls 3

pushMethod · 0.80
nextMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected