--- parser3/src/main/pa_string.C 2001/02/12 13:26:55 1.18 +++ parser3/src/main/pa_string.C 2001/02/13 10:50:23 1.22 @@ -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.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,13 +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 + +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()() const { + 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) { + position=0; + return; + } + if(read_here==link_row) { + String::Chunk *chunk=link_row->link; + if(!chunk) + 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]; + } + position=read_here->item.ptr; + } +} + +bool String_iterator::skip_to(char 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; + } + + // 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_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; + } +}