about summary refs log tree commit diff
diff options
context:
space:
mode:
authorIgor Aleksanov <popzxc@yandex.ru>2019-11-03 12:54:23 +0300
committerIgor Aleksanov <popzxc@yandex.ru>2019-11-03 12:54:23 +0300
commit649a5247f58a2cdba58b63e48403b55cf7bf8bdb (patch)
treeed39408a5b2607e83b58942040eb29b40d2b2199
parente0c45f7ee7b1c3882d08e9b71e753e3251c2dff1 (diff)
downloadrust-649a5247f58a2cdba58b63e48403b55cf7bf8bdb.tar.gz
rust-649a5247f58a2cdba58b63e48403b55cf7bf8bdb.zip
librustc_lexer: Simplify "single_quoted_string" method
-rw-r--r--src/librustc_lexer/src/lib.rs26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/librustc_lexer/src/lib.rs b/src/librustc_lexer/src/lib.rs
index 92d99f37713..2edf3bd78ef 100644
--- a/src/librustc_lexer/src/lib.rs
+++ b/src/librustc_lexer/src/lib.rs
@@ -537,26 +537,30 @@ impl Cursor<'_> {
 
     fn single_quoted_string(&mut self) -> bool {
         debug_assert!(self.prev() == '\'');
-        // Parse `'''` as a single char literal.
-        if self.nth_char(0) == '\'' && self.nth_char(1) == '\'' {
+        // Check if it's a one-symbol literal.
+        if self.second() == '\'' && self.first() != '\\' {
             self.bump();
+            self.bump();
+            return true;
         }
+
+        // Literal has more than one symbol.
+
         // Parse until either quotes are terminated or error is detected.
-        let mut first = true;
         loop {
             match self.first() {
-                // Probably beginning of the comment, which we don't want to include
-                // to the error report.
-                '/' if !first => break,
-                // Newline without following '\'' means unclosed quote, stop parsing.
-                '\n' if self.nth_char(1) != '\'' => break,
-                // End of file, stop parsing.
-                EOF_CHAR if self.is_eof() => break,
                 // Quotes are terminated, finish parsing.
                 '\'' => {
                     self.bump();
                     return true;
                 }
+                // Probably beginning of the comment, which we don't want to include
+                // to the error report.
+                '/' => break,
+                // Newline without following '\'' means unclosed quote, stop parsing.
+                '\n' if self.second() != '\'' => break,
+                // End of file, stop parsing.
+                EOF_CHAR if self.is_eof() => break,
                 // Escaped slash is considered one character, so bump twice.
                 '\\' => {
                     self.bump();
@@ -567,8 +571,8 @@ impl Cursor<'_> {
                     self.bump();
                 }
             }
-            first = false;
         }
+        // String was not terminated.
         false
     }