Class: NSScanner
Overview
Class Method Summary (collapse)
-
+ localizedScannerWithString:
Returns an NSScanner object that scans a given string according to the user’s default locale.
-
+ scannerWithString:
Returns an NSScanner object that scans a given string.
Instance Method Summary (collapse)
-
- caseSensitive
Returns a Boolean value that indicates whether the receiver distinguishes case in the characters it scans.
-
- charactersToBeSkipped
Returns a character set containing the characters the receiver ignores when looking for a scannable element.
-
- initWithString:
Returns an NSScanner object initialized to scan a given string.
-
- isAtEnd
Returns a Boolean value that indicates whether the receiver has exhausted all significant characters.
-
- locale
Returns the receiver’s locale.
-
- scanCharactersFromSet:intoString:
Scans the string as long as characters from a given character set are encountered, accumulating characters into a string that’s returned by reference.
-
- scanDecimal:
Scans for an NSDecimal value, returning a found value by reference.
-
- scanDouble:
Scans for a double value, returning a found value by reference.
-
- scanFloat:
Scans for a float value, returning a found value by reference.
-
- scanHexDouble:
Scans for a double value from a hexadecimal representation, returning a found value by reference.
-
- scanHexFloat:
Scans for a double value from a hexadecimal representation, returning a found value by reference.
-
- scanHexInt:
Scans for an unsigned value from a hexadecimal representation, returning a found value by reference.
-
- scanHexLongLong:
Scans for a long long value from a hexadecimal representation, returning a found value by reference.
-
- scanInt:
Scans for an int value from a decimal representation, returning a found value by reference.
-
- scanInteger:
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.
-
- scanLocation
Returns the character position at which the receiver will begin its next scanning operation.
-
- scanLongLong:
Scans for a long long value from a decimal representation, returning a found value by reference.
-
- scanString:intoString:
Scans a given string, returning an equivalent string object by reference if a match is found.
-
- scanUpToCharactersFromSet:intoString:
Scans the string until a character from a given character set is encountered, accumulating characters into a string that’s returned by reference.
-
- scanUpToString:intoString:
Scans the string until a given string is encountered, accumulating characters into a string that’s returned by reference.
-
- setCaseSensitive:
Sets whether the receiver is case sensitive when scanning characters.
-
- setCharactersToBeSkipped:
Sets the set of characters to ignore when scanning for a value representation.
-
- setLocale:
Sets the receiver’s locale to a given locale.
-
- setScanLocation:
Sets the location at which the next scan operation will begin to a given index.
-
- string
Returns the string with which the receiver was created or initialized.
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
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.
- (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.
- (Boolean) isAtEnd
Returns a Boolean value that indicates whether the receiver has exhausted all significant characters
- (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.
- (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.
- (Boolean) scanDecimal(decimalValue)
- (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.
- (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.
- (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.
- (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.
- (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.
- (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.
- (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.
- (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.
- (Integer) scanLocation
Returns 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.
- (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.
- (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.
- (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.
- (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.
- (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.
- (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.
- (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.
- (String) string
Returns the string with which the receiver was created or initialized.