当前位置: 首页>>代码示例>>C#>>正文


C# Document.GetLine方法代码示例

本文整理汇总了C#中Mono.TextEditor.Document.GetLine方法的典型用法代码示例。如果您正苦于以下问题:C# Document.GetLine方法的具体用法?C# Document.GetLine怎么用?C# Document.GetLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mono.TextEditor.Document的用法示例。


在下文中一共展示了Document.GetLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindNextWordOffset

		int FindNextWordOffset (Document doc, int offset, bool subword)
		{
			int lineNumber   = doc.OffsetToLineNumber (offset);
			LineSegment line = doc.GetLine (lineNumber);
			if (line == null)
				return offset;
			
			int result    = offset;
			int endOffset = line.Offset + line.EditableLength;
			if (result == endOffset) {
				line = doc.GetLine (lineNumber + 1);
				if (line != null)
					result = line.Offset;
				return result;
			}
			
			CharacterClass current = GetCharacterClass (doc.GetCharAt (result), subword, false);
			while (result < endOffset) {
				CharacterClass next = GetCharacterClass (doc.GetCharAt (result), subword, false);
				if (next != current) {
					
					// camelCase and PascalCase handling
					bool camelSkip = false;
					if (next == CharacterClass.LowercaseLetter && current == CharacterClass.UppercaseLetter) {
						if (result-2 > line.Offset) {
							CharacterClass previous = GetCharacterClass (doc.GetCharAt (result-2), subword, false);
							if (previous == CharacterClass.UppercaseLetter && result-2 > offset)
								result--;
							else
								camelSkip = true;
						}
					}
					
					if (!camelSkip)
						break;
				}
				
				current = next;		
				result++;
			}
			while (result < endOffset && GetCharacterClass (doc.GetCharAt (result), subword, false) == CharacterClass.Whitespace) {
				result++;
			}
			return result;
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:45,代码来源:SharpDevelopWordFindStrategy.cs

示例2: GetPrevOffset

		static int GetPrevOffset (Document document, int lineNumber)
		{
			LineSegment startLine = document.GetLine (lineNumber);
			RedBlackTree<LineSegmentTree.TreeNode>.RedBlackTreeIterator iter = startLine.Iter;
			while (iter.MoveBack ()) {
				LineSegment line = iter.Current;
				if (line.IsBookmarked) {
					return line.Offset;
				}
			}
			return -1;
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:12,代码来源:BookmarkActions.cs

示例3: GetNextOffset

		static int GetNextOffset (Document document, int lineNumber)
		{
			int startLineNumber = lineNumber + 1;
			if (startLineNumber > document.Length) 
				startLineNumber = 0;
			
			LineSegment startLine = document.GetLine (startLineNumber);
			RedBlackTree<LineSegmentTree.TreeNode>.RedBlackTreeIterator iter = startLine.Iter;
			do {
				LineSegment line = iter.Current;
				if (line.IsBookmarked)
					return line.Offset;
			} while (iter.MoveNext ());
			return -1;
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:15,代码来源:BookmarkActions.cs

示例4: FindPrevWordOffset

		int FindPrevWordOffset (Document doc, int offset, bool subword)
		{
			int lineNumber = doc.OffsetToLineNumber (offset);
			LineSegment line = doc.GetLine (lineNumber);
			if (line == null)
				return offset;
			
			int result = offset;
			if (result == line.Offset) {
				line = doc.GetLine (lineNumber - 1);
				if (line != null)
					result = line.Offset + line.EditableLength;
				return result;
			}
			
			CharacterClass current = GetCharacterClass (doc.GetCharAt (result - 1), subword, false);
			
			if (current == CharacterClass.Whitespace && result - 1 > line.Offset) {
				result--;
				current = GetCharacterClass (doc.GetCharAt (result - 2), subword, false);
			}
			
			while (result > line.Offset) {
				CharacterClass prev = GetCharacterClass (doc.GetCharAt (result - 1), subword, false);
				if (prev != current) {
					
					// camelCase and PascalCase handling
					bool camelSkip = false;
					if (prev == CharacterClass.UppercaseLetter && current == CharacterClass.LowercaseLetter) {
						if (result-2 > line.Offset) {
							CharacterClass back2 = GetCharacterClass (doc.GetCharAt (result-2), subword, false);
							if (back2 == CharacterClass.UppercaseLetter)
								result--;
							else
								camelSkip = true;
						}
					}
					
					if (!camelSkip)
						break;
				}
				
				current = prev;
				result--;
			}
			
			return result;
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:48,代码来源:SharpDevelopWordFindStrategy.cs

示例5: CheckStartPoint

		static void CheckStartPoint (Document doc, InsertionPoint point, bool isEndPoint)
		{
			LineSegment line = doc.GetLine (point.Location.Line);
			if (line == null)
				return;
			if (doc.GetLineIndent (line).Length + 1 == point.Location.Column) {
				int lineNr = point.Location.Line;
				while (lineNr > 1 && doc.GetLineIndent (lineNr - 1).Length == doc.GetLine (lineNr - 1).EditableLength) {
					lineNr--;
				}
				line = doc.GetLine (lineNr);
				point.Location = new DocumentLocation (lineNr, doc.GetLineIndent (line).Length + 1);
			}
			
			if (doc.GetLineIndent (line).Length + 1 < point.Location.Column)
				point.LineBefore = isEndPoint ? NewLineInsertion.Eol : NewLineInsertion.BlankLine;
			if (point.Location.Column < line.EditableLength + 1)
				point.LineAfter = isEndPoint ? NewLineInsertion.Eol : NewLineInsertion.BlankLine;
		}
开发者ID:stewartwhaley,项目名称:monodevelop,代码行数:19,代码来源:HelperMethods.cs

示例6: CheckEndPoint

		static void CheckEndPoint (Document doc, InsertionPoint point, bool isStartPoint)
		{
			LineSegment line = doc.GetLine (point.Location.Line);
			if (line == null)
				return;
			
			if (doc.GetLineIndent (line).Length + 1 < point.Location.Column)
				point.LineBefore = NewLineInsertion.BlankLine;
			if (point.Location.Column < line.EditableLength + 1)
				point.LineAfter = NewLineInsertion.Eol;
		}
开发者ID:stewartwhaley,项目名称:monodevelop,代码行数:11,代码来源:HelperMethods.cs

示例7: IsBlankLine

		static bool IsBlankLine (Document doc, int i)
		{
			var line = doc.GetLine (i);
			return line.EditableLength == line.GetIndentation (doc).Length;
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:5,代码来源:MoveTypeToFile.cs

示例8: StripHeader

		static string StripHeader (string content)
		{
			var doc = new Mono.TextEditor.Document (content);
			while (true) {
				string lineText = doc.GetLineText (1);
				if (lineText == null)
					break;
				if (lineText.StartsWith ("//")) {
					((IBuffer)doc).Remove (doc.GetLine (1));
					continue;
				}
				break;
			}
			return doc.Text;
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:15,代码来源:MoveTypeToFile.cs

示例9: StripDoubleBlankLines

		static string StripDoubleBlankLines (string content)
		{
			var doc = new Mono.TextEditor.Document (content);
			for (int i = 1; i + 1 <= doc.LineCount; i++) {
				if (IsBlankLine (doc, i) && IsBlankLine (doc, i + 1)) {
					((IBuffer)doc).Remove (doc.GetLine (i));
					i--;
					continue;
				}
			}
			return doc.Text;
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:12,代码来源:MoveTypeToFile.cs

示例10: Format

		public static void Format (TextEditorData data, IType type, IMember member, ProjectDom dom, ICompilationUnit unit, DomLocation caretLocation)
		{
			if (type == null)
				return;
			if (member == null) {
				//				member = type;
				return;
			}
			string wrapper;
			int endPos;
			wrapper = CreateWrapperClassForMember (member, member != type, data, out endPos);
			if (string.IsNullOrEmpty (wrapper) || endPos < 0)
				return;
		//			Console.WriteLine (wrapper);
			
			int bracketIndex = wrapper.IndexOf ('{') + 1;
			int col = GetColumn (wrapper, bracketIndex, data.Options.TabSize);
			
			CSharpFormatter formatter = new CSharpFormatter ();
			formatter.startIndentLevel = System.Math.Max (0, col / data.Options.TabSize - 1);
			
			string formattedText = formatter.InternalFormat (dom != null && dom.Project != null ? dom.Project.Policies : null, MimeType, wrapper, 0, wrapper.Length);
			
			if (formatter.hasErrors)
				return;
			
			int startPos = data.Document.LocationToOffset (member.Location.Line, 1) - 1;
			InFormat = true;
			if (member != type) {
				int len1 = formattedText.IndexOf ('{') + 1;
				int last = formattedText.LastIndexOf ('}');
				formattedText = formattedText.Substring (len1, last - len1 - 1).TrimStart ('\n', '\r');
			} else {
				startPos++;
			}
			
			//Console.WriteLine ("formattedText0:" + formattedText.Replace ("\t", "->").Replace (" ", "°"));
			if (member != type) {
				string indentToRemove = GetIndent (formattedText);
		//				Console.WriteLine ("Remove:" + indentToRemove.Replace ("\t", "->").Replace (" ", "°"));
				formattedText = RemoveIndent (formattedText, indentToRemove);
			} else {
				formattedText = formattedText.TrimStart ();
			}
			//Console.WriteLine ("Indent:" + GetIndent (data, member.Location.Line - 1).Replace ("\t", "->").Replace (" ", "°"));
			//Console.WriteLine ("formattedText1:" + formattedText.Replace ("\t", "->").Replace (" ", "°"));
			formattedText = AddIndent (formattedText, GetIndent (data, member.Location.Line));
			
			Document doc = new Document ();
			doc.Text = formattedText;
			for (int i = doc.LineCount; i --> DocumentLocation.MinLine;) {
				LineSegment lineSegment = doc.GetLine (i);
				if (doc.IsEmptyLine (lineSegment))
					((IBuffer)doc).Remove (lineSegment.Offset, lineSegment.Length);
			}
			formattedText = doc.Text;
			
			//Console.WriteLine ("formattedText3:" + formattedText.Replace ("\t", "->").Replace (" ", "°").Replace ("\n", "\\n").Replace ("\r", "\\r"));
	
			int textLength = CanInsertFormattedText (data, startPos, data.Document.LocationToOffset (caretLocation.Line, caretLocation.Column), formattedText);
			if (textLength > 0) {
//				Console.WriteLine (formattedText.Substring (0, textLength));
				InsertFormattedText (data, startPos, formattedText.Substring (0, textLength).TrimEnd ());
			} else {
				Console.WriteLine ("Can't insert !!!");
			}
			InFormat = false;
		}
开发者ID:pgoron,项目名称:monodevelop,代码行数:68,代码来源:CSharpFormatter.cs

示例11: GetInsertionPoints

		public static List<InsertionPoint> GetInsertionPoints (Document doc, IType type)
		{
			if (doc == null)
				throw new ArgumentNullException ("doc");
			if (type == null)
				throw new ArgumentNullException ("type");
			List<InsertionPoint> result = new List<InsertionPoint> ();
			
			int offset = doc.LocationToOffset (type.BodyRegion.Start.Line, type.BodyRegion.Start.Column);
			if (offset < 0)
				return result;
			while (offset < doc.Length && doc.GetCharAt (offset) != '{' && char.IsWhiteSpace (doc.GetCharAt (offset)))
				offset++;
			var realStartLocation = doc.OffsetToLocation (offset);
			result.Add (GetInsertionPosition (doc, realStartLocation.Line, realStartLocation.Column));
			result[0].LineBefore = NewLineInsertion.None;
			foreach (IMember member in type.Members) {
				DomLocation domLocation = member.BodyRegion.End;
				if (domLocation.Line <= 0) {
					LineSegment lineSegment = doc.GetLine (member.Location.Line);
					if (lineSegment == null)
						continue;
					domLocation = new DomLocation (member.Location.Line, lineSegment.EditableLength + 1);
				}
				result.Add (GetInsertionPosition (doc, domLocation.Line, domLocation.Column));
			}
			result[result.Count - 1].LineAfter = NewLineInsertion.None;
			CheckStartPoint (doc, result[0], result.Count == 1);
			if (result.Count > 1)
				CheckEndPoint (doc, result[result.Count - 1], result.Count == 1);
			return result;
		}
开发者ID:pgoron,项目名称:monodevelop,代码行数:32,代码来源:HelperMethods.cs

示例12: GetInsertionPosition

		static InsertionPoint GetInsertionPosition (Document doc, int line, int column)
		{
			int bodyEndOffset = doc.LocationToOffset (line, column) + 1;
			
			LineSegment curLine = doc.GetLine (line);
			if (curLine != null) {
				if (bodyEndOffset < curLine.Offset + curLine.EditableLength)
					return new InsertionPoint (new DocumentLocation (line, column + 1), NewLineInsertion.BlankLine, NewLineInsertion.BlankLine);
			}
			
			LineSegment nextLine = doc.GetLine (line + 1);
			
			int endOffset = nextLine != null ? nextLine.Offset : doc.Length;
			for (int i = bodyEndOffset; i < endOffset; i++) {
				char ch = doc.GetCharAt (i);
				if (!char.IsWhiteSpace (ch))
					return new InsertionPoint (doc.OffsetToLocation (i), NewLineInsertion.BlankLine, NewLineInsertion.BlankLine);
			}
			
			if (nextLine == null)
				return new InsertionPoint (doc.OffsetToLocation (bodyEndOffset - 1), NewLineInsertion.BlankLine, NewLineInsertion.BlankLine);
			int oldLine = line;
			while (line < doc.LineCount && doc.GetLineIndent (line + 1).Length == doc.GetLine (line + 1).EditableLength)
				line++;
			NewLineInsertion insertBefore = NewLineInsertion.None;
			NewLineInsertion insertAfter = NewLineInsertion.None;
			int delta = line - oldLine;
			int lineNumber = line + 1;
			
			if (delta == 0) {
				insertBefore = NewLineInsertion.Eol;
				insertAfter = NewLineInsertion.BlankLine;
			} else if (delta == 1) {
				insertAfter = NewLineInsertion.BlankLine;
			} else if (delta == 2) {
				lineNumber--;
				insertAfter = NewLineInsertion.BlankLine;
			} else if (delta >= 3) {
				lineNumber -= 2;
				insertAfter = NewLineInsertion.None;
			}
			
			return new InsertionPoint (new DocumentLocation (lineNumber, doc.GetLineIndent (lineNumber).Length + 1), insertBefore, insertAfter);
		}
开发者ID:pgoron,项目名称:monodevelop,代码行数:44,代码来源:HelperMethods.cs

示例13: GetInsertionPoints

		public static List<InsertionPoint> GetInsertionPoints (Document doc, IType type)
		{
			if (doc == null)
				throw new ArgumentNullException ("doc");
			if (type == null)
				throw new ArgumentNullException ("type");
			List<InsertionPoint> result = new List<InsertionPoint> ();
			result.Add (GetInsertionPosition (doc, type.BodyRegion.Start.Line - 1, type.BodyRegion.Start.Column));
			result[0].ShouldInsertNewLineBefore = false;
			foreach (IMember member in type.Members) {
				DomLocation domLocation = member.BodyRegion.End;
				if (domLocation.Line <= 0) {
					LineSegment lineSegment = doc.GetLine (member.Location.Line - 1);
					if (lineSegment == null)
						continue;
					domLocation = new DomLocation (member.Location.Line, lineSegment.EditableLength + 1);
				}
				result.Add (GetInsertionPosition (doc, domLocation.Line - 1, domLocation.Column - 1));
			}
			result[result.Count - 1].ShouldInsertNewLineAfter = false;
			CheckStartPoint (doc, result[0]);
			if (result.Count > 1)
				CheckEndPoint (doc, result[result.Count - 1]);
			return result;
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:25,代码来源:HelperMethods.cs

示例14: GetInsertionPosition

		static InsertionPoint GetInsertionPosition (Document doc, int line, int column)
		{
			LineSegment nextLine = doc.GetLine (line + 1);
			int bodyEndOffset = doc.LocationToOffset (line, column) + 1;
			int endOffset = nextLine != null ? nextLine.Offset : doc.Length;
			for (int i = bodyEndOffset; i < endOffset; i++) {
				char ch = doc.GetCharAt (i);
				if (!char.IsWhiteSpace (ch))
					return new InsertionPoint (doc.OffsetToLocation (i), true, true);
			}
			
			if (nextLine == null)
				return new InsertionPoint (doc.OffsetToLocation (bodyEndOffset - 1), true, true);
			int oldLine = line;
			bool curLineEmpty = false;
			if (doc.GetLineIndent (nextLine).Length == nextLine.EditableLength) {
				curLineEmpty = true;
				while (line + 2 < doc.LineCount && doc.GetLineIndent (line + 2).Length == doc.GetLine (line + 2).EditableLength)
					line++;
			}
			bool insertBefore = !curLineEmpty && line - oldLine <= 1;
			bool insertAfter  = line - oldLine == 0;
//			if (curLineEmpty)
//				line++;
			int lineNumber = line + 1;
			return new InsertionPoint (new DocumentLocation (lineNumber, doc.GetLineIndent (lineNumber).Length), insertBefore, insertAfter);
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:27,代码来源:HelperMethods.cs

示例15: CheckStartPoint

		static void CheckStartPoint (Document doc, InsertionPoint point)
		{
			LineSegment line = doc.GetLine (point.Location.Line);
			if (line == null)
				return;
			if (doc.GetLineIndent (line).Length < point.Location.Column)
				point.ShouldInsertNewLineBefore = true;
			if (point.Location.Column < line.EditableLength)
				point.ShouldInsertNewLineAfter = true;
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:10,代码来源:HelperMethods.cs


注:本文中的Mono.TextEditor.Document.GetLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。