Move string escape to its own mod
diff --git a/src/attr.rs b/src/attr.rs
index 4bfba22..20bf628 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -28,7 +28,7 @@
#[cfg(feature = "parsing")]
pub mod parsing {
use super::*;
- use helper::escaped_string;
+ use escape::escaped_string;
use ident::parsing::ident;
use nom::multispace;
diff --git a/src/escape.rs b/src/escape.rs
new file mode 100644
index 0000000..de76590
--- /dev/null
+++ b/src/escape.rs
@@ -0,0 +1,42 @@
+#![cfg(feature = "parsing")]
+
+use nom::{self, IResult};
+
+pub fn escaped_string(input: &str) -> IResult<&str, String> {
+ let mut s = String::new();
+ let mut chars = input.char_indices().peekable();
+ while let Some((byte_offset, ch)) = chars.next() {
+ match ch {
+ '"' => {
+ return IResult::Done(&input[byte_offset..], s);
+ }
+ '\\' => {
+ match chars.next() {
+ Some((_, 'x')) => unimplemented!(),
+ Some((_, 'n')) => s.push('\n'),
+ Some((_, 'r')) => s.push('\r'),
+ Some((_, 't')) => s.push('\t'),
+ Some((_, '\\')) => s.push('\\'),
+ Some((_, '0')) => s.push('\0'),
+ Some((_, 'u')) => unimplemented!(),
+ Some((_, '\'')) => s.push('\''),
+ Some((_, '"')) => s.push('"'),
+ Some((_, '\n')) => {
+ while let Some(&(_, ch)) = chars.peek() {
+ if ch.is_whitespace() {
+ chars.next();
+ } else {
+ break;
+ }
+ }
+ }
+ _ => break,
+ }
+ }
+ ch => {
+ s.push(ch);
+ }
+ }
+ }
+ IResult::Error(nom::Err::Position(nom::ErrorKind::Escaped, input))
+}
diff --git a/src/helper.rs b/src/helper.rs
index eec2912..952a356 100644
--- a/src/helper.rs
+++ b/src/helper.rs
@@ -56,42 +56,3 @@
})
};
}
-
-pub fn escaped_string(input: &str) -> IResult<&str, String> {
- let mut s = String::new();
- let mut chars = input.char_indices().peekable();
- while let Some((byte_offset, ch)) = chars.next() {
- match ch {
- '"' => {
- return IResult::Done(&input[byte_offset..], s);
- }
- '\\' => {
- match chars.next() {
- Some((_, 'x')) => unimplemented!(),
- Some((_, 'n')) => s.push('\n'),
- Some((_, 'r')) => s.push('\r'),
- Some((_, 't')) => s.push('\t'),
- Some((_, '\\')) => s.push('\\'),
- Some((_, '0')) => s.push('\0'),
- Some((_, 'u')) => unimplemented!(),
- Some((_, '\'')) => s.push('\''),
- Some((_, '"')) => s.push('"'),
- Some((_, '\n')) => {
- while let Some(&(_, ch)) = chars.peek() {
- if ch.is_whitespace() {
- chars.next();
- } else {
- break;
- }
- }
- }
- _ => break,
- }
- }
- ch => {
- s.push(ch);
- }
- }
- }
- IResult::Error(nom::Err::Position(nom::ErrorKind::Escaped, input))
-}
diff --git a/src/lib.rs b/src/lib.rs
index 2bee314..6037fdf 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -11,6 +11,8 @@
#[macro_use]
mod helper;
+mod escape;
+
mod attr;
pub use attr::{
Attribute,