获取汉字的笔画数

@param string $str 汉字，可以不止一个汉字
@return array 按照汉字顺序输出笔画数组
@throws \InvalidArgumentException
170971
public static function get(string $str):array
    {
        $str = trim($str);
        $strArr = Str::toArray($str);
        $results = [];
        foreach ($strArr as $s) {
            $results[] = self::getSingle($s);
        }
        return $results;
    }
1367014
private function parse_fun_var(& $str)
    {
        // 变量： 点号变量转为数组式变量  $a.b.c   =>  $a[b][c] 
        $str = preg_replace('/\$(\w+)\.(\w+)\.(\w+)\.(\w+)/is','$\\1[\'\\2\'][\'\\3\'][\'\\4\']',$str);
        $str = preg_replace('/\$(\w+)\.(\w+)\.(\w+)/is','$\\1[\'\\2\'][\'\\3\']',$str);
        $str = preg_replace('/\$(\w+)\.(\w+)/is','$\\1[\'\\2\']',$str);
        
        // 方法: {function()}}
        $str = preg_replace("/\{(\!?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff:\\-\>$]*\(([^{}]*)\))\s*\}/", "<?php print_r(\\1); ?>", $str );
        
        // 方法: {function a=a1 b=b1}
        $str = \preg_replace_callback("/\{(\w+)\s+([^}]+)\}/i", array($this,'func_arr_params_callback'), $str);
        
        // 常量: {XXXX}
        $str = preg_replace ( "/\{([A-Z_\x7f-\xff][A-Z0-9_\x7f-\xff]*)\}/s", "<?php print_r(\\1); ?>", $str );
        
        // 变量: {$varname[]}, {$varname}
        //$str = preg_replace("/\{(\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff\[\]\'\"]*)\}/", "<?php print_r(isset(\\1) ? \\1 : '');\?\>", $str );
        
        // 其他: {$var...} to directly output, {$var||'abd'} or {$var}
        $str = preg_replace("/\{(\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff:]*(?:[^{}]*))\|\|\s*([^}]+)\s*\}/s", "<?php print_r(isset(\\1) && \\1 ? \\1 : \\2); ?>", $str );
        $str = preg_replace("/\{(\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff:]*(?:[^{}]*))\}/s", "<?php print_r(isset(\\1) ? \\1 : ''); ?>", $str );

        // 转义变量，放在后边
        /*
         * $str = preg_replace("/\{(\\$[a-zA-Z0-9_\[\]\'\"\$\x7f-\xff]+)\}/es", "\$this->addquote('<?php echo \\1; ?>')", $str);
         */
        $str = preg_replace_callback ("/\{(\\$[a-zA-Z0-9_\[\]\'\"\$\x7f-\xff]+)\}/s", array($this,'addquote_callback'), $str);
        
        return $str;
    }
521311
public static function getSingle(string $str):int
    {
        $str = trim($str);
        if (Str::length($str) > 1) {
            throw new \InvalidArgumentException('getSingle method only support one chinese word.');
        }
        //不是中文，笔画为0
        if (!Str::isChinese($str)) {
            return 0;
        }
        foreach (self::$lib as $k => $v) {
            if (strpos($v, $str) !== false) {
                return $k;
            }
        }
        //找不到的汉字，默认笔画为0
        return 0;
    }
759900
protected function parseInterpolationString($str)
	{
		$parsed = [];

		if ( ! preg_match_all('~\{([a-z\d_\-\|\#]+?)\}~i', $str, $matches))
		{
			return $parsed;
		}

		foreach ($matches[1] as $key => $value)
		{
			$parsed[$matches[0][$key]] = explode('|', $value);
		}

		return $parsed;
	}
964995
public function parseUrl($str)
	{
		if (! is_string($str)) {
			throw new InvalidUrlException('Unexpected type.');
		}
		if ($str === '') {
			throw new InvalidUrlException('Empty URL.');
		}
		if (trim($str, ' ') === '') {
			throw new InvalidUrlException('Empty URL.');
		}
		$components = $this->parseUrlComponents($str);
		$components = array_replace([
			'scheme' => '',
			'host' => '',
			'port' => '',
			'user' => '',
			'pass' => '',
			'path' => '',
			'query' => '',
			'fragment' => ''
		], $components);
		$this->scheme->parseComponent($components['scheme']);
		$this->host->parseComponent($components['host']);
		$this->port->parseComponent(strval($components['port']));
		if (empty($components['user']) && empty($components['pass'])) {
			$this->credentials->username = null;
			$this->credentials->password = null;
		} else {
			$this->credentials->parseComponent($components['user'] . ':' . $components['pass']);
		}
		$this->path->parseComponent($components['path']);
		$this->query->parseComponent($components['query']);
		$this->fragment->parseComponent($components['fragment']);
		return $this;
	}
197571
function unpack($str)
    {
        $data = array();
        foreach ($this->fileds as $k => $field)
        {
            /**
             * @var $field Field
             */
            switch ($field->type)
            {
                case Field::INT:
                    switch ($field->size)
                    {
                        case 1:
                            list(, $data[$k]) = unpack($field->signed ? 'c' : 'C', $str);
                            break;
                        case 2:
                            if ($this->convertBigEndian)
                            {
                                //网络字节序只有无符号的编码方式
                                list(, $data[$k]) = unpack('n', $str);
                            }
                            else
                            {
                                list(, $data[$k]) = unpack($field->signed ? 's' : 'S', $str);
                            }
                            break;
                        case 4:
                            if ($this->convertBigEndian)
                            {
                                //网络字节序只有无符号的编码方式
                                list(, $data[$k]) = unpack('N', $str);
                            }
                            else
                            {
                                list(, $data[$k]) = unpack($field->signed ? 'l' : 'L', $str);
                            }
                            break;
                        case 8:
                            if ($this->convertBigEndian)
                            {
                                //网络字节序只有无符号的编码方式
                                list(, $data[$k]) = unpack('J', $str);
                            }
                            else
                            {
                                list(, $data[$k]) = unpack($field->signed ? 'q' : 'Q', $str);
                            }
                            break;
                        default:
                            break;
                    }
                    break;
                case Field::FLOAT:
                    list(, $data[$k]) = unpack($field->size == 4 ? 'f' : 'd', $str);
                    break;
                case Field::CHAR:
                    $data[$k] = substr($str, 0, strpos($str, "\0"));
                    break;
                case Field::STRUCT:
                    $data[$k] = $field->struct->unpack($str);
                    break;
                default:
                    break;
            }
            $str = substr($str, $field->size);
        }
        return $data;
    }
649525
public static function removeUnsafeChars($str) {
		static $blacklist = '/[!\"?():\']/';
		static $whitelist = '/[^a-zA-Z0-9-_.]/';
		$validStr = preg_replace(array($blacklist, $whitelist), array('', '-'), $str);
		return $validStr;
	}
82468
public function widont($str) {
		$str = rtrim($str);
		$space = strrpos($str, ' ');

		if ($space !== false) {
			$str = substr($str, 0, $space) . '&nbsp;' . substr($str, $space + 1);
		}

		return $str;
	}
428562
public function getErrors ($str = FALSE)
	{
		
		// Copy the errors array
		
		$errors	= $this->errors;
		
		// Reset errors
		
		$this->resetErrors ();
		
		// If return as string
		
		if ($str)
		{
			
			// Convert to string and return
			
			return implode ('<br />', $errors);
			
		}
		
		// Else
		
		else
		{
			
			// Return the errors array
			
			return $errors;
			
		}
		
	}
122875
public function token($str) {
        $str=trim(preg_replace('/\{\{(.+?)\}\}/s',trim('\1'),
            Base::instance()->compile($str)));
        if (preg_match('/^(.+)(?<!\|)\|((?:\h*\w+(?:\h*[,;]?))+)$/s',
            $str,$parts)) {
            $str=trim($parts[1]);
            foreach (Base::instance()->split($parts[2]) as $func)
                $str=is_string($cmd=$this->filter($func))?
                    $cmd.'('.$str.')':
                    'Base::instance()->'.
                    'call($this->filter(\''.$func.'\'),['.$str.'])';
        } elseif (false !== strpos($str, '(')) {
            for ($i=0,$len=strlen($str),$newStr='',$tmp='';$i<$len;) {
                if ($str[$i] === '(') {
                    if ($tmp && array_key_exists($tmp, $this->filter)) {
                        $tmp = $this->filter[$tmp];
                    }
                    $newStr .= $tmp . '(';
                    $tmp = '';
                } elseif (in_array($str[$i], [' '])) {
                    $newStr .= $tmp . $str[$i];
                    $tmp = '';
                } else {
                    $tmp .= $str[$i];
                }
                $i++;
            }
            $newStr .= $tmp;
            $str = $newStr;
        }

        return $str;
    }
1337647
public static function str2array($str, $sep = ',')
    {
        $str = trim($str, "$sep ");

        if (!$str) {
            return [];
        }

        return preg_split("/\s*$sep\s*/", $str, -1, PREG_SPLIT_NO_EMPTY);
    }
493477
public static function getCharset($str) {
    if (empty($str)) {
      throw new Exception('Argument str cannot be empty');
    }
    $ord = self::unistr2ords($str);
    return self::getDominant($ord);
  }
661955
public function extract($str = null)
  {
    if (!$this->canCastToString($str)) {
      throw new \InvalidArgumentException('$str could not be cast to string');
    }
    $str = (string) $str;

    # match $str against $this->regex
    $matches = array();
    if (!preg_match($this->regex, $str, $matches)) {
      return null;
    }
    unset($matches[0]); # we only want the capturing groups

    # combine matches with their capturing group names
    $matches = array_combine($this->keys, $matches);
    $matches = $this->unflatten($matches);

    # cast each element in $matches to integer or float if possible
    array_walk_recursive($matches, array($this, 'typeCast'));

    return empty($matches) ? null : $matches;
  }
628912
public static function lines(string $str): array
    {
        $lines = BaseStringy::create($str)->lines();

        foreach ($lines as $i => $line) {
            $lines[$i] = $line;
        }

        /** @var string[] $lines */
        return $lines;
    }
561420
public static function tel($str)
	{
		$rule = array ('/^(\d{3,4}-)?(\d{7,8}){1}(-\d{2,4})?$/',		// 普通电话
		'/^(\d{3,4}-)?(\d{3,4}){1}(-\d{3,4})?$/');
		foreach ($rule as $t)
		{
			if (1 === preg_match($t, $str))
			{
				return true;
			}
		}
		return false;
	}
461042
function parse($str) {
		preg_match_all('/(\w+)\h*=\h*(.+?)(?=,|$)/',
			$str,$pairs,PREG_SET_ORDER);
		$out=array();
		foreach ($pairs as $pair)
			$out[$pair[1]]=trim($pair[2]);
		return $out;
	}
1250499
protected function fromBinaryString($str){
		
		if(!(\is_string($str) && \preg_match('/^[01]+$/', $str))){
			throw new \InvalidArgumentException('$str is not a binary string');
		}
		
		for($i = 0, $l = \strlen($str); $i < $l; ++$i){
			$this->_List->pushFront($str[$i] === '1' ? true : false);
		}
		
	}