/* Function: PreviousPastWhitespace * * Moves backwards until past all whitespace tokens or it reaches the limit. Returns whether it moved. * * Parameters: * * mode - If set to <PreviousPastWhitespaceMode.EndingBounds>, the iterator will move until the *previous* token is * no longer whitespace, paying no attention to the token the iterator is on. This is useful if you're using it as the * ending bounds relative to another iterator and want to trim trailing whitespace off. * * If set to <PreviousPastWhitespaceMode.Iterator>, the iterator will move until the *current* token is no longer * whitespace. This is useful if you're using it as an independent iterator and want it to be on a non-whitespace * token. */ public bool PreviousPastWhitespace(PreviousPastWhitespaceMode mode, TokenIterator limit) { if (mode == PreviousPastWhitespaceMode.Iterator) { if (FundamentalType != Tokenization.FundamentalType.Whitespace || this <= limit) { return(false); } do { Previous(); }while (FundamentalType == Tokenization.FundamentalType.Whitespace && this > limit); return(true); } else if (mode == PreviousPastWhitespaceMode.EndingBounds) { TokenIterator temp = this; temp.Previous(); if (temp.FundamentalType != FundamentalType.Whitespace || temp < limit) { return(false); } do { this = temp; temp.Previous(); }while (temp.FundamentalType == FundamentalType.Whitespace && temp >= limit); return(true); } else { throw new NotImplementedException(); } }
/* Function: PreviousPastWhitespace * * Moves backwards until past all whitespace tokens or it reaches the limit. * * Parameters: * * mode - If set to <PreviousPastWhitespaceMode.EndingBounds>, the iterator will move until the *previous* token is * no longer whitespace, paying no attention to the token the iterator is on. This is useful if you're using it as the * ending bounds relative to another iterator and want to trim trailing whitespace off. * * If set to <PreviousPastWhitespaceMode.Iterator>, the iterator will move until the *current* token is no longer * whitespace. This is useful if you're using it as an independent iterator and want it to be on a non-whitespace * token. */ public void PreviousPastWhitespace(PreviousPastWhitespaceMode mode, TokenIterator limit) { if (mode == PreviousPastWhitespaceMode.Iterator) { while (FundamentalType == Tokenization.FundamentalType.Whitespace && this > limit) { Previous(); } } else if (mode == PreviousPastWhitespaceMode.EndingBounds) { TokenIterator temp = this; temp.Previous(); while (temp.FundamentalType == FundamentalType.Whitespace && temp >= limit) { this = temp; temp.Previous(); } } }