public static unsafe string Unfold (string text)
{
int startIndex;
int endIndex;
int i = 0;
if (text == null)
return string.Empty;
while (i < text.Length && char.IsWhiteSpace (text[i]))
i++;
if (i == text.Length)
return string.Empty;
startIndex = i;
endIndex = i;
while (i < text.Length) {
if (!char.IsWhiteSpace (text[i++]))
endIndex = i;
}
int count = endIndex - startIndex;
char[] chars = new char[count];
fixed (char* outbuf = chars) {
char* outptr = outbuf;
for (i = startIndex; i < endIndex; i++) {
if (text[i] != '\r' && text[i] != '\n')
*outptr++ = text[i];
}
count = (int) (outptr - outbuf);
}
return new string (chars, 0, count);
}