public string FormatString (DocumentLocation loc, string str)
{
if (string.IsNullOrEmpty (str))
return "";
StringBuilder sb = new StringBuilder ();
bool convertTabs = TabsToSpaces;
var tabSize = Options.TabSize;
for (int i = 0; i < str.Length; i++) {
char ch = str [i];
switch (ch) {
case '\u00A0': // convert non breaking spaces to standard spaces.
sb.Append (' ');
break;
case '\t':
if (convertTabs) {
int tabWidth = TextViewMargin.GetNextTabstop (this, loc.Column, tabSize) - loc.Column;
sb.Append (new string (' ', tabWidth));
loc = new DocumentLocation (loc.Line, loc.Column + tabWidth);
} else
goto default;
break;
case '\r':
if (i + 1 < str.Length && str [i + 1] == '\n')
i++;
goto case '\n';
case '\n':
sb.Append (EolMarker);
loc = new DocumentLocation (loc.Line + 1, 1);
break;
default:
sb.Append (ch);
loc = new DocumentLocation (loc.Line, loc.Column + 1);
break;
}
}
return sb.ToString ();
}