fn read_next_string(&mut self) -> ImageResult<String> {
        let mut bytes = Vec::new();

        // pair input bytes with a bool mask to remove comments
        let mark_comments = self.bytes().scan(true, |partof, read| {
            let byte = match read {
                Err(err) => return Some((*partof, Err(err))),
                Ok(byte) => byte,
            };
            let cur_enabled = *partof && byte != b'#';
            let next_enabled = cur_enabled || (byte == b'\r' || byte == b'\n');
            *partof = next_enabled;
            Some((cur_enabled, Ok(byte)))
        });

        for (_, byte) in mark_comments.filter(|ref e| e.0) {
            match byte {
                Ok(b'\t') | Ok(b'\n') | Ok(b'\x0b') | Ok(b'\x0c') | Ok(b'\r') | Ok(b' ') => {
                    if !bytes.is_empty() {
                        break; // We're done as we already have some content
                    }
                }
                Ok(byte) => {
                    bytes.push(byte);
                }
                Err(_) => break,
            }
        }

        if bytes.is_empty() {
            return Err(ImageError::FormatError("Unexpected eof".to_string()));
        }

        if !bytes.as_slice().is_ascii() {
            return Err(ImageError::FormatError(
                "Non ascii character in preamble".to_string(),
            ));
        }

        String::from_utf8(bytes)
            .map_err(|_| ImageError::FormatError("Couldn't read preamble".to_string()))
    }
/// Reads a string as well as a single whitespace after it, ignoring comments
Reads a string as well as a single whitespace after it, ignoring comments
Reads a string as well as a single whitespace after it ignoring comments
fn read_next_string(&mut self) -> ImageResult<String> {
        let mut bytes = Vec::new();
        // pair input bytes with a bool mask to remove comments
        let mark_comments = self.bytes().scan(true, |partof, read| {
            let byte = match read {
                Err(err) => return Some((*partof, Err(err))),
                Ok(byte) => byte,
            };
            let cur_enabled = *partof && byte != b'#';
            let next_enabled = cur_enabled || (byte == b'\r' || byte == b'\n');
            *partof = next_enabled;
            Some((cur_enabled, Ok(byte)))
        });
        for (_, byte) in mark_comments.filter(|ref e| e.0) {
            match byte {
                Ok(b'\t') | Ok(b'\n') | Ok(b'\x0b') | Ok(b'\x0c') | Ok(b'\r') | Ok(b' ') => {
                    if !bytes.is_empty() {
                        break; // We're done as we already have some content
                    }
                }
                Ok(byte) => {
                    bytes.push(byte);
                }
                Err(_) => break,
            }
        }
        if bytes.is_empty() {
            return Err(ImageError::FormatError("Unexpected eof".to_string()));
        }
        if !bytes.as_slice().is_ascii() {
            return Err(ImageError::FormatError(
                "Non ascii character in preamble".to_string(),
            ));
        }
        String::from_utf8(bytes)
            .map_err(|_| ImageError::FormatError("Couldn't read preamble".to_string()))
    }
fn read_next_string ( & mut self ) -> ImageResult < String > { let mut bytes = Vec :: new ( ) ; // pair input bytes with a bool mask to remove comments let mark_comments = self . bytes ( ) . scan ( true , | partof , read | { let byte = match read { Err ( err ) => return Some ( ( * partof , Err ( err ) ) ) , Ok ( byte ) => byte , } ; let cur_enabled = * partof && byte != b'#' ; let next_enabled = cur_enabled || ( byte == b'\r' || byte == b'\n' ) ; * partof = next_enabled ; Some ( ( cur_enabled , Ok ( byte ) ) ) } ) ; for ( _ , byte ) in mark_comments . filter ( | ref e | e . 0 ) { match byte { Ok ( b'\t' ) | Ok ( b'\n' ) | Ok ( b'\x0b' ) | Ok ( b'\x0c' ) | Ok ( b'\r' ) | Ok ( b' ' ) => { if ! bytes . is_empty ( ) { break ; // We're done as we already have some content } } Ok ( byte ) => { bytes . push ( byte ) ; } Err ( _ ) => break , } } if bytes . is_empty ( ) { return Err ( ImageError :: FormatError ( " " . to_string ( ) ) ) ; } if ! bytes . as_slice ( ) . is_ascii ( ) { return Err ( ImageError :: FormatError ( " " . to_string ( ) , ) ) ; } String :: from_utf8 ( bytes ) . map_err ( | _ | ImageError :: FormatError ( " " . to_string ( ) ) ) }
Reads a string as well as a single whitespace after it, ignoring comments
Reads a string as well as a single whitespace after it ignoring comments
&mut self