Новости | FAQ | Авторы | Документация | В действии | Библиотека |
Инструменты | Полезные ссылки | Хостинги | Скачать | Примеры | Форум |
Sikoz 12.03.2005 14:49
Класс h2s предназначен для преобразования строки в хеш и обратно.@CLASS h2s #string like "$.[$.a(1)$.b[c]]" -> hash. Usage: $my_hash[^h2s:createh[$that_string]] @createh[str] ^process{^taint[as-is; ^$hash_^[$str^] ]} $result[^if($hash_ is hash){$hash_}{^hash::create[]}] #hash to option. Usage: ^h2s:h2o[$my_hash] @h2o[hash_;div] $result[^hash_.foreach[k;v]{$k}[^if(def $div){$div}{ }]] #option-like string to hash. Usage: $my_option_hash[^h2s:s2h[one|two|three;|]] @s2h[str;div][tmp;tmpt;str1] ^if(!def $div){$div[ ]} ^if($str is hash){$result[$str]}{ $tmp[^str.split[$div;v]] $tmph[^tmp.menu{^if(def $tmp.piece){$.[$tmp.piece](1)}}] } $result[^if($tmph is hash){$tmph}{^hash::create[]}] #hash to string. That hash may have only string or number values! @h2s[hash1;level][tmp;hh] $hh(^level.int(0)) ^hh.inc(1) ^hash1.foreach[k;v]{ ^if($v is hash){$tmp[^hash::create[$hash1.$k]] ^$.$k^[ ^h2s[$tmp;$hh] ]}{^$.$k^if($v is int || $v is double){($v)}{[$v]}} }