--- parser3/src/main/pa_string.C 2001/02/13 10:00:27 1.19 +++ parser3/src/main/pa_string.C 2001/02/13 10:50:23 1.22 @@ -1,5 +1,5 @@ /* - $Id: pa_string.C,v 1.19 2001/02/13 10:00:27 paf Exp $ + $Id: pa_string.C,v 1.22 2001/02/13 10:50:23 paf Exp $ */ #include @@ -7,6 +7,7 @@ #include "pa_pool.h" #include "pa_string.h" #include "pa_hash.h" +#include "pa_exception.h" // String @@ -208,73 +209,113 @@ bool String::operator == (const String& } String& String::append(const String_iterator& begin, const String_iterator& end) { - return z; + //TODO + return *this; } -// 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), - offset(0), - feof(astring.size()==0), - read_here(astring.head.rows), - link_row(astring.preallocated_link) { +String_iterator::String_iterator(String& astring) : string(astring) { + read_here=string.head.rows; + position=string.size()==0?0:read_here->item.ptr; + link_row=reinterpret_cast(string.head.preallocated_link); } -char String_iterator::operator() { - return feof?0:read_here->item.ptr[offset]; +char String_iterator::operator()() const { + return position?*position:0; } void String_iterator::skip() { - if(feof) + if(!position) return; - if(++offset==read_here->item.size) { + if(++position== + read_here->item.ptr+ + read_here->item.size) { + + // next row if(++read_here==string.append_here) { - feof=true; + position=0; return; } - offset=0; if(read_here==link_row) { - Chunk *chunk=link_row->link; + String::Chunk *chunk=link_row->link; if(!chunk) - string.pool.exception().raise( + string.pool.exception().raise(0, 0, + &string, "String_iterator::skip() missed " "read_here==string.append_here check"); read_here=chunk->rows; - link_row=chunk->rows[chunk->count]; + link_row=&chunk->rows[chunk->count]; } + position=read_here->item.ptr; } } bool String_iterator::skip_to(char c) { - for(; !feof; skip()) - if(operator()==c) + if(!position) + return false; + + while(true) { + if(char *found=static_cast( + memchr(position, c, read_here->item.size-(position-read_here->item.ptr)))) { + position=found; return true; - return false; + } + + // next row + if(++read_here==string.append_here) { + position=0; + return false; + } + if(read_here==link_row) { + String::Chunk *chunk=link_row->link; + if(!chunk) + string.pool.exception().raise(0, 0, + &string, + "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) { - for(; !feof; skip()) - if(char type=types.get(operator())) - return type; - return 0; +int String_iterator::skip_to(Char_types& types) { + if(!position) + return false; + + while(true) { + int countdown=read_here->item.size-(position-read_here->item.ptr); + for(; countdown--; position++) + if(int type=types.get(*position)) + return type; + + // next row + if(++read_here==string.append_here) { + position=0; + return -1; + } + if(read_here==link_row) { + String::Chunk *chunk=link_row->link; + if(!chunk) + string.pool.exception().raise(0, 0, + &string, + "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; + } }