|
|
| version 1.322, 2016/09/08 16:31:35 | version 1.331, 2016/09/21 15:14:39 |
|---|---|
| Line 111 struct TableControlChars { | Line 111 struct TableControlChars { |
| if(Value* vseparator=options.get(PA_COLUMN_SEPARATOR_NAME)) { | if(Value* vseparator=options.get(PA_COLUMN_SEPARATOR_NAME)) { |
| sseparator=&vseparator->as_string(); | sseparator=&vseparator->as_string(); |
| if(sseparator->length()!=1) | if(sseparator->length()!=1) |
| throw Exception(PARSER_RUNTIME, sseparator, "separator must be one character long"); | throw Exception(PARSER_RUNTIME, sseparator, "separator must be one byte character"); |
| separator=sseparator->first_char(); | separator=sseparator->first_char(); |
| separators[0]=separator; | separators[0]=separator; |
| result++; | result++; |
| Line 121 struct TableControlChars { | Line 121 struct TableControlChars { |
| if(sencloser->is_empty()){ | if(sencloser->is_empty()){ |
| encloser=0; | encloser=0; |
| } else { | } else { |
| if(sencloser->length()!=1) | if(sencloser->length()!=1) |
| throw Exception(PARSER_RUNTIME, sencloser, "encloser must be one character long"); | throw Exception(PARSER_RUNTIME, sencloser, "encloser must be empty or one byte character"); |
| encloser=sencloser->first_char(); | encloser=sencloser->first_char(); |
| } | } |
| result++; | result++; |
| } | } |
| Line 160 public: | Line 160 public: |
| String *extract(char *pos){ | String *extract(char *pos){ |
| String *result=new String; | String *result=new String; |
| // first: their langs | if(size_t len=strlen(pos)){ |
| result->langs.append(result->body, langs, pos-base, strlen(pos)); | // first: their langs |
| // next: letters themselves | result->langs.append(result->body, langs, pos-base, len); |
| result->body=Body(pos); | // next: letters themselves |
| result->body=Body(pos); | |
| } | |
| return result; | return result; |
| } | } |
| }; | }; |
| Line 171 public: | Line 173 public: |
| inline lsplit_sresult lsplit(char* *string_ref, const char* delims, StringSplitHelper& helper) { | inline lsplit_sresult lsplit(char* *string_ref, const char* delims, StringSplitHelper& helper) { |
| lsplit_sresult result; | lsplit_sresult result; |
| if(char *pos=*string_ref) { | if(char *pos=*string_ref) { |
| while(char* v=strpbrk(pos, delims)) { | while(pos=strpbrk(pos, delims)) { |
| if(helper.check_lang(v)){ | if(helper.check_lang(pos)){ |
| result.delim=*v; | result.delim=*pos; |
| *v=0; | *pos=0; |
| result.piece=helper.extract(*string_ref); | result.piece=helper.extract(*string_ref); |
| *string_ref=v+1; | *string_ref=pos+1; |
| return result; | return result; |
| } | } |
| pos=v+1; | pos++; |
| } | } |
| result.piece=helper.extract(*string_ref); | result.piece=helper.extract(*string_ref); |
| *string_ref=0; | *string_ref=0; |
| Line 196 static lsplit_sresult lsplit(char** stri | Line 198 static lsplit_sresult lsplit(char** stri |
| // we are enclosed, searching for second encloser | // we are enclosed, searching for second encloser |
| while(1) { | while(1) { |
| if(char* v=strchr(pos, encloser)){ | if(pos=strchr(pos, encloser)){ |
| if(helper.check_lang(v)){ | if(helper.check_lang(pos)){ |
| *(v++)=0; | *(pos++)=0; |
| result.append(helper.extract(*string_ref)); | result.append(helper.extract(*string_ref)); |
| if(*v==encloser && helper.check_lang(v)){ // double-encloser stands for encloser | if(*pos==encloser && helper.check_lang(pos)){ // double-encloser stands for encloser |
| *string_ref=v+1; | *string_ref=pos++; |
| } else { | } else { |
| *string_ref=pos=v; | *string_ref=pos; |
| break; | break; |
| } | } |
| } | } |
| pos=v+1; | } else { |
| }{ | |
| result.append(helper.extract(*string_ref)); | result.append(helper.extract(*string_ref)); |
| *string_ref=0; | *string_ref=0; |
| return result; | return result; |
| Line 216 static lsplit_sresult lsplit(char** stri | Line 217 static lsplit_sresult lsplit(char** stri |
| } | } |
| // we are no longer enclosed, searching for delimiter | // we are no longer enclosed, searching for delimiter |
| while(char* v=strpbrk(pos, delims)) { | while(pos=strpbrk(pos, delims)) { |
| if(helper.check_lang(v)){ | if(helper.check_lang(pos)){ |
| result.delim=*v; | result.delim=*pos; |
| if(v>*string_ref){ | if(pos>*string_ref){ |
| *v=0; | *pos=0; |
| result.append(helper.extract(*string_ref)); | result.append(helper.extract(*string_ref)); |
| } | } |
| *string_ref=v+1; | *string_ref=pos+1; |
| return result; | return result; |
| } | } |
| pos=v+1; | pos++; |
| } | } |
| result.append(helper.extract(*string_ref)); | result.append(helper.extract(*string_ref)); |
| *string_ref=0; | *string_ref=0; |
| Line 271 static void _create(Request& r, MethodPa | Line 272 static void _create(Request& r, MethodPa |
| size_t options_param_index=data_param_index+1; | size_t options_param_index=data_param_index+1; |
| if( options_param_index<params.count() && (options=params.as_hash(options_param_index)) ) { | if( options_param_index<params.count() && (options=params.as_hash(options_param_index)) ) { |
| // cloning, so that we could change | if(control_chars.load(*options)!=options->count()) |
| options=new HashStringValue(*options); | throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); |
| control_chars.load(*options); | |
| } | } |
| // data | // data |
| Line 363 static lsplit_result lsplit(char** strin | Line 363 static lsplit_result lsplit(char** strin |
| *write++=c; | *write++=c; |
| } | } |
| // we are no longer enclosed, searching for delimiter, skipping extra enclosers | // we are no longer enclosed, searching for delimiter |
| while(c=*read++) { | while(c=*read++) { |
| if(c==delims[0] || c==delims[1]) { | if(c==delims[0] || c==delims[1]) { |
| result.delim=c; | result.delim=c; |
| break; | break; |
| } else if(c!=encloser) | } else |
| *write++=c; | *write++=c; |
| } | } |
| Line 1148 static void _flip(Request& r, MethodPara | Line 1148 static void _flip(Request& r, MethodPara |
| static void _foreach(Request& r, MethodParams& params) { | static void _foreach(Request& r, MethodParams& params) { |
| InCycle temp(r); | InCycle temp(r); |
| const String& rownum_name=params.as_string(0, "rownum-var name must be string"); | const String* rownum_var_name=¶ms.as_string(0, "rownum-var name must be string"); |
| const String& value_name=params.as_string(1, "value-var name must be string"); | const String* value_var_name=¶ms.as_string(1, "value-var name must be string"); |
| Value& body_code=params.as_junction(2, "body must be code"); | Value& body_code=params.as_junction(2, "body must be code"); |
| Line 1158 static void _foreach(Request& r, MethodP | Line 1158 static void _foreach(Request& r, MethodP |
| Table& table=GET_SELF(r, VTable).table(); | Table& table=GET_SELF(r, VTable).table(); |
| size_t saved_current=table.current(); | size_t saved_current=table.current(); |
| const String* rownum_var_name=rownum_name.is_empty()? 0 : &rownum_name; | rownum_var_name=rownum_var_name->is_empty()? 0 : rownum_var_name; |
| const String* value_var_name=value_name.is_empty()? 0 : &value_name; | value_var_name=value_var_name->is_empty()? 0 : value_var_name; |
| Value* var_context=r.get_method_frame()->caller(); | Value* var_context=r.get_method_frame()->caller(); |
| Line 1221 inline Table::element_type row_from_stri | Line 1221 inline Table::element_type row_from_stri |
| // parse cells | // parse cells |
| Table::element_type row=new ArrayString; | Table::element_type row=new ArrayString; |
| size_t pos_after=0; | string.split(*row, 0, "\t", String::L_AS_IS); |
| string.split(*row, pos_after, "\t", String::L_AS_IS); | |
| return row; | return row; |
| } | } |