static private String UnescapeWin32String(String str, int start, int end)
{
StringBuilder result = null;
bool inQuote = false;
for (int i = start; i < str.Length && i <= end; i++)
{
// Look for quote
if (str[i] == '\'')
{
// Already in quote?
if (inQuote)
{
BCLDebug.Assert(result != null, "[CultureTable.UnescapeWin32String]Expect result to be non-null");
// See another single quote. Is this '' of 'fred''s' or ending quote?
if (i + 1 < str.Length)
{
if (str[i+1] == '\'')
{
// Append a ' and keep going (so we don't turn off quote mode)
result.Append('\'');
i++;
continue;
}
}
inQuote = false;
}
else
{
// Found beginning quote, remove it.
inQuote = true;
if (result == null)
result = new StringBuilder(str, start, i - start, str.Length);
}
}
else
{
// If we have a builder we need to add our non-quote char
if (result != null)
result.Append(str[i]);
}
}
// No ', just return input string substring
if (result == null)
return (str.Substring(start, end-start + 1));
// Had ', need to use the builder
return (result.ToString());
}