Ruby StringScanner Functions

EditRocket provides the following information on StringScanner functions in the Ruby source code builder.

beginning_of_line?() - Returns true iff the scan pointer is at the beginning of the line.

check" check(pattern) - "This returns the value that #scan would return, without advancing the scan pointer. The match register is affected, though."

check_until" check_until(pattern) - "This returns the value that #scan_until would return, without advancing the scan pointer. The match register is affected, though."

clear() - "Equivalent to #terminate. This method is obsolete; use #terminate instead."

concat concat(str) - Appends str to the string being scanned. This method does not affect scan pointer.

empty?() - "Equivalent to #eos?. This method is obsolete, use #eos? instead."

eos?() - Returns true if the scan pointer is at the end of the string.

exist?" exist?(pattern) - "Looks ahead to see if the pattern exists anywhere in the string, without advancing the scan pointer. This predicates whether a #scan_until will return a value."

get_byte() - "Scans one byte and returns it. This method is NOT multi-byte character sensitive. See also #getch."

getbyte() - "Equivalent to #get_byte. This method is obsolete; use #get_byte instead."

getch() - "Scans one character and returns it. This method is multi-byte character sensitive. See also #get_byte."

initialize_copy - Duplicates a StringScanner object.

inspect() - "Returns a string that represents the StringScanner object, showing:"

match?" match?(pattern) - Tests whether the given pattern is matched from the current scan pointer. Returns the length of the match, or nil. The scan pointer is not advanced.

matched?() - Returns true iff the last match was successful.

matched() - Returns the last matched string.

matched_size() - "Returns the size of the most recent match (see #matched), or nil if there was no recent match."

matchedsize() - "Equivalent to #matched_size. This method is obsolete; use #matched_size instead."

must_C_version - This method is defined for backward compatibility.

new" StringScanner.new(string, dup = false) - Creates a new StringScanner object to scan over the given string. dup argument is obsolete and not used now.

peek" peek(len) - Extracts a string corresponding to string[pos,len], without advancing the scan pointer.

peep(p1) - "Equivalent to #peek. This method is obsolete; use #peek instead."

pointer=" pos=(n) - Modify the scan pointer.

pointer() - Returns the position of the scan pointer. In the 'reset' position, this value is zero. In the 'terminated' position (i.e. the string is exhausted), this value is the length of the string.

pos=" pos=(n) - Modify the scan pointer.

pos() - Returns the position of the scan pointer. In the 'reset' position, this value is zero. In the 'terminated' position (i.e. the string is exhausted), this value is the length of the string.

post_match() - Return the post-match (in the regular expression sense) of the last scan.

pre_match() - Return the pre-match (in the regular expression sense) of the last scan.

reset() - Reset the scan pointer (index 0) and clear matching data.

rest?() - "Returns true iff there is more data in the string. See #eos?. This method is obsolete; use #eos? instead."

rest() - Returns the "rest" of the string (i.e. everything after the scan pointer). If there is no more data (eos? = true), it returns "".

rest_size() - s.rest_size is equivalent to s.rest.size.

restsize() - "s.restsize is equivalent to s.rest_size. This method is obsolete; use #rest_size instead."

scan" scan(pattern) - Tries to match with pattern at the current position. If there's a match, the scanner advances the "scan pointer" and returns the matched string. Otherwise, the scanner returns nil.

scan_full" scan_full(pattern, return_string_p, advance_pointer_p) - Tests whether the given pattern is matched from the current scan pointer. Returns the matched string if return_string_p is true. Advances the scan pointer if advance_pointer_p is true. The match register is affected.

scan_until" scan_until(pattern) - Scans the string until the pattern is matched. Returns the substring up to and including the end of the match, advancing the scan pointer to that location. If there is no match, nil is returned.

search_full" search_full(pattern, return_string_p, advance_pointer_p) - Scans the string until the pattern is matched. Returns the matched string if return_string_p is true, otherwise returns the number of bytes advanced. Advances the scan pointer if advance_pointer_p, otherwise not. This method does affect the match register.

skip" skip(pattern) - Attempts to skip over the given pattern beginning with the scan pointer. If it matches, the scan pointer is advanced to the end of the match, and the length of the match is returned. Otherwise, nil is returned.

skip_until" skip_until(pattern) - Advances the scan pointer until pattern is matched and consumed. Returns the number of bytes advanced, or nil if no match was found.

string=" string=(str) - Changes the string being scanned to str and resets the scanner. Returns str.

string() - Returns the string being scanned.

terminate - Set the scan pointer to the end of the string and clear matching data.

unscan() - Set the scan pointer to the previous position. Only one previous position is remembered, and it changes with each scanning operation.