Source for file Stream.php
Documentation is available at Stream.php
* High level API for convert character set
* This api is high level api that convert between binary and numeric
* for convert character set with PHP
* @subpackage KSC5601_pure
* @author JoungKyun.Kim <http://oops.org>
* @copyright (c) 2015, JoungKyun.Kim
* @link http://pear.oops.org/package/KSC5601
* High level API for convert character set
* This api is high level api that convert between binary and numeric
* for convert character set with PHP
// {{{ function chr2hex ($c, $prefix = true, $dec = false)
* Convert character to hex string
* @return string hexical strings or decimal strings
* @param string 1 byte binary character
* @param string (optional) Defaults to true. Set ture, retuan with
* @param boolean (optional) Defaults to false. Set true, return with
static function chr2hex ($c, $prefix = true, $dec = false) {
$prefix = $prefix ? '0x' : '';
// {{{ function hex2chr ($c)
* Convert hexical string to 1 byte binary character.
* @return string 1 byte binary character
* @param string hexical string
// {{{ function chr2dec ($c)
* Convert 1 byte binary character to decimal strings.
* @return Decimal strings
* @param string 1 byte binary character
// {{{ function chr2bin ($c, $shift = '')
* Convert binary character 1 byte to binary(numeric) strings
* @param string 1 byte binary character
* @param string (optional) Defaults to empty. shift string with '>> [N]' or '<< [N]'
static function chr2bin ($c, $shift = '') {
if ( $shift && preg_match ('/^([<>]+)[\s]*([0-9]+)/', $shift, $match) ) :
case '>>' : $c = $c >> $match[2]; break;
case '<<' : $c = $c << $match[2]; break;
case '<' : $c = $c < $match[2]; break;
case '>' : $c = $c > $match[2]; break;
for ( $i= 0; $i< $n; $i++ ) :
// {{{ function bin2chr ($c)
* Convert binary strings to 1byte binary character
* @return string 1byte binary character
* @param string binary strings
// {{{ function check2byte ($byte)
return decbin (0x80 >> (8 - $byte));
// {{{ function decbin ($s, $bit = 4)
* Convert decimal strings to 4-digit binary(numeric) strings.
* @return {$bit}-digit binary strings
* @param string Given decimal strings
* @param numeric (optiona) Defaults to 4. number of digit.
static function decbin ($s, $bit = 4) {
// {{{ function is_out_of_ksx1001 ($c1, $c2, $is_dec = false)
* Check given 2byte is whether KSX1001 or out of range.
* @return boolean When out of range, true.
* @param string 1st byte binary character
* @param string 2st byte binary character
* @param boolean (optional) Defaults to false. If type of 1st and 2st arguments
if ( $is_dec === false ) {
if ( (($c1 > 0x80 && $c1 < 0xa1) && ($c2 > 0x40 && $c2 < 0x5b )) ||
(($c1 > 0x80 && $c1 < 0xa1) && ($c2 > 0x60 && $c2 < 0x7b )) ||
(($c1 > 0x80 && $c1 < 0xa1) && ($c2 > 0x80 && $c2 < 0xff )) ||
(($c1 > 0xa0 && $c1 < 0xc6) && ($c2 > 0x40 && $c2 < 0x5b )) ||
(($c1 > 0xa0 && $c1 < 0xc6) && ($c2 > 0x60 && $c2 < 0x7b )) ||
(($c1 > 0xa0 && $c1 < 0xc6) && ($c2 > 0x80 && $c2 < 0xa1 )) ||
($c1 == 0xc6 && ($c2 > 0x40 && $k < 0x53)) ) {
// {{{ function execute_time ($t1, $t2)
* @param array microtime() of starting
* @param array microtime() of ending
return sprintf("%.2f", ($end[1] + $end[0]) - ($start[1] + $start[0]));
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
|