--- parser3/src/classes/hash.C 2015/09/24 20:14:03 1.122 +++ parser3/src/classes/hash.C 2015/10/15 18:12:29 1.124 @@ -17,7 +17,7 @@ #include "pa_vbool.h" #include "pa_vmethod_frame.h" -volatile const char * IDENT_HASH_C="$Id: hash.C,v 1.122 2015/09/24 20:14:03 moko Exp $"; +volatile const char * IDENT_HASH_C="$Id: hash.C,v 1.124 2015/10/15 18:12:29 moko Exp $"; // class @@ -508,6 +508,7 @@ static int sort_cmp_double(const void *a return 0; } static void _sort(Request& r, MethodParams& params){ +#ifdef HASH_ORDER const String& key_var_name=params.as_string(0, "key-var name must be string"); const String& value_var_name=params.as_string(1, "value-var name must be string"); Value& key_maker=params.as_junction(2, "key-maker must be code"); @@ -564,6 +565,7 @@ static void _sort(Request& r, MethodPara hash.order_next(seq[pos].hash_pair); delete[] seq; +#endif } static void _at(Request& r, MethodParams& params) { @@ -605,11 +607,14 @@ static void _at(Request& r, MethodParams switch(result_type) { case AtResultTypeKey: { +#ifdef HASH_ORDER if(pos == 0) { r.write_assign_lang(*new VString(*new String(hash.first_key(), String::L_TAINTED))); } else if((size_t)pos == count-1) { r.write_assign_lang(*new VString(*new String(hash.last_key(), String::L_TAINTED))); - } else { + } else +#endif + { for(HashStringValue::Iterator i(hash); i; i.next(), pos-- ) if(!pos){ r.write_assign_lang(*new VString(*new String(i.key(), String::L_TAINTED))); @@ -620,11 +625,14 @@ static void _at(Request& r, MethodParams } case AtResultTypeValue: { +#ifdef HASH_ORDER if(pos == 0) { r.write_assign_lang(*hash.first_value()); } else if((size_t)pos == count-1) { r.write_assign_lang(*hash.last_value()); - } else { + } else +#endif + { for(HashStringValue::Iterator i(hash); i; i.next(), pos-- ) if(!pos){ r.write_assign_lang(*i.value()); @@ -635,11 +643,14 @@ static void _at(Request& r, MethodParams } case AtResultTypeHash: { +#ifdef HASH_ORDER if(pos == 0) { r.write_no_lang(SingleElementHash(hash.first_key(), hash.first_value())); } else if((size_t)pos == count-1) { r.write_no_lang(SingleElementHash(hash.last_key(), hash.last_value())); - } else { + } else +#endif + { for(HashStringValue::Iterator i(hash); i; i.next(), pos-- ) if(!pos){ r.write_no_lang(SingleElementHash(i.key(), i.value())); @@ -681,10 +692,10 @@ MHash::MHash(): Methoded("hash") add_native_method("sql", Method::CT_DYNAMIC, _sql, 1, 2); // ^hash._keys[[column name]] - add_native_method("_keys", Method::CT_DYNAMIC, _keys, 0, 1); + add_native_method("_keys", Method::CT_DYNAMIC, _keys, 0, 1); // ^hash._count[] - add_native_method("_count", Method::CT_DYNAMIC, _count, 0, 0); + add_native_method("_count", Method::CT_DYNAMIC, _count, 0, 0); // ^hash.foreach[key;value]{code}[delim] add_native_method("foreach", Method::CT_DYNAMIC, _foreach, 2+1, 2+1+1); @@ -696,4 +707,12 @@ MHash::MHash(): Methoded("hash") // ^hash._at[first|last[;'key'|'value'|'hash']] // ^hash._at([-+]offset)[['key'|'value'|'hash']] add_native_method("_at", Method::CT_DYNAMIC, _at, 1, 2); + +#ifdef FEATURE_GET_ELEMENT4CALL + // aliases without "_" + add_native_method("keys", Method::CT_DYNAMIC, _keys, 0, 1); + add_native_method("count", Method::CT_DYNAMIC, _count, 0, 0); + add_native_method("at", Method::CT_DYNAMIC, _at, 1, 2); +#endif + }