Iterator for text strings which allows you to iterate
over just the text portions, the format portions, or the
whole thing. Instantiate the iterator with the text you want to iterate
over.
Here's some example code using the FormattedTextIter
class:
' iter = FormattedTextIter("this <color v=blue">text is blue</color>") '
' while iter.moreText(): '
' mem = iter.nextText() '
' mem = string.replace(mem, "blue", "red") '
' iter.replaceText(mem) '
Methods
|
|
__init__ firstFormat firstText moreFormat moreText nextFormat nextText replaceFormat replaceText
|
|
__init__
|
__init__ ( self, text )
Initializes the FormattedTextIter class based on the text.
Note: right now it does all the initialization up front--this
should probably be moved to on demand. arguments:
-
text
- (string) the initial text to iterate over.
|
|
firstFormat
|
firstFormat ( self )
Resets the formatindex to 0. This effectively restarts the
iterator to the beginning of the text element list. |
|
firstText
|
firstText ( self )
Resets the textindex to 0. This effectively restarts the
iterator to the beginning of the text element list. |
|
moreFormat
|
moreFormat ( self )
Tells you whether or not there are additional formatting
elements in the iterator. returns:
(0 or 1) whether there are more format elements
|
|
moreText
|
moreText ( self )
Tells you whether or not there are additional text elements
in the iterator. returns:
(0 or 1) whether or not there are more text elements
|
|
nextFormat
|
nextFormat ( self )
Increments the formatindex and returns the next format element
in the iterator. returns:
(string) the next formatting element
Exceptions
|
|
ValueError, "No more formatting tokens available."
|
|
|
nextText
|
nextText ( self )
Increments the textindex and gives you the next text element
in the iterator. returns:
(string) the next text element
Exceptions
|
|
ValueError, "No more text tokens available."
|
|
|
replaceFormat
|
replaceFormat ( self, newformat )
Replaces the current format element with the format text given.
The current format element will be whatever you just pulled
out via the most recent call to nextFormat() . Or the
first element in the list if you have never called
nextFormat() . arguments:
-
newformat
- (string) the formatting element to replace the
existing one
|
|
replaceText
|
replaceText ( self, newtext )
Replaces the current text element with the text given.
The current text element will be whatever you just pulled
out via the most recent call to nextText() . Or the
first element in the list if you have never called
nextText() . arguments:
-
newtext
- (string) the text element to replace the existing
one.
|
|