From b421a17ed14e966bddb62165c9d944e565f1ba7a Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 3 May 2015 16:19:58 +0200 Subject: vtcol.rs: parse color indices in scheme files --- vtcol.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/vtcol.rs b/vtcol.rs index 0b86fc2..14abf4b 100644 --- a/vtcol.rs +++ b/vtcol.rs @@ -402,12 +402,22 @@ impl Palette { while let Ok(line) = reader.read_line() { let len = line.len(); if len < 8_us { panic!("invalid line in string: {}", line); }; - if let Some(idx) = line.find_str("#") { - let idx = idx + 1_us; - if idx > len - 6_us { /* no room left for color definition after '#' char */ + if let Some(off) = line.find_str("#") { + if off != 0_us { + /* Palette index specified, number prepended */ + let str_idx = line.slice_chars(0, off); + let parse_res : Option + = std::str::FromStr::from_str(str_idx); + match parse_res { + Some(new_idx) => pal_idx = new_idx * 3_us, + None => () + } + } + let off = off + 1_us; + if off > len - 6_us { /* no room left for color definition after '#' char */ panic!("invalid color definition: {}", line); } - let col = line.slice_chars(idx, idx + RAW_COLEXPR_SIZE); + let col = line.slice_chars(off, off + RAW_COLEXPR_SIZE); let (r, g, b) = rgb_of_hex_triplet(col); pal[pal_idx + 0_us] = r; -- cgit v1.2.3