public static string Escape(string s)
{
return NonUriChar.Replace(s, m => {
var c = m.Value[0];
return ( c == ' ' ) ? "+" :
( c < 0x80 ) ? IntToHex(c) :
( c < 0x0800 ) ? IntToHex(( ( c >> 6 ) & 0x1f ) + 0xc0, ( c & 0x3f ) + 0x80) :
IntToHex(( ( c >> 12 ) & 0x0f ) + 0xe0, ( ( c >> 6 ) & 0x3f ) + 0x80, ( c & 0x3f ) + 0x80);
}
);
}