|
|
| version 1.7, 2024/09/21 15:23:23 | version 1.9, 2024/09/22 17:01:23 |
|---|---|
| Line 74 static ArrayValue::Action_options get_ac | Line 74 static ArrayValue::Action_options get_ac |
| if(Value* voffset=options->get(sql_offset_name)) { | if(Value* voffset=options->get(sql_offset_name)) { |
| valid_options++; | valid_options++; |
| result.offset=r.process(*voffset).as_int(); | int offset=r.process(*voffset).as_int(); |
| result.offset=offset < 0 ? 0 : offset; | |
| } | } |
| if(Value* vlimit=options->get(sql_limit_name)) { | if(Value* vlimit=options->get(sql_limit_name)) { |
| valid_options++; | valid_options++; |
| result.limit=r.process(*vlimit).as_int(); | int limit=r.process(*vlimit).as_int(); |
| result.limit=limit < 0 ? 0: limit; | |
| } | } |
| if(valid_options!=options->count()) | if(valid_options!=options->count()) |
| Line 141 static void _join(Request& r, MethodPara | Line 143 static void _join(Request& r, MethodPara |
| static void _sql(Request& r, MethodParams& params) {} | static void _sql(Request& r, MethodParams& params) {} |
| static void _sub(Request& r, MethodParams& params) {} | |
| static void _union(Request& r, MethodParams& params) {} | static void mid(Request& r, ArrayValue::Action_options o) { |
| ArrayValue& array=GET_SELF(r, VArray).array(); | |
| if(o.limit>0){ | |
| VArray *result=new VArray; | |
| ArrayValue& result_array=result->array(); | |
| for(ArrayValue::Iterator i(array); i; i.next()){ | |
| if(i.value()){ | |
| if(o.offset > 0){ | |
| o.offset--; | |
| continue; | |
| } | |
| if(o.limit-- == 0) | |
| break; | |
| result_array+=i.value(); | |
| } | |
| } | |
| r.write(*result); | |
| } else { | |
| r.write(*new VArray); | |
| } | |
| } | |
| static void _intersection(Request& r, MethodParams& params) {} | static void _left(Request& r, MethodParams& params) { |
| int sn=params.as_int(0, "n must be int", r); | |
| mid(r, ArrayValue::Action_options(0, sn < 0 ? 0 : sn)); | |
| } | |
| static void _right(Request& r, MethodParams& params) { | |
| int sn=params.as_int(0, "n must be int", r); | |
| if(sn>0){ | |
| size_t used=GET_SELF(r, VArray).array().used(); | |
| if(sn<used){ | |
| mid(r, ArrayValue::Action_options(used-sn, sn)); | |
| } else { | |
| mid(r, ArrayValue::Action_options()); | |
| } | |
| } else { | |
| mid(r, ArrayValue::Action_options(0, 0)); | |
| } | |
| } | |
| 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); | |
| if(begin<0) | |
| throw Exception(PARSER_RUNTIME, 0, "p(%d) must be >=0", begin); | |
| size_t end; | |
| size_t length=0; | |
| static void _intersects(Request& r, MethodParams& params) {} | if(params.count()>1) { |
| int n=params.as_int(1, "n must be int", r); | |
| if(n<0) | |
| throw Exception(PARSER_RUNTIME, 0, "n(%d) must be >=0", n); | |
| mid(r, ArrayValue::Action_options(begin, n)); | |
| } else { | |
| mid(r, ArrayValue::Action_options(begin)); | |
| } | |
| } | |
| static void _keys(Request& r, MethodParams& params) { | static void _keys(Request& r, MethodParams& params) { |
| const String* keys_column_name; | const String* keys_column_name; |
| Line 205 static void _insert(Request& r, MethodPa | Line 262 static void _insert(Request& r, MethodPa |
| size_t index=VArray::index(params.as_int(0, PARAM_INDEX, r)); | size_t index=VArray::index(params.as_int(0, PARAM_INDEX, r)); |
| for(int i=1; i<count; i++){ | for(int i=1; i<count; i++){ |
| array.insert(index+i-1, &r.process(params[i])); | array.insert(index++, &r.process(params[i])); |
| } | } |
| self.invalidate(); | self.invalidate(); |
| } | } |
| Line 623 MArray::MArray(): Methoded(VARRAY_TYPE) | Line 680 MArray::MArray(): Methoded(VARRAY_TYPE) |
| // ^array.join[join_from[;options]] | // ^array.join[join_from[;options]] |
| add_native_method("join", Method::CT_DYNAMIC, _join, 1, 2); | add_native_method("join", Method::CT_DYNAMIC, _join, 1, 2); |
| // ^array.sub[sub_from] | // ^array.left(n) |
| add_native_method("sub", Method::CT_DYNAMIC, _sub, 1, 1); | add_native_method("left", Method::CT_DYNAMIC, _left, 1, 1); |
| // ^array.union[b] = array | // ^array.right(n) |
| add_native_method("union", Method::CT_DYNAMIC, _union, 1, 1); | add_native_method("right", Method::CT_DYNAMIC, _right, 1, 1); |
| // ^array.intersection[b][options array] = array | // ^array.mid(p) |
| add_native_method("intersection", Method::CT_DYNAMIC, _intersection, 1, 2); | // ^array.mid(p;n) |
| // ^array.intersects[b] = bool | add_native_method("mid", Method::CT_DYNAMIC, _mid, 1, 2); |
| add_native_method("intersects", Method::CT_DYNAMIC, _intersects, 1, 1); | |
| // ^array::new[value;value] | |
| add_native_method("new", Method::CT_DYNAMIC, _append, 0, 10000); | |
| // ^array.append[value;value] | // ^array.append[value;value] |
| add_native_method("append", Method::CT_DYNAMIC, _append, 1, 10000); | add_native_method("append", Method::CT_DYNAMIC, _append, 1, 10000); |
| // ^array.insert[index;value...] | // ^array.insert[index;value...] |