Class: NSScanner

Inherits:
NSObject show all

Overview

The NSScanner class is an abstract superclass of a class cluster that declares the programmatic interface for an object that scans values from an NSString object.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Class Method Details

+ (Object) localizedScannerWithString(aString)

Returns an NSScanner object that scans a given string according to the user’s default locale. Sets the string to scan by invoking initWithString: with aString. The locale is set with setLocale:.

Parameters:

  • aString (String)

    The string to scan.

Returns:

  • (Object)

    An NSScanner object that scans aString according to the user’s default locale.

+ (Object) scannerWithString(aString)

Returns an NSScanner object that scans a given string. Sets the string to scan by invoking initWithString: with aString.

Parameters:

  • aString (String)

    The string to scan.

Returns:

Instance Method Details

- (Boolean) caseSensitive

Returns a Boolean value that indicates whether the receiver distinguishes case in the characters it scans. Scanners are not case sensitive by default. Note that case sensitivity doesn’t apply to the characters to be skipped.

Returns:

  • (Boolean)

    YES if the receiver distinguishes case in the characters it scans, otherwise NO.

- (NSCharacterSet) charactersToBeSkipped

Returns a character set containing the characters the receiver ignores when looking for a scannable element. For example, if a scanner ignores spaces and you send it a scanInt: message, it skips spaces until it finds a decimal digit or other character. While an element is being scanned, however, no characters are skipped. If you scan for something made of characters in the set to be skipped (for example, using scanInt: when the set of characters to be skipped is the decimal digits), the result is undefined.The default set to skip is the whitespace and newline character set.

Returns:

  • (NSCharacterSet)

    A character set containing the characters the receiver ignores when looking for a scannable element.

- (Object) initWithString(aString)

Returns an NSScanner object initialized to scan a given string.

Parameters:

  • aString (String)

    The string to scan.

Returns:

  • (Object)

    An NSScanner object initialized to scan aString from the beginning. The returned object might be different than the original receiver.

- (Boolean) isAtEnd

Returns a Boolean value that indicates whether the receiver has exhausted all significant characters

Returns:

  • (Boolean)

    YES if the receiver has exhausted all significant characters in its string, otherwise NO.If only characters from the set to be skipped remain, returns YES.

- (Object) locale

Returns the receiver’s locale. A scanner’s locale affects the way it interprets numeric values from the string. In particular, a scanner uses the locale’s decimal separator to distinguish the integer and fractional parts of floating-point representations. A scanner with no locale set uses non-localized values.

Returns:

  • (Object)

    The receiver’s locale, or nil if it has none.

- (Boolean) scanCharactersFromSet(scanSet, intoString:stringValue)

Scans the string as long as characters from a given character set are encountered, accumulating characters into a string that’s returned by reference. Invoke this method with NULL as stringValue to simply scan past a given set of characters.

Parameters:

  • scanSet (NSCharacterSet)

    The set of characters to scan.

  • stringValue (Pointer)

    Upon return, contains the characters scanned.

Returns:

  • (Boolean)

    YES if the receiver scanned any characters, otherwise NO.

- (Boolean) scanDecimal(decimalValue)

Scans for an NSDecimal value, returning a found value by reference. Invoke this method with NULL as decimalValue to simply scan past an NSDecimal representation.

Parameters:

Returns:

  • (Boolean)

    YES if the receiver finds a valid NSDecimal representation, otherwise NO.

- (Boolean) scanDouble(doubleValue)

Scans for a double value, returning a found value by reference. Skips past excess digits in the case of overflow, so the scanner’s position is past the entire floating-point representation.Invoke this method with NULL as doubleValue to simply scan past a double value representation. Floating-point representations are assumed to be IEEE compliant.

Parameters:

  • doubleValue (Float)

    Upon return, contains the scanned value. Contains HUGE_VAL or –HUGE_VAL on overflow, or 0.0 on underflow.

Returns:

  • (Boolean)

    YES if the receiver finds a valid floating-point representation, otherwise NO.

- (Boolean) scanFloat(floatValue)

Scans for a float value, returning a found value by reference. Skips past excess digits in the case of overflow, so the scanner’s position is past the entire floating-point representation.Invoke this method with NULL as floatValue to simply scan past a float value representation. Floating-point representations are assumed to be IEEE compliant.

Parameters:

  • floatValue (Float)

    Upon return, contains the scanned value. Contains HUGE_VAL or –HUGE_VAL on overflow, or 0.0 on underflow.

Returns:

  • (Boolean)

    YES if the receiver finds a valid floating-point representation, otherwise NO.

- (Boolean) scanHexDouble(result)

Scans for a double value from a hexadecimal representation, returning a found value by reference. This corresponds to %a or %A formatting. The hexadecimal double representation must be preceded by 0x or 0X. Invoke this method with NULL as result to simply scan past a hexadecimal double representation.

Parameters:

  • result (Float)

    Upon return, contains the scanned value.

Returns:

  • (Boolean)

    YES if the receiver finds a valid double-point representation, otherwise NO.

- (Boolean) scanHexFloat(result)

Scans for a double value from a hexadecimal representation, returning a found value by reference. This corresponds to %a or %A formatting. The hexadecimal float representation must be preceded by 0x or 0X. Invoke this method with NULL as result to simply scan past a hexadecimal float representation.

Parameters:

  • result (Float)

    Upon return, contains the scanned value.

Returns:

  • (Boolean)

    YES if the receiver finds a valid float-point representation, otherwise NO.

- (Boolean) scanHexInt(intValue)

Scans for an unsigned value from a hexadecimal representation, returning a found value by reference. The hexadecimal integer representation may optionally be preceded by 0x or 0X. Skips past excess digits in the case of overflow, so the receiver’s position is past the entire hexadecimal representation.Invoke this method with NULL as intValue to simply scan past a hexadecimal integer representation.

Parameters:

  • intValue (unsigned)

    Upon return, contains the scanned value. Contains INT_MAX or INT_MIN on overflow.

Returns:

  • (Boolean)

    Returns YES if the receiver finds a valid hexadecimal integer representation, otherwise NO.

- (Boolean) scanHexLongLong(result)

Scans for a long long value from a hexadecimal representation, returning a found value by reference. The hexadecimal integer representation may optionally be preceded by 0x or 0X. Skips past excess digits in the case of overflow, so the receiver’s position is past the entire hexadecimal representation.Invoke this method with NULL as result to simply scan past a hexadecimal long long representation.

Parameters:

  • result (Integer)

    Upon return, contains the scanned value.

Returns:

  • (Boolean)

    YES if the receiver finds a valid hexadecimal long long representation, otherwise NO.

- (Boolean) scanInt(intValue)

Scans for an int value from a decimal representation, returning a found value by reference. Skips past excess digits in the case of overflow, so the receiver’s position is past the entire decimal representation.Invoke this method with NULL as intValue to simply scan past a decimal integer representation.

Parameters:

  • intValue (Integer)

    Upon return, contains the scanned value. Contains INT_MAX or INT_MIN on overflow.

Returns:

  • (Boolean)

    YES if the receiver finds a valid decimal integer representation, otherwise NO.

- (Boolean) scanInteger(value)

Scans for an NSInteger value from a decimal representation, returning a found value by reference Skips past excess digits in the case of overflow, so the receiver’s position is past the entire integer representation.Invoke this method with NULL as value to simply scan past a decimal integer representation.

Parameters:

  • value (Integer)

    Upon return, contains the scanned value.

Returns:

  • (Boolean)

    YES if the receiver finds a valid integer representation, otherwise NO.

- (Integer) scanLocation

Returns the character position at which the receiver will begin its next scanning operation.

Returns:

  • (Integer)

    The character position at which the receiver will begin its next scanning operation.

- (Boolean) scanLongLong(longLongValue)

Scans for a long long value from a decimal representation, returning a found value by reference. All overflow digits are skipped. Skips past excess digits in the case of overflow, so the receiver’s position is past the entire decimal representation.Invoke this method with NULL as longLongValue to simply scan past a long decimal integer representation.

Parameters:

  • longLongValue (Integer)

    Upon return, contains the scanned value. Contains LLONG_MAX or LLONG_MIN on overflow.

Returns:

  • (Boolean)

    YES if the receiver finds a valid decimal integer representation, otherwise NO.

- (Boolean) scanString(string, intoString:stringValue)

Scans a given string, returning an equivalent string object by reference if a match is found. If string is present at the current scan location, then the current scan location is advanced to after the string; otherwise the scan location does not change.Invoke this method with NULL as stringValue to simply scan past a given string.

Parameters:

  • string (String)

    The string for which to scan at the current scan location.

  • stringValue (Pointer)

    Upon return, if the receiver contains a string equivalent to string at the current scan location, contains a string equivalent to string.

Returns:

  • (Boolean)

    YES if stringValue matches the characters at the scan location, otherwise NO.

- (Boolean) scanUpToCharactersFromSet(stopSet, intoString:stringValue)

Scans the string until a character from a given character set is encountered, accumulating characters into a string that’s returned by reference. Invoke this method with NULL as stringValue to simply scan up to a given set of characters.If no characters in stopSet are present in the scanner’s source string, the remainder of the source string is put into stringValue, the receiver’s scanLocation is advanced to the end of the source string, and the method returns YES.

Parameters:

  • stopSet (NSCharacterSet)

    The set of characters up to which to scan.

  • stringValue (Pointer)

    Upon return, contains the characters scanned.

Returns:

  • (Boolean)

    YES if the receiver scanned any characters, otherwise NO.If the only scanned characters are in the charactersToBeSkipped character set (which is the whitespace and newline character set by default), then returns NO.

- (Boolean) scanUpToString(stopString, intoString:stringValue)

Scans the string until a given string is encountered, accumulating characters into a string that’s returned by reference. If stopString is present in the receiver, then on return the scan location is set to the beginning of that string.If stopString is the first string in the receiver, then the method returns NO and stringValue is not changed.If the search string (stopString) isn’t present in the scanner’s source string, the remainder of the source string is put into stringValue, the receiver’s scanLocation is advanced to the end of the source string, and the method returns YES.Invoke this method with NULL as stringValue to simply scan up to a given string.

Parameters:

  • stopString (String)

    The string to scan up to.

  • stringValue (Pointer)

    Upon return, contains any characters that were scanned.

Returns:

  • (Boolean)

    YES if the receiver scans any characters, otherwise NO.If the only scanned characters are in the charactersToBeSkipped character set (which by default is the whitespace and newline character set), then this method returns NO.

- (Object) setCaseSensitive(flag)

Sets whether the receiver is case sensitive when scanning characters. Scanners are not case sensitive by default. Note that case sensitivity doesn’t apply to the characters to be skipped.

Parameters:

  • flag (Boolean)

    If YES, the receiver will distinguish case when scanning characters, otherwise it will ignore case distinctions.

Returns:

- (Object) setCharactersToBeSkipped(skipSet)

Sets the set of characters to ignore when scanning for a value representation. For example, if a scanner ignores spaces and you send it a scanInt: message, it skips spaces until it finds a decimal digit or other character. While an element is being scanned, however, no characters are skipped. If you scan for something made of characters in the set to be skipped (for example, using scanInt: when the set of characters to be skipped is the decimal digits), the result is undefined.The characters to be skipped are treated literally as single values. A scanner doesn’t apply its case sensitivity setting to these characters and doesn’t attempt to match composed character sequences with anything in the set of characters to be skipped (though it does match pre-composed characters individually). If you want to skip all vowels while scanning a string, for example, you can set the characters to be skipped to those in the string “AEIOUaeiou” (plus any accented variants with pre-composed characters).The default set of characters to skip is the whitespace and newline character set.

Parameters:

  • skipSet (NSCharacterSet)

    The characters to ignore when scanning for a value representation. Pass nil to not ignore any characters.

Returns:

- (Object) setLocale(aLocale)

Sets the receiver’s locale to a given locale. A scanner’s locale affects the way it interprets values from the string. In particular, a scanner uses the locale’s decimal separator to distinguish the integer and fractional parts of floating-point representations. A new scanner’s locale is by default nil, which causes it to use non-localized values.

Parameters:

  • aLocale (Object)

    The locale for the receiver.

Returns:

- (Object) setScanLocation(index)

Sets the location at which the next scan operation will begin to a given index. This method is useful for backing up to rescan after an error. Rather than setting the scan location directly to skip known sequences of characters, use scanString:intoString: or scanCharactersFromSet:intoString:, which allow you to verify that the expected substring (or set of characters) is in fact present.

Parameters:

  • index (Integer)

    The location at which the next scan operation will begin. Raises an NSRangeException if index is beyond the end of the string being scanned.

Returns:

- (String) string

Returns the string with which the receiver was created or initialized.

Returns:

  • (String)

    The string with which the receiver was created or initialized.