scan

@param int|null $i_iterator
@param string $str_pattern
@param int $i_count
@return array|boolean
341907
public function scan(&$i_iterator, $str_pattern = null, $i_count = null)
	{
        $argStrs = ['ARGV[1]'];
        $args = [$i_iterator];

        $argvCounter = 1;

        if(null !== $str_pattern)
        {
            $argStrs[] = "'MATCH'";
            $argStrs[] = 'ARGV[' . (++$argvCounter) . ']';
            $args[] = $str_pattern;
        }

        if(null !== $i_count)
        {
            $argStrs[] = "'COUNT'";
            $argStrs[] = 'ARGV[' . (++$argvCounter) . ']';
            $args[] = $i_count;
        }

        $argStr = implode(',', $argStrs);

        $result = $this->eval(<<<STR
return redis.call('scan', {$argStr}) 
STR
        , $args);

        if(!$result)
        {
            return false;
        }

        $i_iterator = (int)$result[0];
        return 0 === $i_iterator && [] === $result[1] ? false : $result[1];
	}
44774
public function scan($cursor, $pattern = null, $count = null) {
        $params = [$cursor];
        if ($pattern) {
            $params[] = 'MATCH';
            $params[] = $pattern;
        }
        if ($count) {
            $params[] = 'COUNT';
            $params[] = $count;
        }
        return $this->returnCommand(['SCAN'], null, $params);
    }
985143
function scan(req, res) {
  var records = []
    , position
    , i
    , key
    , inc
    , map = this.map
    , len = this.cursor + this.count;

  for(i = this.cursor; i < len;i++) {
    if(i === this.target.length) {
      position = 0;
      break;
    }
    key = '' + this.target[i];
    inc = !this.pattern || (this.pattern && this.pattern.test(key));
    if(inc) {
      records.push(key);
      if(map) records.push(this.stringify ? '' + map[key] : map[key]);
    }
    position = i + 1;
  }

  res.send(null, [position, records]);
}
408317
public static void p(int i, Regex r) {
        if (0 == i) {
            System.out.println(i + ": " + r.stringMatched());
        } else {
            System.out.println(i + ": " + r.stringMatched(i));
        }
    }
1100982
public function scan($pattern = '*', $count = 100)
    {
        $client = $this->getConnection();
        $keys = [];

        foreach (new Keyspace($client->client(), $pattern) as $item) {
            $keys[] = $item;

            if (count($keys) == $count) {
                break;
            }
        }

        $script = <<<'LUA'
        local type = redis.call('type', KEYS[1])
        local ttl = redis.call('ttl', KEYS[1])

        return {KEYS[1], type, ttl}
LUA;

        return $client->pipeline(function (Pipeline $pipe) use ($keys, $script) {
            foreach ($keys as $key) {
                $pipe->eval($script, 1, $key);
            }
        });
    }
237674
public function hscan($key, $cursor, $pattern = null, $count = null) {
        $params = [$key, $cursor];
        if (isset($pattern)) {
            $params[] = 'MATCH';
            $params[] = $pattern;
        }
        if (isset($count)) {
            $params[] = 'COUNT';
            $params[] = $count;
        }
        return $this->returnCommand(['HSCAN'], $key, $params);
    }
759832
public function select(string $pattern): \Iterator
    {
        //游标,每次查询必须从0开始
        $iterator = NULL;
        while (true) {
            //查询并更新游标
            $ret = $this->handle->zScan($this->name, $iterator, $pattern, 10);

            //没有更多数据了
            if (false === $ret) {
                break;
            }

            //逐个返回
            foreach ($ret as $key => $val) {
                yield [$key => $val];
            }
        }
    }
369489
public static Iterable<MatchResult> findMatches(Pattern pattern,
			CharSequence s) {
		List<MatchResult> results = new ArrayList<MatchResult>();

		for (Matcher m = pattern.matcher(s); m.find();)
			results.add(m.toMatchResult());

		return results;
	}
634211
public static function preg_replace( $arr, $string, $count = null ) 
	{
		return preg_replace( array_keys( $arr ), array_values( $arr ), $string, $count );
	}
856399
private static String combinatorialPatternMaker(String[] str, int str_size, int c) {
        String comb_pattern = "";
        int curr_comb = 1;
        for (int i = 0; i < str_size; i++) {
            if ((c & curr_comb) != 0) {
                comb_pattern += str[i] + "\\s";
            } else {
                comb_pattern += "[\\w]+\\s";
            }
            curr_comb = curr_comb << 1;
        }
        //System.err.println(comb_pattern);
        return comb_pattern;
    }
352410
function processChildren( &$textElements,
                              &$children, $key, &$item, &$index, &$isFirstRun,
                              &$delimiterStructure, &$sequenceStructure, &$filterStructure,
                              $tpl, $rootNamespace, $name, $functionPlacement,
                              &$variableIterator, $noLastValue,
                              &$iteratorData )
    {
        if ( $variableIterator !== null )
        {
            unset( $last );
            if ( !$noLastValue and $iteratorData['iterator'] !== false )
            {
                $last =& $iteratorData['iterator'];
            }
            else
            {
                $last = false;
            }
            unset( $iteratorData['iterator'] );
            $iteratorData['iterator'] = new eZTemplateSectionIterator();
            $iteratorData['iterator']->setIteratorValues( $item, $key, $index, $index + 1, false, $last );
            unset( $last );

            $iteratorObject =& $iteratorData['iterator'];
            $tpl->setVariable( $variableIterator, $iteratorObject, $name );
        }
        else
        {
            $tpl->setVariable( "key", $key, $name );
            $tpl->setVariable( "item", $item, $name );
            $tpl->setVariable( "index", $index, $name );
            $tpl->setVariable( "number", $index + 1, $name );
        }
        if ( count( $filterStructure ) > 0 )
        {
            $filterCount = count( $filterStructure );
            $includeElement = true;
            for ( $i = 0; $i < $filterCount; ++$i )
            {
                $filterElement =& $filterStructure[$i];
                $filterParameters =& $filterElement[3];
                $filterName = $filterElement[2];
                $filterMatch = null;
                if ( isset( $filterParameters["match"] ) )
                {
                    $filterMatch = $tpl->elementValue( $filterParameters["match"], $rootNamespace, $name, $functionPlacement );
                    if ( $filterMatch )
                        $includeElement = $filterName == "section-exclude" ? false : true;
                }
                else
                    $tpl->missingParameter( "section:$filterName", "match" );
            }
            if ( !$includeElement )
                return false;
        }
        if ( $delimiterStructure !== null and !$isFirstRun )
        {
            $delimiterParameters = $delimiterStructure[3];
            $delimiterMatch = true;
            if ( isset( $delimiterParameters["modulo"] ) )
            {
                $delimiterModulo = $delimiterParameters["modulo"];
                $modulo = $tpl->elementValue( $delimiterModulo, $rootNamespace, $name, $functionPlacement );
                $modulo = trim( $modulo );
                if ( is_numeric( $modulo ) )
                    $delimiterMatch = ( $index % $modulo ) == 0;
            }
            if ( isset( $delimiterParameters["match"] ) )
            {
                $delimiterMatchParameter = $delimiterParameters["match"];
                $delimiterMatch = $tpl->elementValue( $delimiterMatchParameter, $rootNamespace, $name, $functionPlacement );
            }
            if ( $delimiterMatch )
            {
                $delimiterChildren =& $delimiterStructure[1];
                if ( is_array( $delimiterChildren ) )
                {
                    foreach ( array_keys( $delimiterChildren ) as $delimiterChildKey )
                    {
                        $delimiterChild =& $delimiterChildren[$delimiterChildKey];
                        $tpl->processNode( $delimiterChild, $textElements, $rootNamespace, $name );
                    }
                }
            }
        }
        $isFirstRun = false;
        if ( $sequenceStructure !== null and is_array( $sequenceStructure ) )
        {
            $sequenceValue = array_shift( $sequenceStructure );
            if ( $variableIterator !== null )
            {
                $iteratorData['iterator']->setSequence( $sequenceValue );
            }
            else
            {
                $tpl->setVariable( "sequence", $sequenceValue, $name );
            }
            $sequenceStructure[] = $sequenceValue;
        }
        foreach ( array_keys( $children ) as $childKey )
        {
            $child =& $children[$childKey];
            $tpl->processNode( $child, $textElements, $rootNamespace, $name );
        }
        ++$index;
        return true;
    }
774711
function find($selector, $idx=null, $lowercase=false)
	{
		$selectors = $this->parse_selector($selector);
		if (($count=count($selectors))===0) return array();
		$found_keys = array();

		// find each selector
		for ($c=0; $c<$count; ++$c)
		{
			// The change on the below line was documented on the sourceforge code tracker id 2788009
			// used to be: if (($levle=count($selectors[0]))===0) return array();
			if (($levle=count($selectors[$c]))===0) return array();
			if (!isset($this->_[HDOM_INFO_BEGIN])) return array();

			$head = array($this->_[HDOM_INFO_BEGIN]=>1);

			// handle descendant selectors, no recursive!
			for ($l=0; $l<$levle; ++$l)
			{
				$ret = array();
				foreach ($head as $k=>$v)
				{
					$n = ($k===-1) ? $this->dom->root : $this->dom->nodes[$k];
					//PaperG - Pass this optional parameter on to the seek function.
					$n->seek($selectors[$c][$l], $ret, $lowercase);
				}
				$head = $ret;
			}

			foreach ($head as $k=>$v)
			{
				if (!isset($found_keys[$k]))
				{
					$found_keys[$k] = 1;
				}
			}
		}

		// sort keys
		ksort($found_keys);

		$found = array();
		foreach ($found_keys as $k=>$v)
			$found[] = $this->dom->nodes[$k];

		// return nth-element or array
		if (is_null($idx)) return $found;
		else if ($idx<0) $idx = count($found) + $idx;
		return (isset($found[$idx])) ? $found[$idx] : null;
	}
1372079
static public function resolveNginxStatus($str)
    {
        preg_match_all('/\d+/is', $str, $matched);
        if (count($matched[0]) === 7) {
            return [
                'connections' => (int)$matched[0][0],
                'accepts' => (int)$matched[0][1],
                'handled' => (int)$matched[0][2],
                'requests' => (int)$matched[0][3],
                'reading' => (int)$matched[0][4],
                'writing' => (int)$matched[0][5],
                'waiting' => (int)$matched[0][6]
            ];
        }

        return null;
    }
927900
public function filter($collection = null, $iterator = null)
    {
        $return = array();
        foreach ($collection as $val) {
            if (call_user_func($iterator, $val)) {
                $return[] = $val;
            }
        }
        return $return;
    }
222800
public static <E> int counti(Iterable<E> iterable) {
        dbc.precondition(iterable != null, "cannot call counti with a null iterable");
        return counti(iterable.iterator());
    }
639783
function(array, pattern) {
      for(var i=0; i<array.length; i++) {
        var match = array[i].match(pattern);
        if(match) {
          return match;
        }
      }

      return null;
    }
196039
public static String[] splitToArray(String str, Pattern separatorPattern, int limit, boolean isTrim, boolean ignoreEmpty){
		return toArray(split(str, separatorPattern, limit, isTrim, ignoreEmpty));
	}