An Objective-C/Perl Bridge


A CamelBones::NSRange object represents part of a series. It has two properties: location, which describes the index at which the series begins, and length, which is the number of items in the series. Both are unsigned integers.


Returns the value of the location property.
Returns the value of the length property.
Stores the value of $newLocation in the location property.
Stores the value of $newLength in the length property.
setAll($newLocation, $newLength)
Stores the value of $newLocation and $newLength in the location and length properties, respectively.
$hr = getHashref()
Returns the range data as a reference to a hash with keys 'location' and 'length'.
$ar = getArrayref()
Returns the range data as an array reference. Properties are stored in the array in the order location,length.


$isEQ = NSEqualRanges($range1, $range2)
Returns a true (nonzero) value if both location and length properties are the same for both ranges, a false (zero) value if not.
$range = NSIntersectionRange($range1, $range2)
Returns an NSRange that covers the intersection of $range1 and $range2. If no part of $range1 and $range2 overlap, the returned range has a length of 0.
$isIn = NSLocationInRange($loc, $range)
Returns a true value if $loc falls within $range, false if not.
$range = NSMakeRange($newLocation, $newLength)
Creates a new NSRange structure with the specified properties.
$max = NSMaxRange($range)
Returns a number 1 greater than the maximum value in $range.
$range = NSRangeFromString($str)
Creates a new NSRange structure from the string representation in $str.
$str = NSStringFromRange($range)
Returns a string representation of $range
$range = NSUnionRange($range1, $range2)
Returns all locations in and between $range1 and $range2.

NSRange function and method arguments

Naturally, a function or method that is declared as taking an NSRange structure as an argument will also take a CamelBones::NSRange object. However, a hash or array reference may be passed as well, as illustrated by these examples:

# Create a CamelBones::NSRange object
my $range = NSMakeRange(0, 5);

# Returns zero
my $isEQ = NSEqualRanges($range, { location=>5, length=>5 });

# Returns nonzero
my $isIn = NSLocationInRange(2, [0,10]);

NSRange return values

Cocoa functions and methods that are declared as returning NSRange structures will return CamelBones::NSRange objects to Perl.

See also


Managing Ranges