internal bool MatchSpecifiedWords(String target, bool checkWordBoundary, ref int matchLength) {
int valueRemaining = Value.Length - Index;
matchLength = target.Length;
if (matchLength > valueRemaining || m_info.Compare(Value, Index, matchLength, target, 0, matchLength, CompareOptions.IgnoreCase) !=0) {
// Check word by word
int targetPosition = 0; // Where we are in the target string
int thisPosition = Index; // Where we are in this string
int wsIndex = target.IndexOfAny(WhiteSpaceChecks, targetPosition);
if (wsIndex == -1) {
return false;
}
do {
int segmentLength = wsIndex - targetPosition;
if (thisPosition >= Value.Length - segmentLength) { // Subtraction to prevent overflow.
return false;
}
if (segmentLength == 0) {
// If segmentLength == 0, it means that we have leading space in the target string.
// In that case, skip the leading spaces in the target and this string.
matchLength--;
} else {
// Make sure we also have whitespace in the input string
if (!Char.IsWhiteSpace(Value[thisPosition + segmentLength])) {
return false;
}
if (m_info.Compare(Value, thisPosition, segmentLength, target, targetPosition, segmentLength, CompareOptions.IgnoreCase) !=0) {
return false;
}
// Advance the input string
thisPosition = thisPosition + segmentLength + 1;
}
// Advance our target string
targetPosition = wsIndex + 1;
// Skip past multiple whitespace
while (thisPosition < Value.Length && Char.IsWhiteSpace(Value[thisPosition])) {
thisPosition++;
matchLength++;
}
} while ((wsIndex = target.IndexOfAny(WhiteSpaceChecks, targetPosition)) >= 0);
// now check the last segment;
if (targetPosition < target.Length) {
int segmentLength = target.Length - targetPosition;
if (thisPosition > Value.Length - segmentLength) {
return false;
}
if (m_info.Compare(Value, thisPosition, segmentLength, target, targetPosition, segmentLength, CompareOptions.IgnoreCase) !=0) {
return false;
}
}
}
if (checkWordBoundary) {
int nextCharIndex = Index + matchLength;
if (nextCharIndex < Value.Length) {
if (Char.IsLetter(Value[nextCharIndex])) {
return (false);
}
}
}
return (true);
}