Make comment support switchable

Previously, serde_jsonrc always accepted embedded comments in
the JSON. With this change, this is now switchable.

Bug: 1069271
Change-Id: I27c19c63bcebfc6cb492f2ee9874e0d9a38fb686
diff --git a/src/de.rs b/src/de.rs
index 45ada2e..6d838d1 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -26,6 +26,7 @@
     #[cfg(feature = "unbounded_depth")]
     disable_recursion_limit: bool,
     ignore_trailing_commas: bool,
+    allow_comments: bool,
 }
 
 impl<'de, R> Deserializer<R>
@@ -48,6 +49,7 @@
                 scratch: Vec::new(),
                 remaining_depth: 128,
                 ignore_trailing_commas: true,
+                allow_comments: true,
             }
         }
 
@@ -59,6 +61,7 @@
                 remaining_depth: 128,
                 disable_recursion_limit: false,
                 ignore_trailing_commas: true,
+                allow_comments: true,
             }
         }
     }
@@ -235,6 +238,11 @@
         self.ignore_trailing_commas = ignore;
     }
 
+    /// Whether to allow comments.
+    pub fn set_allow_comments(&mut self, allow: bool) {
+        self.allow_comments = allow;
+    }
+
     fn peek(&mut self) -> Result<Option<u8>> {
         self.read.peek()
     }
@@ -278,7 +286,7 @@
                 Some(b' ') | Some(b'\n') | Some(b'\t') | Some(b'\r') => {
                     self.eat_char();
                 }
-                Some(b'/') => {
+                Some(b'/') if self.allow_comments => {
                     self.eat_char();
                     match tri!(self.peek()) {
                         Some(b'/') => {