--- parser3/src/main/pa_string.C 2001/02/12 13:26:55 1.18 +++ parser3/src/main/pa_string.C 2001/02/13 10:30:22 1.21 @@ -1,5 +1,5 @@ /* - $Id: pa_string.C,v 1.18 2001/02/12 13:26:55 paf Exp $ + $Id: pa_string.C,v 1.21 2001/02/13 10:30:22 paf Exp $ */ #include @@ -211,10 +211,117 @@ String& String::append(const String_iter return z; } -// Char_set +// Char_types -Char_set::Char_set() { - memset(bools, 0, sizeof(bools)); +Char_types::Char_types() { + memset(types, 0, sizeof(types)); } // String_iterator + + // home string + String& string; + // the row in which we are + Chunk::Row *read_here; + // position in that row's string fragment + int offset; + // when read_here reaches this row, move to the next chunk + Chunk::Row *link_row; + + bool feof; + +String_iterator::String_iterator(String& astring) : string(astring) { + read_here=string.head.rows; + position=string.size()==0?0:read_here->item.ptr; + link_row=string.preallocated_link; +} + +char String_iterator::operator() { + return position?*position:0; +} + +void String_iterator::skip() { + if(!position) + return; + + if(++position== + read_here->item.ptr+ + read_here->item.size) { + + // next row + if(++read_here==string.append_here) { + feof=true; + return; + } + if(read_here==link_row) { + Chunk *chunk=link_row->link; + if(!chunk) + string.pool.exception().raise( + "String_iterator::skip() missed " + "read_here==string.append_here check"); + + read_here=chunk->rows; + link_row=chunk->rows[chunk->count]; + } + position=read_here->item.ptr; + } +} + +bool String_iterator::skip_to(char c) { + if(!position) + return false; + + while(true) { + if(char *found=static_cast( + memchr(ptr, c, read_here->size-(position-read_here->ptr)))) { + position=found; + return true; + } + + // next row + if(++read_here==string.append_here) { + position=0; + return false; + } + if(read_here==link_row) { + Chunk *chunk=link_row->link; + if(!chunk) + string.pool.exception().raise( + "String_iterator::skip_to(char) missed " + "read_here==string.append_here check"); + + read_here=chunk->rows; + link_row=chunk->rows[chunk->count]; + } + position=read_here->item.ptr; + } +} + +int String_iterator::skip_to(Char_type& types) { + if(!position) + return false; + + while(true) { + int countdown=read_here->size-(position-read_here->ptr))); + for(; countdown--; position++) + if(int type=types.get(*position)) + return type; + + // next row + if(++read_here==string.append_here) { + position=0; + return 0; + } + if(read_here==link_row) { + Chunk *chunk=link_row->link; + if(!chunk) + string.pool.exception().raise( + "String_iterator::skip_to(Char_type) missed " + "read_here==string.append_here check"); + + read_here=chunk->rows; + link_row=chunk->rows[chunk->count]; + } + position=read_here->item.ptr; + } +}