Exemplo n.º 1
0
 /**
 		Finds and returns the range of the firt occurrence of a given string within
 		the receiver.
 		\param $aString
 		\returns RTRange
 */
 public function rangeOfString(RTString $aString)
 {
     $pos = strpos($this->description(), $aString->description());
     if ($pos === FALSE) {
         return RTMakeRange(0, 0);
     }
     return RTMakeRange($pos, $aString->length());
 }
Exemplo n.º 2
0
 public function testRemoveObjectsInRangeWithInvalidRange()
 {
     $range = RTMakeRange(0, 40);
     try {
         self::$array->removeObjectsInRange($range);
     } catch (RTRangeException $e) {
         return;
     }
     $this->fail("RTMutableArray::removeObjectsInRange should throw RTRangeException when " . "the specified range is out of bounds");
 }
Exemplo n.º 3
0
 public function testRangeInRange()
 {
     $lhsRange = RTMakeRange(0, 0);
     $rhsRange = $this->range;
     $this->assertFalse(RTRangeInRange($lhsRange, $rhsRange));
     $lhsRange = RTCopyRange($rhsRange);
     $this->assertTrue(RTRangeInRange($lhsRange, $rhsRange));
     $rhsRange->location--;
     $rhsRange->length++;
     $this->assertFalse(RTRangeInRange($lhsRange, $rhsRange));
 }
Exemplo n.º 4
0
 public function testSubstringWithRangeThrowsExceptionWithInvalidLength()
 {
     $string = RTString::stringWithString("This is a test");
     $range = RTMakeRange(0, $string->length() + 1);
     try {
         $anotherString = $string->substringWithRange($range);
     } catch (RTRangeException $e) {
         return;
     }
     $this->fail("Should have thrown exception when range's length is beyond the end of the string");
 }
Exemplo n.º 5
0
function RTRangeFromString($aString)
{
    $vals = json_decode($aString);
    return RTMakeRange($vals->location, $vals->length);
}
Exemplo n.º 6
0
 public function testSubarrayWithRange()
 {
     $array = self::$array->subarrayWithRange(RTMakeRange(0, 1));
     $this->assertTrue(is_object($array));
     $this->assertEquals("RTArray", $array->className());
     $this->assertEquals(2, $array->count());
     for ($i = 0; $i < $array->count(); $i++) {
         $this->assertEquals($array->objectAtIndex($i), self::$fixture[$i]);
     }
 }