internal StringBuilder encode(string s, int section)
{
if (!encoding) return buf.Append(s);
int len = s.Length;
int c = 0, prev;
for (int i=0; i<len; ++i)
{
prev = c;
c = s[i];
// unreserved character
if (c < 128 && (charMap[c] & section) != 0 && prev != '\\')
{
buf.Append((char)c);
continue;
}
// the backslash esc itself doesn't get encoded
if (c == '\\' && prev != '\\') continue;
// we have a reserved, escaped, or non-ASCII
// encode
if (c == ' ' && section == QUERY)
buf.Append('+');
else
percentEncodeChar(buf, c);
// if we just encoded backslash, then it
// doesn't escape the next char
if (c == '\\') c = 0;
}
return buf;
}