/** * This method returns an array of sub-strings that were split on the regular expression. * * @access public * @static * @param IRegex\Type $x the regular expression * @param Core\Type $ys the object to be split * @return IArrayList\Type an array of sub-strings */ public static function split(IRegex\Type $x, Core\Type $ys) : IArrayList\Type { $zs = $ys instanceof ITuple\Type ? preg_split($x->unbox(), $ys->first()->__toString(), (int) $ys->second()->unbox()) : preg_split($x->unbox(), $ys->__toString()); return IArrayList\Type::box(array_map(function ($z) { return IString\Type::box($z); }, $zs)); }
/** * This method tests the "split" method. * * @dataProvider data_split */ public function test_split(array $provided, array $expected) { if (is_array($provided[1])) { $p0 = IRegex\Module::split(IRegex\Type::box($provided[0]), ITuple\Type::box2(IString\Type::box($provided[1][0]), IInt32\Type::box($provided[1][1]))); } else { $p0 = IRegex\Module::split(IRegex\Type::box($provided[0]), IString\Type::box($provided[1])); } $e0 = $expected[0]; $this->assertInstanceOf('\\Saber\\Data\\IArrayList\\Type', $p0); $this->assertSame($e0, $p0->unbox(1)); }
/** * This method returns the backtrace information as a string. * * @access public * @static * @param Throwable\Runtime\Exception $x the exception to be processed * @return string the backtrace information */ public static function getTraceAsString(Throwable\Runtime\Exception $x) { return IString\Type::box($x->__getTraceAsString()); }
/** * This method returns each item in this string until the predicate fails. * * @access public * @static * @param IString\Type $xs the left operand * @param callable $predicate the predicate function to be used * @return IString\Type the string */ public static function takeWhile(IString\Type $xs, callable $predicate) : IString\Type { $buffer = ''; $length = $xs->length(); for ($i = IInt32\Type::zero(); IInt32\Module::lt($i, $length)->unbox(); $i = IInt32\Module::increment($i)) { $x = $xs->item($i); if (!$predicate($x, $i)->unbox()) { break; } $buffer .= $x->unbox(); } return IString\Type::box($buffer); }
/** * This method returns the object's class type. * * @access public * @final * @return IString\Type the object's class type */ public final function typeOf() : IString\Type { return IString\Type::box($this->__typeOf()); }
/** * This method returns a string representing a sequence of substring delimited by the * "space" character. * * @access public * @static * @param ISeq\Type $xs a sequence of substrings * @return IString\Type the string */ public static function unwords(ISeq\Type $xs) { return IString\Utilities::join(IString\Type::box(' '), $xs); }
/** * This method tests the "length" method. * * @dataProvider data_length */ public function test_length(array $provided, array $expected) { $p0 = IString\Type::box($provided[0])->length(); $e0 = $expected[0]; $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $p0); $this->assertSame($e0, $p0->unbox()); }
/** * This method provides the data for testing that a value is of a particular size. * * @return array */ public function dataSize() { $data = array(array(array(), array(0)), array(array(ITuple\Type::box2(IString\Type::box('key0'), IInt32\Type::zero())), array(1)), array(array(ITuple\Type::box2(IString\Type::box('key0'), IInt32\Type::zero()), ITuple\Type::box2(IString\Type::box('key1'), IInt32\Type::one())), array(2))); return $data; }
/** * This method creates a string of "n" length with every item set to the given object. * * @access public * @static * @param IChar\Type $x the object to be replicated * @param IInt32\Type $n the number of times to replicate * @return IString\Type the string */ public static function replicate(IChar\Type $x, IInt32\Type $n) : IString\Type { $buffer = ''; $length = $n->unbox(); for ($i = 0; $i < $length; $i++) { $buffer .= $x->__toString(); } return IString\Type::box($buffer); }