Last active
August 29, 2015 14:13
-
-
Save hinst/e7e1da6a67210bc29702 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::File; | |
use std::sync::Arc; | |
use std::io::stdio::println; | |
use std::iter::AdditiveIterator; | |
static function_headers_marker: &'static str = "{$region functions_header}"; | |
static function_headers_end_marker: &'static str = "{$endRegion functions_header}"; | |
fn write_line(string: String) { | |
let string = string.as_slice(); | |
std::io::stdio::println(string); | |
} | |
fn concat_strings(strings: &[String]) -> String { | |
let result_length = strings.iter().map(|ref s| s.len()).sum(); | |
let mut result = String::with_capacity(result_length); | |
for string in strings.iter() { | |
let string = string.as_slice(); | |
result.push_str(string); | |
} | |
result | |
} | |
/// Accepts file content. Returns processed file content. | |
fn convert(content: String) -> String { | |
let content = content.as_slice(); | |
let function_headers_marker_position = content.find_str(function_headers_marker); | |
let function_headers_end_marker_position = content.find_str(function_headers_end_marker); | |
if function_headers_marker_position.is_some() && function_headers_end_marker_position.is_some() { | |
let function_headers_marker_position = function_headers_marker_position.unwrap(); | |
let function_headers_end_marker_position = function_headers_end_marker_position.unwrap(); | |
let header_content = content.slice_chars(function_headers_marker_position + function_headers_marker.len(), function_headers_end_marker_position - 1); | |
write_line("Debug: header content is: '".to_string() + header_content + "'"); | |
} | |
else { | |
write_line(concat_strings(&[ | |
"Error: ".to_string(), | |
if function_headers_marker_position.is_none() {concat_strings(&["function headers marker not found: '".to_string(), function_headers_marker.to_string(), "'".to_string()])} | |
else if function_headers_end_marker_position.is_none() {concat_strings(&["function headers end marker not found: '".to_string(), function_headers_marker.to_string(), "'".to_string()])} | |
else {"unknown error".to_string()} | |
])) | |
} | |
let mut result = String::new(); | |
result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment