pub fn from_string_desc<T: AsRef<str>>(string_desc: T) -> Self {
        let mut regions = Vec::new();

        let mut parts: Vec<&str> = string_desc.as_ref().split('/').collect();

        // Strip of the @ at the beginning and remove trailing spaces
        let name = String::from(parts.remove(0)).trim()[1..].to_string();

        let re = regex::Regex::new(r"(\d*)\*(\d*)(\D)(\w)").unwrap();

        while parts.len() >= 2 {
            let address_str = parts.remove(0).trim_start_matches("0x");
            let mut address = u32::from_str_radix(address_str, 16).unwrap_or_default();

            let mut sectors_str: Vec<&str> = parts.remove(0).split(',').collect();

            while !sectors_str.is_empty() {
                let sector_str = sectors_str.remove(0);
                let captures = re.captures(sector_str).unwrap();

                let sector_count = captures
                    .get(1)
                    .unwrap()
                    .as_str()
                    .parse::<u32>()
                    .unwrap_or_default();

                let multiplier_str = captures.get(3).unwrap().as_str();
                let multiplier = match multiplier_str {
                    "K" => 1024,
                    "M" => 1024 * 1024,
                    _ => 1,
                };
                let sector_size = captures
                    .get(2)
                    .unwrap()
                    .as_str()
                    .parse::<u32>()
                    .unwrap_or_default()
                    * multiplier;

                let sector_type = captures.get(4).unwrap().as_str();
                let readable = matches!(sector_type, "a" | "c" | "e" | "g");
                let writable = matches!(sector_type, "d" | "e" | "f" | "g");
                let erasable = matches!(sector_type, "b" | "c" | "f" | "g");

                let region = MemorySegmentRegion {
                    start_address: address,
                    end_address: address + sector_count * sector_size - 1,
                    sector_count,
                    sector_size,
                    readable,
                    writable,
                    erasable,
                };

                regions.push(region);

                address += sector_count * sector_size;
            }
        }

        Self { name, regions }
    }
/// Creates a new segment by parsing the string descriptor
Creates a new segment by parsing the string descriptor
Creates a new segment by parsing the string descriptor
pub fn from_string_desc<T: AsRef<str>>(string_desc: T) -> Self {
        let mut regions = Vec::new();
        let mut parts: Vec<&str> = string_desc.as_ref().split('/').collect();
        // Strip of the @ at the beginning and remove trailing spaces
        let name = String::from(parts.remove(0)).trim()[1..].to_string();
        let re = regex::Regex::new(r"(\d*)\*(\d*)(\D)(\w)").unwrap();
        while parts.len() >= 2 {
            let address_str = parts.remove(0).trim_start_matches("0x");
            let mut address = u32::from_str_radix(address_str, 16).unwrap_or_default();
            let mut sectors_str: Vec<&str> = parts.remove(0).split(',').collect();
            while !sectors_str.is_empty() {
                let sector_str = sectors_str.remove(0);
                let captures = re.captures(sector_str).unwrap();
                let sector_count = captures
                    .get(1)
                    .unwrap()
                    .as_str()
                    .parse::<u32>()
                    .unwrap_or_default();
                let multiplier_str = captures.get(3).unwrap().as_str();
                let multiplier = match multiplier_str {
                    "K" => 1024,
                    "M" => 1024 * 1024,
                    _ => 1,
                };
                let sector_size = captures
                    .get(2)
                    .unwrap()
                    .as_str()
                    .parse::<u32>()
                    .unwrap_or_default()
                    * multiplier;
                let sector_type = captures.get(4).unwrap().as_str();
                let readable = matches!(sector_type, "a" | "c" | "e" | "g");
                let writable = matches!(sector_type, "d" | "e" | "f" | "g");
                let erasable = matches!(sector_type, "b" | "c" | "f" | "g");
                let region = MemorySegmentRegion {
                    start_address: address,
                    end_address: address + sector_count * sector_size - 1,
                    sector_count,
                    sector_size,
                    readable,
                    writable,
                    erasable,
                };
                regions.push(region);
                address += sector_count * sector_size;
            }
        }
        Self { name, regions }
    }
pub fn from_string_desc < T : AsRef < str > > ( string_desc : T ) -> Self { let mut regions = Vec :: new ( ) ; let mut parts : Vec < & str > = string_desc . as_ref ( ) . split ( '/' ) . collect ( ) ; // Strip of the @ at the beginning and remove trailing spaces let name = String :: from ( parts . remove ( 0 ) ) . trim ( ) [ 1 .. ] . to_string ( ) ; let re = regex :: Regex :: new ( r"(\d*)\*(\d*)(\D)(\w)" ) . unwrap ( ) ; while parts . len ( ) >= 2 { let address_str = parts . remove ( 0 ) . trim_start_matches ( " " ) ; let mut address = u32 :: from_str_radix ( address_str , 16 ) . unwrap_or_default ( ) ; let mut sectors_str : Vec < & str > = parts . remove ( 0 ) . split ( ',' ) . collect ( ) ; while ! sectors_str . is_empty ( ) { let sector_str = sectors_str . remove ( 0 ) ; let captures = re . captures ( sector_str ) . unwrap ( ) ; let sector_count = captures . get ( 1 ) . unwrap ( ) . as_str ( ) . parse :: < u32 > ( ) . unwrap_or_default ( ) ; let multiplier_str = captures . get ( 3 ) . unwrap ( ) . as_str ( ) ; let multiplier = match multiplier_str { " " => 1024 , " " => 1024 * 1024 , _ => 1 , } ; let sector_size = captures . get ( 2 ) . unwrap ( ) . as_str ( ) . parse :: < u32 > ( ) . unwrap_or_default ( ) * multiplier ; let sector_type = captures . get ( 4 ) . unwrap ( ) . as_str ( ) ; let readable = matches ! ( sector_type " " " " " " " " ) ; let writable = matches ! ( sector_type " " " " " " " " ) ; let erasable = matches ! ( sector_type " " " " " " " " ) ; let region = MemorySegmentRegion { start_address : address , end_address : address + sector_count * sector_size - 1 , sector_count , sector_size , readable , writable , erasable , } ; regions . push ( region ) ; address += sector_count * sector_size ; } } Self { name , regions } }
Creates a new segment by parsing the string descriptor
Creates a new segment by parsing the string descriptor
string_desc
T