summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBen S <ogham@bsago.me>2015-01-05 14:41:43 +0000
committerBen S <ogham@bsago.me>2015-01-05 14:41:43 +0000
commitd400231de5312d07081ec57efdb039615052db66 (patch)
treed21f07622990cf6fe11c9b000d6c3c75f7f44e3f /src
parentba36d4f7f07ac9f03445ebf5788dc00681ff08a1 (diff)
Upgrade to latest Rust
Also, remove dependency on the Regex library by replacing the one place it was used with standard code that should hopefully be faster anyway.
Diffstat (limited to 'src')
-rw-r--r--src/exa.rs9
-rw-r--r--src/file.rs42
2 files changed, 24 insertions, 27 deletions
diff --git a/src/exa.rs b/src/exa.rs
index 0b7aef5..67c8b9e 100644
--- a/src/exa.rs
+++ b/src/exa.rs
@@ -1,6 +1,5 @@
-#![feature(phase, globs)]
-extern crate regex;
-#[phase(plugin)] extern crate regex_macros;
+#![feature(globs)]
+
extern crate ansi_term;
extern crate number_prefix;
extern crate unicode;
@@ -116,11 +115,11 @@ fn lines_view(files: Vec<File>) {
fn fit_into_grid(across: bool, console_width: uint, files: &Vec<File>) -> Option<(uint, Vec<uint>)> {
// TODO: this function could almost certainly be optimised...
// surely not *all* of the numbers of lines are worth searching through!
-
+
// Instead of numbers of columns, try to find the fewest number of *lines*
// that the output will fit in.
for num_lines in range(1, files.len()) {
-
+
// The number of columns is the number of files divided by the number
// of lines, *rounded up*.
let mut num_columns = files.len() / num_lines;
diff --git a/src/file.rs b/src/file.rs
index 74018ac..9fb283c 100644
--- a/src/file.rs
+++ b/src/file.rs
@@ -1,6 +1,5 @@
use std::io::{fs, IoResult};
use std::io;
-use std::str::CowString;
use ansi_term::{ANSIString, Colour, Style};
use ansi_term::Style::Plain;
@@ -49,16 +48,15 @@ impl<'a> File<'a> {
dir: parent,
stat: stat,
name: filename.to_string(),
- ext: File::ext(filename),
+ ext: File::ext(filename.as_slice()),
}
}
- fn ext(name: CowString) -> Option<String> {
+ fn ext(name: &'a str) -> Option<String> {
// The extension is the series of characters after a dot at
// the end of a filename. This deliberately also counts
// dotfiles - the ".git" folder has the extension "git".
- let re = regex!(r"\.([^.]+)$");
- re.captures(name.as_slice()).map(|caps| caps.at(1).to_string())
+ name.rfind('.').map(|pos| name.slice_from(pos + 1).to_string())
}
pub fn is_dotfile(&self) -> bool {
@@ -209,7 +207,7 @@ impl<'a> File<'a> {
dir: self.dir,
stat: stat,
name: filename.to_string(),
- ext: File::ext(filename.clone()),
+ ext: File::ext(filename.as_slice()),
});
// Statting a path usually fails because the file at the
@@ -232,19 +230,19 @@ impl<'a> File<'a> {
GREY.paint("-").to_string()
}
else {
- let result = match size_format {
- SizeFormat::DecimalBytes => decimal_prefix(self.stat.size as f64),
- SizeFormat::BinaryBytes => binary_prefix(self.stat.size as f64),
- SizeFormat::JustBytes => return Green.bold().paint(self.stat.size.to_string().as_slice()).to_string(),
- };
-
- match result {
- Standalone(bytes) => Green.bold().paint(bytes.to_string().as_slice()).to_string(),
- Prefixed(prefix, n) => {
- let number = if n < 10f64 { format!("{:.1}", n) } else { format!("{:.0}", n) };
- format!("{}{}", Green.bold().paint(number.as_slice()), Green.paint(prefix.symbol()))
- }
- }
+ let result = match size_format {
+ SizeFormat::DecimalBytes => decimal_prefix(self.stat.size as f64),
+ SizeFormat::BinaryBytes => binary_prefix(self.stat.size as f64),
+ SizeFormat::JustBytes => return Green.bold().paint(self.stat.size.to_string().as_slice()).to_string(),
+ };
+
+ match result {
+ Standalone(bytes) => Green.bold().paint(bytes.to_string().as_slice()).to_string(),
+ Prefixed(prefix, n) => {
+ let number = if n < 10f64 { format!("{:.1}", n) } else { format!("{:.0}", n) };
+ format!("{}{}", Green.bold().paint(number.as_slice()), Green.paint(prefix.symbol()))
+ }
+ }
}
}
@@ -270,10 +268,10 @@ impl<'a> File<'a> {
fn permissions_string(&self) -> String {
let bits = self.stat.perm;
let executable_colour = match self.stat.kind {
- io::FileType::RegularFile => Green.bold().underline(),
- _ => Green.bold(),
+ io::FileType::RegularFile => Green.bold().underline(),
+ _ => Green.bold(),
};
-
+
return format!("{}{}{}{}{}{}{}{}{}{}",
self.type_char(),