Exemplo n.º 1
0
 /**
  * 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));
 }
Exemplo n.º 2
0
 /**
  * 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));
 }
Exemplo n.º 3
0
 /**
  * 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());
 }
Exemplo n.º 4
0
 /**
  * This method compares the specified object with the current object for order.
  *
  * @access public
  * @static
  * @param IString\Type $xs                                  the left operand
  * @param IString\Type $ys                                  the object to be compared
  * @return ITrit\Type                                       whether the current object is less than,
  *                                                          equal to, or greater than the specified
  *                                                          object
  */
 public static function compare(IString\Type $xs, IString\Type $ys) : ITrit\Type
 {
     return ITrit\Type::make(strcmp($xs->unbox(), $ys->unbox()));
 }
Exemplo n.º 5
0
 /**
  * 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());
 }
Exemplo n.º 6
0
 /**
  * This method tests that a value is reversed.
  *
  * @dataProvider dataReverse
  */
 public function testReverse(array $provided, array $expected)
 {
     $this->markTestIncomplete();
     $p0 = IString\Type::make($provided[0])->reverse();
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IString\\Type', $p0);
     $this->assertSame($e0, $p0->unbox());
 }
Exemplo n.º 7
0
 /**
  * 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);
 }
Exemplo n.º 8
0
 /**
  * This method allows for the class to be extend with custom utility functions.
  *
  * @access public
  * @static
  * @param IString\Type $name                                 the name of the mixin
  * @param callable $closure                                 the custom utility function
  */
 public static function mixin(IString\Type $name, callable $closure)
 {
     static::$mixins[$name->unbox()] = $closure;
 }
Exemplo n.º 9
0
 /**
  * This method tests the "toString" method.
  *
  * @dataProvider data_toString
  */
 public function test_toString(array $provided, array $expected)
 {
     $p0 = IString\Type::make($provided[0])->toString();
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IString\\Type', $p0);
     $this->assertSame($e0, $p0->unbox());
 }
Exemplo n.º 10
0
 /**
  * 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;
 }
Exemplo n.º 11
0
 /**
  * This method returns whether the iterator is still valid.
  *
  * @access public
  * @final
  * @return bool                                             whether there are more objects
  */
 public final function valid() : bool
 {
     return $this->i->unbox() < $this->xs->__length();
 }
Exemplo n.º 12
0
 /**
  * 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);
 }