|
|
| version 1.35, 2001/04/04 10:50:33 | version 1.40, 2001/04/26 14:55:13 |
|---|---|
| Line 22 VStateless_class *string_class; | Line 22 VStateless_class *string_class; |
| // methods | // methods |
| static void _length(Request& r, const String&, Array *) { | static void _length(Request& r, const String&, MethodParams *) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Value& value=*new(pool) VDouble(pool, r.self->get_string()->size()); | Value& value=*new(pool) VDouble(pool, r.self->get_string()->size()); |
| r.write_no_lang(value); | r.write_no_lang(value); |
| } | } |
| static void _int(Request& r, const String&, Array *) { | static void _int(Request& r, const String&, MethodParams *) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Value& value=*new(pool) VInt(pool, (int)r.self->as_double()); | Value& value=*new(pool) VInt(pool, (int)r.self->as_double()); |
| r.write_no_lang(value); | r.write_no_lang(value); |
| } | } |
| static void _double(Request& r, const String&, Array *) { | static void _double(Request& r, const String&, MethodParams *) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Value& value=*new(pool) VDouble(pool, r.self->as_double()); | Value& value=*new(pool) VDouble(pool, r.self->as_double()); |
| r.write_no_lang(value); | r.write_no_lang(value); |
| } | } |
| /// ^string.format{format} | /// ^string.format{format} |
| /*not static*/void _string_format(Request& r, const String& method_name, Array *params) { | /*not static*/void _string_format(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Value& fmt=*static_cast<Value *>(params->get(0)); | Value& fmt=params->get_junction(0, "fmt must be code"); |
| // forcing {this param type} | |
| r.fail_if_junction_(false, fmt, method_name, "fmt must be junction"); | |
| Temp_lang temp_lang(r, String::UL_PASS_APPENDED); | Temp_lang temp_lang(r, String::UL_PASS_APPENDED); |
| char *buf=format(pool, r.self->as_double(), r.process(fmt).as_string().cstr()); | char *buf=format(pool, r.self->as_double(), r.process(fmt).as_string().cstr()); |
| Line 54 static void _double(Request& r, const St | Line 52 static void _double(Request& r, const St |
| r.write_no_lang(String(pool, buf)); | r.write_no_lang(String(pool, buf)); |
| } | } |
| static void _left(Request& r, const String&, Array *params) { | static void _left(Request& r, const String&, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| size_t n=(size_t)r.process(*static_cast<Value *>(params->get(0))).as_double(); | size_t n=(size_t)r.process(params->get(0)).as_double(); |
| const String& string=*static_cast<VString *>(r.self)->get_string(); | const String& string=*static_cast<VString *>(r.self)->get_string(); |
| r.write_assign_lang(*new(pool) VString(string.mid(0, n))); | r.write_assign_lang(*new(pool) VString(string.mid(0, n))); |
| } | } |
| static void _right(Request& r, const String&, Array *params) { | static void _right(Request& r, const String&, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| size_t n=(size_t)r.process(*static_cast<Value *>(params->get(0))).as_double(); | size_t n=(size_t)r.process(params->get(0)).as_double(); |
| const String& string=*static_cast<VString *>(r.self)->get_string(); | const String& string=*static_cast<VString *>(r.self)->get_string(); |
| r.write_assign_lang(*new(pool) VString(string.mid(string.size()-n, string.size()))); | r.write_assign_lang(*new(pool) VString(string.mid(string.size()-n, string.size()))); |
| } | } |
| static void _mid(Request& r, const String&, Array *params) { | static void _mid(Request& r, const String&, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| size_t p=(size_t)r.process(*static_cast<Value *>(params->get(0))).as_double(); | size_t p=(size_t)r.process(params->get(0)).as_double(); |
| size_t n=(size_t)r.process(*static_cast<Value *>(params->get(1))).as_double(); | size_t n=(size_t)r.process(params->get(1)).as_double(); |
| const String& string=*static_cast<VString *>(r.self)->get_string(); | const String& string=*static_cast<VString *>(r.self)->get_string(); |
| r.write_assign_lang(*new(pool) VString(string.mid(p, p+n))); | r.write_assign_lang(*new(pool) VString(string.mid(p, p+n))); |
| } | } |
| static void _pos(Request& r, const String& method_name, Array *params) { | static void _pos(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Value& substr=*static_cast<Value *>(params->get(0)); | Value& substr=params->get_no_junction(0, "substr must not be code"); |
| // forcing [this param type] | |
| r.fail_if_junction_(true, substr, method_name, "substr must not be junction"); | |
| const String& string=*static_cast<VString *>(r.self)->get_string(); | const String& string=*static_cast<VString *>(r.self)->get_string(); |
| r.write_assign_lang(*new(pool) VInt(pool, string.pos(substr.as_string()))); | r.write_assign_lang(*new(pool) VInt(pool, string.pos(substr.as_string()))); |
| } | } |
| static void split_list(Request& r, const String& method_name, Array *params, | static void split_list(Request& r, const String& method_name, MethodParams *params, |
| const String& string, | const String& string, |
| Array& result) { | Array& result) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Value& delim_value=*static_cast<Value *>(params->get(0)); | Value& delim_value=params->get_no_junction(0, "delimiter must not be code"); |
| // forcing [this param type] | |
| r.fail_if_junction_(true, delim_value, method_name, "delimiter must not be junction"); | |
| string.split(result, 0, delim_value.as_string(), String::UL_CLEAN, -1); | string.split(result, 0, delim_value.as_string(), String::UL_CLEAN, -1); |
| } | } |
| static void _lsplit(Request& r, const String& method_name, Array *params) { | static void _lsplit(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| const String& string=*static_cast<VString *>(r.self)->get_string(); | const String& string=*static_cast<VString *>(r.self)->get_string(); |
| Line 119 static void _lsplit(Request& r, const St | Line 113 static void _lsplit(Request& r, const St |
| r.write_no_lang(*new(pool) VTable(pool, &table)); | r.write_no_lang(*new(pool) VTable(pool, &table)); |
| } | } |
| static void _rsplit(Request& r, const String& method_name, Array *params) { | static void _rsplit(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| const String& string=*static_cast<VString *>(r.self)->get_string(); | const String& string=*static_cast<VString *>(r.self)->get_string(); |
| Line 142 static void search_action(Table& table, | Line 136 static void search_action(Table& table, |
| table+=row; | table+=row; |
| } | } |
| /// used by string: _match / replace_action | |
| struct Replace_action_info { | struct Replace_action_info { |
| Request *request; const String *origin; | Request *request; const String *origin; |
| const String *src; String *dest; | const String *src; String *dest; |
| Line 154 static void replace_action(Table& table, | Line 149 static void replace_action(Table& table, |
| if(row) { // begin&middle | if(row) { // begin&middle |
| // piece from last match['start'] to beginning of this match['finish'] | // piece from last match['start'] to beginning of this match['finish'] |
| if(start!=finish) | if(start!=finish) |
| ai.dest->append(ai.src->mid(start, finish), String::UL_PASS_APPENDED);//ai.dest->APPEND_CONST("-"); | *ai.dest << ai.src->mid(start, finish);//ai.dest->APPEND_CONST("-"); |
| // store found parts in one-record Vtable | // store found parts in one-record Vtable |
| if(table.size()) // middle | if(table.size()) // middle |
| table.put(0, row); | table.put(0, row); |
| Line 170 static void replace_action(Table& table, | Line 165 static void replace_action(Table& table, |
| /* | /* |
| ai.dest->APPEND_CONST("("); | ai.dest->APPEND_CONST("("); |
| ai.dest->append(*(String *)row->get(1/*match* /), String::UL_PASS_APPENDED); | *ai.dest << *(String *)row->get(1/*match* /); |
| ai.dest->APPEND_CONST(")"); | ai.dest->APPEND_CONST(")"); |
| */ | */ |
| ai.dest->append(replaced.as_string(), String::UL_PASS_APPENDED); | *ai.dest << replaced.as_string(); |
| } | } |
| ai.post_match=(String *)row->get(2/*post_match*/); | ai.post_match=(String *)row->get(2/*post_match*/); |
| } else // end | } else // end |
| ai.dest->append(*ai.post_match, String::UL_PASS_APPENDED); | *ai.dest << *ai.post_match; |
| } | } |
| /** search/replace | /** search/replace |
| ^string.match[regexp][options] | ^string.match[regexp][options] |
| ^string.match[regexp][options]{replacement-code} | ^string.match[regexp][options]{replacement-code} |
| */ | */ |
| static void _match(Request& r, const String& method_name, Array *params) { | static void _match(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| const String& src=*static_cast<VString *>(r.self)->get_string(); | const String& src=*static_cast<VString *>(r.self)->get_string(); |
| Value& regexp=*static_cast<Value *>(params->get(0)); | Value& regexp=params->get_no_junction(0, "regexp must not be code"); |
| // forcing [this param type] | |
| r.fail_if_junction_(true, regexp, method_name, "regexp must not be junction"); | const String *options= |
| params->size()>1? | |
| const String *options=0; | ¶ms->get_no_junction(1, "options must not be code").as_string():0; |
| if(params->size()>1) { | |
| Value& value=*static_cast<Value *>(params->get(1)); | |
| // forcing {this param type} | |
| r.fail_if_junction_(true, value, method_name, "options must not be junction"); | |
| options=&value.as_string(); | |
| } | |
| Value *result; | Value *result; |
| Temp_lang temp_lang(r, String::UL_PASS_APPENDED); | Temp_lang temp_lang(r, String::UL_PASS_APPENDED); |
| Table *table; | Table *table; |
| if(params->size()<3) { // search | if(params->size()<3) { // search |
| if(src.match(&method_name, | if(src.match(r.pcre_tables, |
| &method_name, | |
| regexp.as_string(), options, | regexp.as_string(), options, |
| &table, | &table, |
| search_action, 0)) { | search_action, 0)) { |
| Line 217 static void _match(Request& r, const Str | Line 207 static void _match(Request& r, const Str |
| } else // not matched [not global] | } else // not matched [not global] |
| result=new(pool) VBool(pool, false); | result=new(pool) VBool(pool, false); |
| } else { // replace | } else { // replace |
| Value& replacement_code=*static_cast<Value *>(params->get(2)); | Value& replacement_code=params->get_junction(2, "replacement code must be code"); |
| // forcing {this param type} | |
| r.fail_if_junction_(false, replacement_code, | |
| method_name, "replacement code must be junction"); | |
| String& dest=*new(pool) String(pool); | String& dest=*new(pool) String(pool); |
| Replace_action_info replace_action_info={ | Replace_action_info replace_action_info={ |
| Line 229 static void _match(Request& r, const Str | Line 216 static void _match(Request& r, const Str |
| &replacement_code, | &replacement_code, |
| &src | &src |
| }; | }; |
| src.match(&method_name, | src.match(r.pcre_tables, |
| &method_name, | |
| r.process(regexp).as_string(), options, | r.process(regexp).as_string(), options, |
| &table, | &table, |
| replace_action, &replace_action_info); | replace_action, &replace_action_info); |