MCPcopy Create free account
hub / github.com/AmrDeveloper/GQL / consume_string_with_around

Method consume_string_with_around

crates/gitql-parser/src/tokenizer.rs:680–742  ·  view source on GitHub ↗
(&mut self, around: char)

Source from the content-addressed store, hash-verified

678 }
679
680 fn consume_string_with_around(&mut self, around: char) -> Result<String, Box<Diagnostic>> {
681 // Consume Around start
682 self.advance();
683
684 let mut buffer = String::new();
685 while !self.is_current_char(around) {
686 if !self.is_current_char('\\') {
687 buffer.push(self.content[self.index]);
688 self.advance();
689 continue;
690 }
691
692 // If '\\' is the last character, we don't need to escape it
693 if self.is_last() {
694 buffer.push(self.content[self.index]);
695 self.advance();
696 continue;
697 }
698
699 // Consume '\\'
700 self.advance();
701
702 // Check possible escape depending on the next character
703 let next_char = self.content[self.index];
704 let character_with_escape_handled = match next_char {
705 // Single quote
706 '\'' => {
707 self.advance();
708 '\''
709 }
710 // Double quote
711 '\"' => {
712 self.advance();
713 '\"'
714 }
715 // Backslash
716 '\\' => {
717 self.advance();
718 '\\'
719 }
720 // New line
721 'n' => {
722 self.advance();
723 '\n'
724 }
725 // Carriage return
726 'r' => {
727 self.advance();
728 '\r'
729 }
730 // Tab
731 't' => {
732 self.advance();
733 '\t'
734 }
735 _ => self.content[self.index - 1],
736 };
737

Calls 3

advanceMethod · 0.80
is_current_charMethod · 0.80
is_lastMethod · 0.80

Tested by

no test coverage detected