/** 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()); }
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"); }
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)); }
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"); }
function RTRangeFromString($aString) { $vals = json_decode($aString); return RTMakeRange($vals->location, $vals->length); }
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]); } }