deps/kb_meme/meme-5.0.1/src/alph-in.c
/*
 * alph_reader_update
 * Update the reader with a chunk of text.
 * This will dispatch the text as lines caching any incomplete lines.
 * Comments will be removed.
 */
alph_reader_update
Update the reader with a chunk of text.
This will dispatch the text as lines caching any incomplete lines.
Comments will be removed.
alph_reader_update Update the reader with a chunk of text . This will dispatch the text as lines caching any incomplete lines . Comments will be removed .
void alph_reader_update(ALPH_READER_T *reader, const char *chunk, size_t size, bool end) {
  char value;
  bool is_nl, is_nl_start, is_comment_start;
  int i, offset;
  if (reader->is_done) die("Alphabet reader was already told the input was ended");
  offset = 0;
  for (i = 0; i < size; i++) {
    is_nl_start = false;
    is_comment_start = false;
    value = chunk[i];
    is_nl = (value == '\n' || value == '\r');
    if (reader->last_is_nl) {
      if (!is_nl) {
        reader->in_comment = false;
        reader->in_string = false; 
      } else {
        if (reader->last_value == value || !reader->last_is_nl_start) {
          reader->in_comment = false;
          reader->in_string = false; 
          is_nl_start = true;
        }
      }
    } else {
      if (is_nl) {
        is_nl_start = true;
      }
    }
    if (!reader->in_comment) {
      if (reader->in_string) {
        if (value == '"' && reader->last_value != '\\') {
          reader->in_string = false;
        }
      } else {
        if (value == '"') {
          reader->in_string = true;
        } else if (value == '#') {
          reader->in_comment = true;
          is_comment_start = true;
        }
      }
    }
    reader->last_value = value;
    reader->last_is_nl = is_nl;
    reader->last_is_nl_start = is_nl_start;
    if ((is_nl_start && !reader->in_comment) || is_comment_start) {
      str_append(reader->line, chunk+offset, (i - offset));
      alph_reader_line(reader, str_internal(reader->line));
      str_clear(reader->line);
    }
    if (is_nl) {
      offset = i + 1;
    }
  }
  if (!reader->in_comment) {
    if (end) {
      str_append(reader->line, chunk+offset, (size - offset));
      alph_reader_line(reader, str_internal(reader->line));
      str_clear(reader->line);
    } else {
      str_append(reader->line, chunk+offset, (size - offset));
    }
  }
  if (end) alph_reader_done(reader);
}
void alph_reader_update ( ALPH_READER_T * reader , const char * chunk , size_t size , bool end ) { char value ; bool is_nl , is_nl_start , is_comment_start ; int i , offset ; if ( reader -> is_done ) die ( " " ) ; offset = 0 ; for ( i = 0 ; i < size ; i ++ ) { is_nl_start = false ; is_comment_start = false ; value = chunk [ i ] ; is_nl = ( value == ' \n ' || value == ' \r ' ) ; if ( reader -> last_is_nl ) { if ( ! is_nl ) { reader -> in_comment = false ; reader -> in_string = false ; } else { if ( reader -> last_value == value || ! reader -> last_is_nl_start ) { reader -> in_comment = false ; reader -> in_string = false ; is_nl_start = true ; } } } else { if ( is_nl ) { is_nl_start = true ; } } if ( ! reader -> in_comment ) { if ( reader -> in_string ) { if ( value == ' ' && reader -> last_value != ' \\ ' ) { reader -> in_string = false ; } } else { if ( value == ' ' ) { reader -> in_string = true ; } else if ( value == ' ' ) { reader -> in_comment = true ; is_comment_start = true ; } } } reader -> last_value = value ; reader -> last_is_nl = is_nl ; reader -> last_is_nl_start = is_nl_start ; if ( ( is_nl_start && ! reader -> in_comment ) || is_comment_start ) { str_append ( reader -> line , chunk + offset , ( i - offset ) ) ; alph_reader_line ( reader , str_internal ( reader -> line ) ) ; str_clear ( reader -> line ) ; } if ( is_nl ) { offset = i + 1 ; } } if ( ! reader -> in_comment ) { if ( end ) { str_append ( reader -> line , chunk + offset , ( size - offset ) ) ; alph_reader_line ( reader , str_internal ( reader -> line ) ) ; str_clear ( reader -> line ) ; } else { str_append ( reader -> line , chunk + offset , ( size - offset ) ) ; } } if ( end ) alph_reader_done ( reader ) ; }
alph_reader_update
 Update the reader with a chunk of text.
alph_reader_update Update the reader with a chunk of text .
// split into lines // check if we've already seen a newline // see what the current char is // not a newline, so line is incremented by previous newline // strings are not multi-line // current char is a newline, so line is only incremented if  // the previous is identical char or it is not a newline beginning // previous char was a differnt newline so increment line and reset // strings are not multi-line // so by deduction the current char is a newline beginning // previous char is not a newline // so by deduction the current char is a newline beginning // check to see if we're in a string or comment // send the line up to this point // update the line parsing variables // now process the lines (with comments removed) // handle multiple lines in one chunk // store any left over text