Mono.TextEditor.TextEditorData.FormatString C# (CSharp) Method

FormatString() public method

public FormatString ( Mono.TextEditor.DocumentLocation loc, string str ) : string
loc Mono.TextEditor.DocumentLocation
str string
return string
		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 ();
		}
		

Same methods

TextEditorData::FormatString ( int offset, string str ) : string

Usage Example

Example #1
0
            public string GetVirtualSpaces(int lineNumber, int column)
            {
                string indent = GetIndent(lineNumber, column);

                if (column == indent.Length + 1)
                {
                    return(data.FormatString(0, indent));
                }
                return("");
            }
All Usage Examples Of Mono.TextEditor.TextEditorData::FormatString