internal int GetUtfEncodingLimit(string s, int start, int end)
{
if ((end - start) * 3 <= MAX_UTF_ENCODING_SIZE)
{
return end;
}
int limit = MAX_UTF_ENCODING_SIZE;
for (int i = start; i != end; i++)
{
int c = s[i];
if (0 != c && c <= unchecked((int)(0x7F)))
{
--limit;
}
else
{
if (c < unchecked((int)(0x7FF)))
{
limit -= 2;
}
else
{
limit -= 3;
}
}
if (limit < 0)
{
return i;
}
}
return end;
}