about summary refs log tree commit diff
path: root/src/rustbook
diff options
context:
space:
mode:
Diffstat (limited to 'src/rustbook')
-rw-r--r--src/rustbook/book.rs85
-rw-r--r--src/rustbook/build.rs7
-rw-r--r--src/rustbook/main.rs2
3 files changed, 45 insertions, 49 deletions
diff --git a/src/rustbook/book.rs b/src/rustbook/book.rs
index 20346449fd1..3047e93137f 100644
--- a/src/rustbook/book.rs
+++ b/src/rustbook/book.rs
@@ -13,7 +13,6 @@
 use std::io::BufferedReader;
 use std::iter;
 use std::iter::AdditiveIterator;
-use regex::Regex;
 
 pub struct BookItem {
     pub title: String,
@@ -94,8 +93,6 @@ pub fn parse_summary<R: Reader>(input: R, src: &Path) -> Result<Book, Vec<String
         }
     }
 
-    let regex = r"(?P<indent>[\t ]*)\*[:space:]*\[(?P<title>.*)\]\((?P<path>.*)\)";
-    let item_re = Regex::new(regex).unwrap();
     let mut top_items = vec!();
     let mut stack = vec!();
     let mut errors = vec!();
@@ -117,45 +114,51 @@ pub fn parse_summary<R: Reader>(input: R, src: &Path) -> Result<Book, Vec<String
             }
         };
 
-        item_re.captures(&line[]).map(|cap| {
-            let given_path = cap.name("path");
-            let title = cap.name("title").unwrap().to_string();
-
-            let path_from_root = match src.join(given_path.unwrap()).path_relative_from(src) {
-                Some(p) => p,
-                None => {
-                    errors.push(format!("paths in SUMMARY.md must be relative, \
-                                         but path '{}' for section '{}' is not.",
-                                         given_path.unwrap(), title));
-                    Path::new("")
-                }
-            };
-            let path_to_root = Path::new(iter::repeat("../")
-                                             .take(path_from_root.components().count() - 1)
-                                             .collect::<String>());
-            let item = BookItem {
-                title: title,
-                path: path_from_root,
-                path_to_root: path_to_root,
-                children: vec!(),
-            };
-            let level = cap.name("indent").unwrap().chars().map(|c| {
-                match c {
-                    ' ' => 1us,
-                    '\t' => 4,
-                    _ => unreachable!()
-                }
-            }).sum() / 4 + 1;
-
-            if level > stack.len() + 1 {
-                errors.push(format!("section '{}' is indented too deeply; \
-                                     found {}, expected {} or less",
-                                    item.title, level, stack.len() + 1));
-            } else if level <= stack.len() {
-                collapse(&mut stack, &mut top_items, level);
+        let star_idx = match line.find_str("*") { Some(i) => i, None => continue };
+
+        let start_bracket = star_idx + line[star_idx..].find_str("[").unwrap();
+        let end_bracket = start_bracket + line[start_bracket..].find_str("](").unwrap();
+        let start_paren = end_bracket + 1;
+        let end_paren = start_paren + line[start_paren..].find_str(")").unwrap();
+
+        let given_path = &line[start_paren + 1 .. end_paren];
+        let title = line[start_bracket + 1..end_bracket].to_string();
+        let indent = &line[..star_idx];
+
+        let path_from_root = match src.join(given_path).path_relative_from(src) {
+            Some(p) => p,
+            None => {
+                errors.push(format!("paths in SUMMARY.md must be relative, \
+                                     but path '{}' for section '{}' is not.",
+                                     given_path, title));
+                Path::new("")
             }
-            stack.push(item)
-        });
+        };
+        let path_to_root = Path::new(iter::repeat("../")
+                                         .take(path_from_root.components().count() - 1)
+                                         .collect::<String>());
+        let item = BookItem {
+            title: title,
+            path: path_from_root,
+            path_to_root: path_to_root,
+            children: vec!(),
+        };
+        let level = indent.chars().map(|c| {
+            match c {
+                ' ' => 1us,
+                '\t' => 4,
+                _ => unreachable!()
+            }
+        }).sum() / 4 + 1;
+
+        if level > stack.len() + 1 {
+            errors.push(format!("section '{}' is indented too deeply; \
+                                 found {}, expected {} or less",
+                                item.title, level, stack.len() + 1));
+        } else if level <= stack.len() {
+            collapse(&mut stack, &mut top_items, level);
+        }
+        stack.push(item)
     }
 
     if errors.is_empty() {
diff --git a/src/rustbook/build.rs b/src/rustbook/build.rs
index 50a6ad43aee..93601c0f61b 100644
--- a/src/rustbook/build.rs
+++ b/src/rustbook/build.rs
@@ -22,8 +22,6 @@ use book::{Book, BookItem};
 use css;
 use javascript;
 
-use regex::Regex;
-
 use rustdoc;
 
 struct Build;
@@ -81,9 +79,6 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
 
         let out_path = tgt.join(item.path.dirname());
 
-        let regex = r"\[(?P<title>[^]]*)\]\((?P<url_stem>[^)]*)\.(?P<ext>md|markdown)\)";
-        let md_urls = Regex::new(regex).unwrap();
-
         let src;
         if os::args().len() < 3 {
             src = os::getcwd().unwrap().clone();
@@ -94,7 +89,7 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
         let markdown_data = try!(File::open(&src.join(&item.path)).read_to_string());
         let preprocessed_path = tmp.path().join(item.path.filename().unwrap());
         {
-            let urls = md_urls.replace_all(&markdown_data[], "[$title]($url_stem.html)");
+            let urls = markdown_data.replace(".md)", ".html)");
             try!(File::create(&preprocessed_path)
                       .write_str(&urls[]));
         }
diff --git a/src/rustbook/main.rs b/src/rustbook/main.rs
index ea72c653087..cbd29004097 100644
--- a/src/rustbook/main.rs
+++ b/src/rustbook/main.rs
@@ -11,8 +11,6 @@
 #![feature(slicing_syntax, box_syntax)]
 #![allow(unstable)]
 
-extern crate regex;
-
 extern crate rustdoc;
 
 use std::os;