public String GetString( ref int position, bool bCreate )
{
int stringEnd;
bool bFoundEnd = false;
for (stringEnd = position; stringEnd < m_data.Length-1; stringEnd += 2)
{
if (m_data[stringEnd] == 0 && m_data[stringEnd + 1] == 0)
{
bFoundEnd = true;
break;
}
}
BCLDebug.Assert(bFoundEnd, "Malformed string in parse data");
StringMaker m = System.SharedStatics.GetSharedStringMaker();
try
{
if (bCreate)
{
m._outStringBuilder = null;
m._outIndex = 0;
for (int i = position; i < stringEnd; i += 2)
{
char c = (char)(m_data[i] << 8 | m_data[i+1]);
// add character to the string
if (m._outIndex < StringMaker.outMaxSize)
{
// easy case
m._outChars[m._outIndex++] = c;
}
else
{
if (m._outStringBuilder == null)
{
// OK, first check if we have to init the StringBuilder
m._outStringBuilder = new StringBuilder();
}
// OK, copy from _outChars to _outStringBuilder
m._outStringBuilder.Append(m._outChars, 0, StringMaker.outMaxSize);
// reset _outChars pointer
m._outChars[0] = c;
m._outIndex = 1;
}
}
}
position = stringEnd + 2;
if (bCreate)
return m.MakeString();
else
return null;
}
finally
{
System.SharedStatics.ReleaseSharedStringMaker(ref m);
}
}