--- parser3/src/main/pa_string.C 2001/05/15 14:31:58 1.83 +++ parser3/src/main/pa_string.C 2001/05/23 08:57:39 1.91 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_string.C,v 1.83 2001/05/15 14:31:58 parser Exp $ + $Id: pa_string.C,v 1.91 2001/05/23 08:57:39 parser Exp $ */ #include "pa_config_includes.h" @@ -21,22 +21,9 @@ #include "pa_array.h" #include "pa_globals.h" #include "pa_table.h" -#include "pa_threads.h" - -#include "pa_sapi.h" -#define STRING_STAT_MAX_PIECES 1000 -int string_stat_pieces[STRING_STAT_MAX_PIECES]; -void log_string_stats(Pool& pool) { - for(int i=0; icount+last_chunk->count*CR_GROW_PERCENT/100; + size_t new_chunk_count=last_chunk->count+CR_GROW_COUNT; last_chunk=static_cast( malloc(sizeof(size_t)+sizeof(Chunk::Row)*new_chunk_count+sizeof(Chunk *))); last_chunk->count=new_chunk_count; @@ -70,7 +50,6 @@ void String::expand() { } String::String(const String& src) : Pooled(src.pool()) { - string_stat_pieces[0]++; head.count=CR_PREALLOCATED_COUNT; size_t src_used_rows=src.fused_rows; @@ -207,7 +186,7 @@ int String::cmp(int& partial, const Stri size_t pos=0; bool a_break=size()==0; - bool b_break=size()==0; + bool b_break=src.size()==0; if(!(a_break || b_break)) while(true) { if(pos+a_row->item.size > this_offset) { if(lang!=UL_UNSPECIFIED && a_row->item.lang!=lang) @@ -328,7 +307,8 @@ int String::cmp(int& partial, const char a_row++; a_countdown--; } - if(a_break=a_row==a_end) + a_break=a_row==a_end; + if(a_break || b_break) break; if(!a_countdown) { a_chunk=a_row->link; @@ -505,6 +485,7 @@ static void regex_options(char *options, } } +/// @todo maybe need speedup: some option to remove pre/match/post string generation bool String::match(const unsigned char *pcre_tables, const String *aorigin, const String& regexp, @@ -655,3 +636,38 @@ break2: return result; } + +double String::as_double() const { + double result; + const char *cstr=this->cstr(); + char *error_pos=0; + // 0xABC + if(cstr[0]=='0' && (cstr[1]=='x' || cstr[1]=='X')) + result=(double)(unsigned long)strtol(cstr, &error_pos, 0); + else + result=strtod(cstr, &error_pos); + + if(error_pos && *error_pos) + THROW(0, 0, + this, + "invalid number (double)"); + + return result; +} +int String::as_int() const { + int result; + const char *cstr=this->cstr(); + char *error_pos=0; + // 0xABC + if(cstr[0]=='0' && (cstr[1]=='x' || cstr[1]=='X')) + result=(int)(unsigned long)strtol(cstr, &error_pos, 0); + else + result=(int)strtol(cstr, &error_pos, 0); + + if(error_pos && *error_pos) + THROW(0, 0, + this, + "invalid number (int)"); + + return result; +}