To remove unneeded white space from the start or end of a line of text.
///
<summary>
///
Removes the whitespace from the front of a word list
///
</summary>
///
<remarks>Tab
characters are not removed because they perform sensible formatting at the
beginning of a line.</remarks>
///
<param name="words">A
reference to the word list that should be trimmed</param>
public
void TrimStart(ref
WordPosCollection words)
{
int
firstindex=0;
if(words.Count==0)
return;
if(words[0].WhiteSpace==WhiteSpace.Indent)
firstindex=1;
float
pos=words[0].PagePos;
bool
needsRePos = false;
while(words[firstindex].WhiteSpace==WhiteSpace.Space
|| words[firstindex].WhiteSpace==WhiteSpace.NewLine)
{
words.RemoveAt(firstindex);
needsRePos=true;
if(words.Count>0)
words[0].PagePos=pos;
}
if(needsRePos)
RePos(ref
words);
}
///
<summary>
///
Trims the whitespace from the end of a word list
///
</summary>
///
<param name="words">A
reference to the word list to be trimmed</param>
public
void TrimEnd(ref
WordPosCollection words)
{
if(words.Count==0)
return;
while(words.Count!=0
&& (words.Last().WhiteSpace!=WhiteSpace.None))
{
words.RemoveLast();
}
}
'/ <summary>
'/
Removes the whitespace from the front of a word list
'/
</summary>
'/
<remarks>Tab characters are not removed because they perform sensible formatting
at the beginning of a line.</remarks>
'/
<param name="words">A reference to the word list that should be trimmed</param>
Public
Sub TrimStart(ByRef
words As WordPosCollection)
Dim
firstindex As Integer
= 0
If
words.Count = 0 Then
Return
End
If
If
words(0).WhiteSpace = WhiteSpace.Indent Then
firstindex = 1
End
If
Dim
pos As Single =
words(0).PagePos
Dim
needsRePos As Boolean
= False
While
words(firstindex).WhiteSpace = WhiteSpace.Space Or
words(firstindex).WhiteSpace = WhiteSpace.NewLine
words.RemoveAt(firstindex)
needsRePos = True
If
words.Count > 0 Then
words(0).PagePos = pos
End
If
End
While
If
needsRePos Then
RePos(words)
End
If
End
Sub 'TrimStart
'/
<summary>
'/
Trims the whitespace from the end of a word list
'/
</summary>
'/
<param name="words">A reference to the word list to be trimmed</param>
Public
Sub TrimEnd(ByRef
words As WordPosCollection)
If
words.Count = 0 Then
Return
End
If
Dim
done As Boolean
= False
Do
If
(words.Count > 0) Then
If
(words.Last().WhiteSpace <> WhiteSpace.None) Then
words.RemoveLast()
Else
done = True
End
If
End
If
Loop
While Not done
End
Sub 'TrimEnd