StringScanner Methods

IN THIS PAGE

Description

The StringScanner object provides high performance string manipulation functions. The StringScanner functions operate at the location of the current offset in the text buffer. The initial position is 1. All functions (except those with optional negative numeric arguments) work from the current offset position towards the end of the buffer.

The StringScanner.ScanXXX() functions position the offset immediately after any found text. The StringScanner.SkipXXX() functions position the offset at the beginning of any found text.

Properties

Property

Description

Offset

The offset position from the start of the buffer. The first position in the buffer is 1.

Text

The contents of the buffer.

Methods

StringScanner.Create()

Type P. Creates a new StringScanner object.

StringScanner.Delete()

Type V. Deletes N bytes from the buffer starting at the offset.

StringScanner.GetLineNumber()

Type N. Returns the line number of the offset.

StringScanner.GetLineText()

Type C. Returns the text of the line that the offset is on.

StringScanner.GetRemainder()

Type C.Return text from the current position to the end of the string.

StringScanner.GetToOffset()

Type C. Returns text from the from the beginning of the string to the current offset.

StringScanner.GotoLineStart()

Type N. Positions the offset to the beginning of the current line.

StringScanner.Replace()

Type V. Inserts text and optionally replaces a specified number of bytes at the current position.

StringScanner.ReplaceSmatch()

Type L. Replaces the next instance of Find_Text with Replace_Text. Uses wildcard characters.

StringScanner.ReplaceSmatchI()

Type L. Replaces the next instance of Find_Text (case insensitive) with Replace_Text. Uses wildcard characters.

StringScanner.ReplaceString()

Type L. Replaces the next instance of Find_Text with Replace_Text.

StringScanner.ReplaceStringI()

Type L. Replaces the next instance of Find_Text (case insensitive) with Replace_Text.

StringScanner.Reset()

Type V. Moves the offset to the beginning of the buffer (position = 1).

StringScanner.ScanOver()

Type C. Moves the offset by a specified number (positive or negative) of characters and returns the text between the starting and ending positions.

StringScanner.ScanOverSmatch()

Type C. Looks for Find_Text at the offset and returns the text between the starting and ending positions. Uses wildcard characters.

StringScanner.ScanOverSmatchI()

Type C. Looks for Find_Text (case insensitive) at the offset and returns the text between the starting and ending positions. Uses wildcard characters.

StringScanner.ScanSmatch()

Type L. Indicates whether the Find_Text can be between the offset and the end of the buffer.

StringScanner.ScanSmatchI()

Type L. Indicates whether the Find_Text (case insensitive) can be between the offset and the end of the buffer.

StringScanner.ScanToAlpha()

Type C. Positions the offset after the next alphabetic character and returns the text between the starting and ending positions of the offset.

StringScanner.ScanToAlphaNum()

Type C. Positions the offset after the next alphanumeric character and returns the text between the starting and ending positions of the offset.

StringScanner.ScanToCharacter()

Type C. Moves the offset forward until it finds a character not in Find_Chars and returns the textbetween the starting and ending positions of the offset.

StringScanner.ScanToDigit()

Type C. Positions the offset after the next number (0 to 9) that it finds and returns the text between the starting and ending positions of the offset.

StringScanner.ScanToSmatch()

Type C. Positions the offset after the next instance of the search argument. Uses wildcard characters.

StringScanner.ScanToSmatchI()

Type C. Positions the offset after the next instance of the search argument (case insensitive). Uses wildcard characters.

StringScanner.ScanToString()

Type C. Positions the offset after the next instance of the Find_Text and returns the text between the starting and ending positions of the offset.

StringScanner.ScanToStringI()

Type C. Positions the offset after the next instance of the Find_Text (case insensitive) and returns the text between the starting and ending positions of the offset.

StringScanner.ScanToToken()

Type C. Moves the offset to the indicated kind of token.

StringScanner.ScanToWhitespace()

Type C. Positions the offset after the next white space character and returns the text between the starting and ending positions of the offset.

StringScanner.ScanTypedToken()

Type C. Returns the next Token_Found in the format Kind:Token.

StringScanner.SkipOver()

Type L. Moves the offset Count characters. The argument can be positive (moving towards the end of the buffer) or negative (moving towards the start of the buffer).

StringScanner.SkipOverAlpha()

Type N. Positions the offset after the next non-alpha character and returns the number of characters skipped.

StringScanner.SkipOverAlphaNum()

Type N. Positions the offset after the next non-alphanumeric character and returns the number of characters skipped.

StringScanner.SkipOverCharacter()

Type N. Positions the offset after the first character not in the group and returns the number of characters skipped over.

StringScanner.SkipOverDigit()

Type N. Positions the offset after the first non-numeric character and returns the number of characters skipped over.

StringScanner.SkipOverSmatch()

Type N. Positions the offset after the search text and returns the number of characters skipped over. Uses wildcard characters.

StringScanner.SkipOverSmatchI()

Type N. Positions the offset after the search text (case insensitive) and returns the number of characters skipped over. Uses wildcard characters.

StringScanner.SkipOverString()

Type N. Positions the offset at the beginning of the search text and returns the number of characters skipped over.

StringScanner.SkipOverStringI()

Type N. Positions the offset at the beginning of the search text (case insensitive) and returns the number of characters skipped over.

StringScanner.SkipOverToken()

Type N. Positions the offset after the next token of the specified type, and returns the characters moved.

StringScanner.SkipOverWhitespace()

Type N. Positions the offset after the next non-white space character and returns the number of characters skipped.

StringScanner.SkipToAlpha()

Type L. Positions the offset at the beginning of the next alphabetic character and returns true if successful.

StringScanner.SkipToAlphaNum()

Type L. Positions the offset at the beginning of the next alphanumeric character and returns true if successful.

StringScanner.SkipToCharacter()

Type L. Positions the offset at the next characters in the search list and returns true if successful.

StringScanner.SkipToDigit()

Type L. Positions the offset at the next digit (0-9) is encountered and returns true if successful.

StringScanner.SkipToString()

Type L. Positions the offset at the beginning of the search text and returns true if successful.

StringScanner.SkipToStringI()

Type L. Positions the offset at the beginning of the search text (case insensitive) is found and returns true if successful.

StringScanner.SkipToToken()

Type L. Positions the offset after the found token.

StringScanner.SkipToWhitespace()

Type L. Positions the offset at the next white space character and returns true if successful.

Example

The following function removes a block of lines from the alphafivehelp.hhc text file that is over 20,000 lines in length. The block to be removed is defined by a "<ul>" and its matching "</ul>" tag. This block follows immediately after the line containing the text defined by lt. The variable dst defines the directory that contains the alphafivehelp.hhc file.

function remove_toc_entries as V ( dst as C, lt as C )
dim fbuffer as C
dim outbuffer as C
dim lbuffer as C
dim ulcount as N = 0
dim counting as L = .F.
dim at_i as N
dim buf as P
dim ln as N

Read the text into a buffer and create the StringScanner object.

outbuffer = ""
fbuffer = file.to_string(dst + "alphafivehelp.hhc")
buf = stringscanner.create(fbuffer)

Move the offset to the line that contains the search text.

if (buf.SkipToStringI("<param name=\"Name\" value=\"" + lt + "\">") = .T.) then
    ' if the text is found, get the line number
    ln = buf.GetLineNumber()
    ' move the offset to the start of the line
    buf.GotoLineStart(ln)
    ' copy everything up to the offset into the output buffer
    outbuffer = buf.GetToOffset()
end if

Look for the starting "<ul>" tag.

if (buf.SkipToStringI("<ul>") = .T.) then
    ' if found, move the offset past it
    buf.ScanOver(5)
    ulcount = 1
    ' find the corresponding "</ul>" tag
    while (ulcount > 0)
        if (buf.SkipToStringI("</ul>") = .T.) then
            lbuffer = buf.GetLineText()
            if ("<ul>" $ lbuffer) then
                ulcount = ulcount + 1
            end if
            if ("</ul>" $ lbuffer) then
                ulcount = ulcount - 1
            end if
            buf.ScanOver(5)
        end if
    end while
end if

Get the line number.

ln = buf.GetLineNumber()+ 1
' move the offset to the start of the next line
buf.GotoLineStart(ln)
' copy everything after the offset into the output buffer
outbuffer = outbuffer + buf.GetRemainder()

Save the output buffer into a new copy of alphafivehelp.hhc.

file.from_string(dst + "alphafivehelp.hhc", outbuffer)
end function

See Also