| | |
| | | |
| | | |
| | | /** |
| | | * Returns whether an $str is a reserved word for any of the version of Javascript or ECMAScript |
| | | * @param str String to check |
| | | * @return boolean True if $str is a reserver word, False if not |
| | | */ |
| | | function is_js_reserved_word($str) |
| | | { |
| | | return in_array($str, array( |
| | | // ECMASript ver 4 reserved words |
| | | 'as','break','case','catch','class','const','continue', |
| | | 'default','delete','do','else','export','extends','false','finally','for','function', |
| | | 'if','import','in','instanceof','is','namespace','new','null','package','private', |
| | | 'public','return','super','switch','this','throw','true','try','typeof','use','var', |
| | | 'void','while','with', |
| | | // ECMAScript ver 4 future reserved words |
| | | 'abstract','debugger','enum','goto','implements','interface','native','protected', |
| | | 'synchronized','throws','transient','volatile', |
| | | // special meaning in some contexts |
| | | 'get','set', |
| | | // were reserved in ECMAScript ver 3 |
| | | 'boolean','byte','char','double','final','float','int','long','short','static' |
| | | )); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Convert a variable into a javascript object notation |
| | | * |
| | | * @param mixed Input value |
| | |
| | | foreach ($var as $key => $value) |
| | | { |
| | | // enclose key with quotes if it is not variable-name conform |
| | | if (!ereg("^[_a-zA-Z]{1}[_a-zA-Z0-9]*$", $key) /* || is_js_reserved_word($key) */) |
| | | if (!ereg("^[_a-zA-Z]{1}[_a-zA-Z0-9]*$", $key) || is_js_reserved_word($key)) |
| | | $key = "'$key'"; |
| | | |
| | | $pairs[] = sprintf("%s%s", $is_assoc ? "$key:" : '', json_serialize($value)); |
| | |
| | | return "'".JQ($var)."'"; |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Function to convert an array to a javascript array |
| | |
| | | */ |
| | | function in_array_nocase($needle, $haystack) |
| | | { |
| | | $needle = rc_strtolower($needle); |
| | | foreach ($haystack as $value) |
| | | if (strtolower($needle)===strtolower($value)) |
| | | if ($needle===rc_strtolower($value)) |
| | | return true; |
| | | |
| | | return false; |
| | |
| | | // FIXME: the order is important, because sometimes |
| | | // iso string is detected as euc-jp and etc. |
| | | $enc = array( |
| | | 'UTF-8', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4', |
| | | 'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9', |
| | | 'ISO-8859-10', 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'ISO-8859-16', |
| | | 'WINDOWS-1252', 'WINDOWS-1251', 'EUC-JP', 'EUC-TW', 'KOI8-R' |
| | | 'UTF-8', 'SJIS', 'BIG5', 'GB2312', |
| | | 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4', |
| | | 'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9', |
| | | 'ISO-8859-10', 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'ISO-8859-16', |
| | | 'WINDOWS-1252', 'WINDOWS-1251', 'EUC-JP', 'EUC-TW', 'KOI8-R', |
| | | 'ISO-2022-KR', 'ISO-2022-JP' |
| | | ); |
| | | |
| | | $result = mb_detect_encoding($string, join(',', $enc)); |