|
|
| version 1.18, 2024/10/17 22:24:44 | version 1.22, 2024/10/23 16:41:11 |
|---|---|
| Line 544 static void _right(Request& r, MethodPar | Line 544 static void _right(Request& r, MethodPar |
| if(sn>0){ | if(sn>0){ |
| size_t used=GET_SELF(r, VArray).array().used(); | size_t used=GET_SELF(r, VArray).array().used(); |
| if(sn<used){ | if((size_t)sn<used){ |
| mid(r, used-sn, sn); | mid(r, used-sn, sn); |
| } else { | } else { |
| mid(r); | mid(r); |
| Line 555 static void _right(Request& r, MethodPar | Line 555 static void _right(Request& r, MethodPar |
| } | } |
| static void _mid(Request& r, MethodParams& params) { | static void _mid(Request& r, MethodParams& params) { |
| const String& string=GET_SELF(r, VString).string(); | |
| int begin=params.as_int(0, "p must be int", r); | int begin=params.as_int(0, "p must be int", r); |
| if(begin<0) | if(begin<0) |
| throw Exception(PARSER_RUNTIME, 0, "p(%d) must be >=0", begin); | throw Exception(PARSER_RUNTIME, 0, "p(%d) must be >=0", begin); |
| size_t end; | |
| size_t length=0; | |
| if(params.count()>1) { | if(params.count()>1) { |
| int n=params.as_int(1, "n must be int", r); | int n=params.as_int(1, "n must be int", r); |
| if(n<0) | if(n<0) |
| Line 908 static void _at(Request& r, MethodParams | Line 904 static void _at(Request& r, MethodParams |
| } | } |
| if(count && pos >= 0 && (size_t)pos < count){ | if(count && pos >= 0 && (size_t)pos < count){ |
| switch(result_type) { | if(count == array.count()){ |
| case AtResultTypeKey: | switch(result_type) { |
| { | case AtResultTypeKey: |
| for(ArrayValue::Iterator i(array); i; i.next() ){ | r.write(*new VString(*new String(pa_uitoa(pos), String::L_TAINTED))); |
| if(i.value() && !(pos--)){ | break; |
| case AtResultTypeValue: | |
| r.write(*array[pos]); | |
| break; | |
| case AtResultTypeHash: | |
| r.write(SingleElementHash(pa_uitoa(pos), array[pos])); | |
| break; | |
| } | |
| } else { | |
| for(ArrayValue::Iterator i(array); i; i.next() ){ | |
| if(i.value() && !(pos--)){ | |
| switch(result_type) { | |
| case AtResultTypeKey: | |
| r.write(*new VString(*new String(i.key(), String::L_TAINTED))); | r.write(*new VString(*new String(i.key(), String::L_TAINTED))); |
| break; | break; |
| } | case AtResultTypeValue: |
| } | |
| break; | |
| } | |
| case AtResultTypeValue: | |
| { | |
| for(ArrayValue::Iterator i(array); i; i.next() ) | |
| if(i.value() &&!(pos--)){ | |
| r.write(*i.value()); | r.write(*i.value()); |
| break; | break; |
| } | case AtResultTypeHash: |
| break; | |
| } | |
| case AtResultTypeHash: | |
| { | |
| for(ArrayValue::Iterator i(array); i; i.next() ) | |
| if(i.value() &&!(pos--)){ | |
| r.write(SingleElementHash(i.key(), i.value())); | r.write(SingleElementHash(i.key(), i.value())); |
| break; | break; |
| } | } |
| break; | break; |
| } | } |
| } | |
| } | } |
| } | } |
| } | } |
| Line 1025 static void _select(Request& r, MethodPa | Line 1021 static void _select(Request& r, MethodPa |
| r.write(*result); | r.write(*result); |
| } | } |
| static void _reverse(Request& r, MethodParams& params) { | static void _reverse(Request& r, MethodParams&) { |
| ArrayValue& source_array=GET_SELF(r, VArray).array(); | ArrayValue& source_array=GET_SELF(r, VArray).array(); |
| VArray& result=*new VArray(source_array.count()); | VArray& result=*new VArray(source_array.count()); |
| Line 1038 static void _reverse(Request& r, MethodP | Line 1034 static void _reverse(Request& r, MethodP |
| r.write(result); | r.write(result); |
| } | } |
| static void _compact(Request& r, MethodParams&) { | |
| GET_SELF(r, VArray).array().compact(); | |
| } | |
| // constructor | // constructor |
| Line 1097 MArray::MArray(): Methoded(VARRAY_TYPE) | Line 1097 MArray::MArray(): Methoded(VARRAY_TYPE) |
| // ^array.reverse[] | // ^array.reverse[] |
| add_native_method("reverse", Method::CT_DYNAMIC, _reverse, 0, 0); | add_native_method("reverse", Method::CT_DYNAMIC, _reverse, 0, 0); |
| // ^array.compact[] | |
| add_native_method("compact", Method::CT_DYNAMIC, _compact, 0, 0); | |
| // ^array._at[first|last[;'key'|'value'|'hash']] | // ^array._at[first|last[;'key'|'value'|'hash']] |
| // ^array._at([-+]offset)[['key'|'value'|'hash']] | // ^array._at([-+]offset)[['key'|'value'|'hash']] |
| add_native_method("_at", Method::CT_DYNAMIC, _at, 1, 2); | add_native_method("_at", Method::CT_DYNAMIC, _at, 1, 2); |