internal static bool TryParseQuoteString(String format, int pos, StringBuilder result, out int returnValue) {
//
// NOTE : pos will be the index of the quote character in the 'format' string.
//
returnValue = 0;
int formatLen = format.Length;
int beginPos = pos;
char quoteChar = format[pos++]; // Get the character used to quote the following string.
bool foundQuote = false;
while (pos < formatLen) {
char ch = format[pos++];
if (ch == quoteChar) {
foundQuote = true;
break;
}
else if (ch == '\\') {
// The following are used to support escaped character.
// Escaped character is also supported in the quoted string.
// Therefore, someone can use a format like "'minute:' mm\"" to display:
// minute: 45"
// because the second double quote is escaped.
if (pos < formatLen) {
result.Append(format[pos++]);
} else {
//
// This means that '\' is at the end of the formatting string.
//
return false;
}
} else {
result.Append(ch);
}
}
if (!foundQuote) {
// Here we can't find the matching quote.
return false;
}
//
// Return the character count including the begin/end quote characters and enclosed string.
//
returnValue = (pos - beginPos);
return true;
}