--- parser3/src/main/pa_string.C 2001/02/11 11:27:25 1.17 +++ parser3/src/main/pa_string.C 2001/02/13 10:50:23 1.22 @@ -1,5 +1,5 @@ /* - $Id: pa_string.C,v 1.17 2001/02/11 11:27:25 paf Exp $ + $Id: pa_string.C,v 1.22 2001/02/13 10:50:23 paf Exp $ */ #include @@ -7,6 +7,9 @@ #include "pa_pool.h" #include "pa_string.h" #include "pa_hash.h" +#include "pa_exception.h" + +// String String::String(Pool& apool) : Pooled(apool) { @@ -204,3 +207,115 @@ bool String::operator == (const String& } return a_break==b_break; } + +String& String::append(const String_iterator& begin, const String_iterator& end) { + //TODO + return *this; +} + +// Char_types + +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; + } +}