about summary refs log tree commit diff
path: root/src/string.rs
diff options
context:
space:
mode:
authorNick Cameron <ncameron@mozilla.com>2017-01-31 08:28:48 +1300
committerNick Cameron <ncameron@mozilla.com>2017-01-31 08:35:23 +1300
commit428339fdc3c572b0b4a4e86ce1fc2ab048cccac0 (patch)
treea6f024f772b19db996ada08783190c50aced0b5f /src/string.rs
parent6054f28bd2c2b617d4d494c5e27e09b4b16db1d2 (diff)
Refactor indent and width into Shape struct
Diffstat (limited to 'src/string.rs')
-rw-r--r--src/string.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/string.rs b/src/string.rs
index 71d8f8415f0..014830a9155 100644
--- a/src/string.rs
+++ b/src/string.rs
@@ -13,7 +13,7 @@
 use unicode_segmentation::UnicodeSegmentation;
 use regex::Regex;
 
-use Indent;
+use Shape;
 use config::Config;
 use utils::wrap_str;
 
@@ -24,8 +24,7 @@ pub struct StringFormat<'a> {
     pub closer: &'a str,
     pub line_start: &'a str,
     pub line_end: &'a str,
-    pub width: usize,
-    pub offset: Indent,
+    pub shape: Shape,
     pub trim_end: bool,
     pub config: &'a Config,
 }
@@ -37,7 +36,7 @@ pub fn rewrite_string<'a>(orig: &str, fmt: &StringFormat<'a>) -> Option<String>
     let stripped_str = re.replace_all(orig, "$1");
 
     let graphemes = UnicodeSegmentation::graphemes(&*stripped_str, false).collect::<Vec<&str>>();
-    let indent = fmt.offset.to_string(fmt.config);
+    let indent = fmt.shape.indent.to_string(fmt.config);
     let punctuation = ":,;.";
 
     // `cur_start` is the position in `orig` of the start of the current line.
@@ -50,7 +49,7 @@ pub fn rewrite_string<'a>(orig: &str, fmt: &StringFormat<'a>) -> Option<String>
     let ender_length = fmt.line_end.len();
     // If we cannot put at least a single character per line, the rewrite won't
     // succeed.
-    let max_chars = try_opt!(fmt.width.checked_sub(fmt.opener.len() + ender_length + 1)) + 1;
+    let max_chars = try_opt!(fmt.shape.width.checked_sub(fmt.opener.len() + ender_length + 1)) + 1;
 
     // Snip a line at a time from `orig` until it is used up. Push the snippet
     // onto result.
@@ -118,7 +117,7 @@ pub fn rewrite_string<'a>(orig: &str, fmt: &StringFormat<'a>) -> Option<String>
     }
 
     result.push_str(fmt.closer);
-    wrap_str(result, fmt.config.max_width, fmt.width, fmt.offset)
+    wrap_str(result, fmt.config.max_width, fmt.shape)
 }
 
 #[cfg(test)]
@@ -133,8 +132,7 @@ mod test {
             closer: "\"",
             line_start: " ",
             line_end: "\\",
-            width: 2,
-            offset: ::Indent::empty(),
+            shape: ::Shape::legacy(2, ::Indent::empty()),
             trim_end: false,
             config: &config,
         };