|
|
| version 1.96, 2001/07/24 15:43:56 | version 1.99, 2001/08/09 16:53:27 |
|---|---|
| Line 46 String::String(const String& src) : | Line 46 String::String(const String& src) : |
| size_t src_used_rows=src.fused_rows; | size_t src_used_rows=src.fused_rows; |
| if(src_used_rows<=head.count) { | if(src_used_rows<=head.count) { |
| // all new rows fit size_to preallocated area | // all new rows fit size_to preallocated area |
| last_chunk=&head; | |
| size_t curr_chunk_rows=head.count; | size_t curr_chunk_rows=head.count; |
| memcpy(head.rows, src.head.rows, sizeof(Chunk::Row)*src_used_rows); | memcpy(head.rows, src.head.rows, sizeof(Chunk::Row)*src_used_rows); |
| append_here=&head.rows[src_used_rows]; | append_here=&head.rows[src_used_rows]; |
| Line 64 String::String(const String& src) : | Line 65 String::String(const String& src) : |
| memcpy(head.rows, src.head.rows, sizeof(Chunk::Row)*head.count); | memcpy(head.rows, src.head.rows, sizeof(Chunk::Row)*head.count); |
| // remaining rows size_to new_chunk | // remaining rows size_to new_chunk |
| size_t curr_chunk_rows=src_used_rows-head.count; | size_t curr_chunk_rows=src_used_rows-head.count; |
| Chunk *new_chunk=static_cast<Chunk *>( | last_chunk=static_cast<Chunk *>( |
| malloc(sizeof(size_t)+sizeof(Chunk::Row)*curr_chunk_rows+sizeof(Chunk *))); | malloc(sizeof(size_t)+sizeof(Chunk::Row)*curr_chunk_rows+sizeof(Chunk *))); |
| new_chunk->count=curr_chunk_rows; | last_chunk->count=curr_chunk_rows; |
| head.preallocated_link=new_chunk; | head.preallocated_link=last_chunk; |
| append_here=link_row=&new_chunk->rows[new_chunk->count]; | append_here=link_row=&last_chunk->rows[last_chunk->count]; |
| Chunk *old_chunk=src.head.preallocated_link; | Chunk *old_chunk=src.head.preallocated_link; |
| Chunk::Row *new_rows=new_chunk->rows; | Chunk::Row *new_rows=last_chunk->rows; |
| size_t rows_left_to_copy=new_chunk->count; | size_t rows_left_to_copy=last_chunk->count; |
| while(true) { | while(true) { |
| size_t old_count=old_chunk->count; | size_t old_count=old_chunk->count; |
| Chunk *next_chunk=old_chunk->rows[old_count].link; | Chunk *next_chunk=old_chunk->rows[old_count].link; |
| Line 149 String& String::real_append(STRING_APPEN | Line 150 String& String::real_append(STRING_APPEN |
| return *this; | return *this; |
| } | } |
| char String::first_char() const { | |
| if(!fused_rows) | |
| THROW(0, 0, | |
| this, | |
| "getting first char of empty string"); | |
| return *head.rows[0].item.ptr; | |
| } | |
| uint String::hash_code() const { | uint String::hash_code() const { |
| uint result=0; | uint result=0; |
| Line 647 double String::as_double() const { | Line 657 double String::as_double() const { |
| const char *cstr=this->cstr(); | const char *cstr=this->cstr(); |
| char *error_pos=0; | char *error_pos=0; |
| // 0xABC | // 0xABC |
| if(cstr[0]=='0' && (cstr[1]=='x' || cstr[1]=='X')) | if(cstr[0]=='0') |
| result=(double)(unsigned long)strtol(cstr, &error_pos, 0); | if(cstr[1]=='x' || cstr[1]=='X') |
| result=(double)(unsigned long)strtol(cstr, &error_pos, 0); | |
| else | |
| result=(double)strtod(/*skip leading 0*/++cstr, &error_pos); | |
| else | else |
| result=strtod(cstr, &error_pos); | result=(double)strtod(cstr, &error_pos); |
| if(error_pos && *error_pos) | if(error_pos && *error_pos) |
| THROW(0, 0, | THROW(0, 0, |
| Line 664 int String::as_int() const { | Line 677 int String::as_int() const { |
| const char *cstr=this->cstr(); | const char *cstr=this->cstr(); |
| char *error_pos=0; | char *error_pos=0; |
| // 0xABC | // 0xABC |
| if(cstr[0]=='0' && (cstr[1]=='x' || cstr[1]=='X')) | if(cstr[0]=='0') |
| result=(int)(unsigned long)strtol(cstr, &error_pos, 0); | if(cstr[1]=='x' || cstr[1]=='X') |
| result=(int)(unsigned long)strtol(cstr, &error_pos, 0); | |
| else | |
| result=(int)strtol(/*skip leading 0*/++cstr, &error_pos, 0); | |
| else | else |
| result=(int)strtol(cstr, &error_pos, 0); | result=(int)strtol(cstr, &error_pos, 0); |