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


C# IDocument.Replace方法代码示例

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


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

示例1: IndentSingleLine

		static void IndentSingleLine(CacheIndentEngine engine, IDocument document, IDocumentLine line)
		{
			engine.Update(line.EndOffset);
			if (engine.NeedsReindent) {
				var indentation = TextUtilities.GetWhitespaceAfter(document, line.Offset);
				// replacing the indentation in two steps is necessary to make the caret move accordingly.
				document.Replace(indentation.Offset, indentation.Length, "");
				document.Replace(indentation.Offset, 0, engine.ThisLineIndent);
				engine.ResetEngineToPosition(line.Offset);
			}
		}
开发者ID:krunalc,项目名称:SharpDevelop,代码行数:11,代码来源:CSharpFormattingStrategy.cs

示例2: SortLines

		public void SortLines(IDocument document, int startLine, int endLine, StringComparer comparer, bool removeDuplicates)
		{
			List<string> lines = new List<string>();
			for (int i = startLine; i <= endLine; ++i) {
				IDocumentLine line = document.GetLine(i);
				lines.Add(document.GetText(line.Offset, line.Length));
			}
			
			lines.Sort(comparer);
			
			if (removeDuplicates) {
				lines = lines.Distinct(comparer).ToList();
			}
			
			using (document.OpenUndoGroup()) {
				for (int i = 0; i < lines.Count; ++i) {
					IDocumentLine line = document.GetLine(startLine + i);
					document.Replace(line.Offset, line.Length, lines[i]);
				}
				
				// remove removed duplicate lines
				for (int i = startLine + lines.Count; i <= endLine; ++i) {
					IDocumentLine line = document.GetLine(startLine + lines.Count);
					document.Remove(line.Offset, line.TotalLength);
				}
			}
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:27,代码来源:SortSelectionCommand.cs

示例3: ReplaceFieldDeclaration

		protected override void ReplaceFieldDeclaration(IDocument document, IField oldField, string newFieldDeclaration)
		{
			// In VB, the field region begins at the start of the declaration
			// and ends on the first column of the line following the declaration.
			int startOffset = document.PositionToOffset(oldField.Region.BeginLine, 1);
			int endOffset   = document.PositionToOffset(oldField.Region.EndLine, 1);
			document.Replace(startOffset, endOffset - startOffset, tabs + newFieldDeclaration + Environment.NewLine);
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:8,代码来源:VBNetDesignerGenerator.cs

示例4: RemoveDiacritics

 public void RemoveDiacritics(IDocument document)
 {
     lexerFactory()
         .LexWords(document)
         .Where(segment => wordProcessor.HasDiacritics(segment.Word))
         .ForEach(segment => document.Replace(segment,
             wordProcessor.RemoveDiacritics(segment.Word)));
 }
开发者ID:tomachristian,项目名称:ProjectUniMTP,代码行数:8,代码来源:DefaultDocumentProcessor.cs

示例5: SmartReplaceLine

        /// <summary>
        /// Replaces the text in a line.
        /// If only whitespace at the beginning and end of the line was changed, this method
        /// only adjusts the whitespace and doesn't replace the other text.
        /// </summary>
        public static void SmartReplaceLine(IDocument document, LineSegment line, string newLineText)
        {
            if (document == null)
            throw new ArgumentNullException("document");
              if (line == null)
            throw new ArgumentNullException("line");
              if (newLineText == null)
            throw new ArgumentNullException("newLineText");
              string newLineTextTrim = newLineText.Trim(_whitespaceChars);
              string oldLineText = document.GetText(line);
              if (oldLineText == newLineText)
            return;
              int pos = oldLineText.IndexOf(newLineTextTrim);
              if (newLineTextTrim.Length > 0 && pos >= 0)
              {
            document.UndoStack.StartUndoGroup();
            try
            {
              // find whitespace at beginning
              int startWhitespaceLength = 0;
              while (startWhitespaceLength < newLineText.Length)
              {
            char c = newLineText[startWhitespaceLength];
            if (c != ' ' && c != '\t')
              break;
            startWhitespaceLength++;
              }
              // find whitespace at end
              int endWhitespaceLength = newLineText.Length - newLineTextTrim.Length - startWhitespaceLength;

              // replace whitespace sections
              int lineOffset = line.Offset;
              document.Replace(lineOffset + pos + newLineTextTrim.Length, line.Length - pos - newLineTextTrim.Length, newLineText.Substring(newLineText.Length - endWhitespaceLength));
              document.Replace(lineOffset, pos, newLineText.Substring(0, startWhitespaceLength));
            }
            finally
            {
              document.UndoStack.EndUndoGroup();
            }
              }
              else
              {
            document.Replace(line.Offset, line.Length, newLineText);
              }
        }
开发者ID:cavaliercoder,项目名称:expression-lab,代码行数:50,代码来源:DefaultFormattingStrategy.cs

示例6: Convert

        protected override void Convert(IDocument document, int startOffset, int length)
        {
            StringBuilder what = new StringBuilder(document.GetText(startOffset, length));

            for (int i = 0; i < what.Length; ++i) {
                if (!Char.IsLetter(what[i]) && i < what.Length - 1) {
                    what[i + 1] = Char.ToUpper(what[i + 1]);
                }
            }
            document.Replace(startOffset, length, what.ToString());
        }
开发者ID:slluis,项目名称:monodevelop-prehistoric,代码行数:11,代码来源:FormatActions.cs

示例7: RenumberOrderedList

 private static void RenumberOrderedList(
     IDocument document,
     DocumentLine line,
     int number)
 {
     while ((line = line.NextLine) != null)
     {
         number += 1;
         var text = document.GetText(line.Offset, line.Length);
         var match = OrderedListPattern.Match(text);
         if (match.Success == false) break;
         var group = match.Groups[1];
         var currentNumber = int.Parse(group.Value);
         if (currentNumber != number) document.Replace(line.Offset + group.Index, group.Length, number.ToString());
     }
 }
开发者ID:foukation,项目名称:Markdown-Edit,代码行数:16,代码来源:LineContinuationEnterCommand.cs

示例8: Convert

		protected override void Convert(IDocument document, int y1, int y2) 
		{
			for (int i = y2; i >= y1; --i) {
				LineSegment line = document.GetLineSegment(i);
				
				if(line.Length > 0) {
					// count how many whitespace characters there are at the start
					int whiteSpace = 0;
					for(whiteSpace = 0; whiteSpace < line.Length && Char.IsWhiteSpace(document.GetCharAt(line.Offset + whiteSpace)); whiteSpace++) {
						// deliberately empty
					}
					if(whiteSpace > 0) {
						string newLine = document.GetText(line.Offset,whiteSpace);
						string newPrefix = newLine.Replace("\t",new string(' ', document.TextEditorProperties.TabIndent));
						document.Replace(line.Offset,whiteSpace,newPrefix);
					}
				}
			}
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:19,代码来源:FormatActions.cs

示例9: UpdateMethodBody

		public void UpdateMethodBody(IDocument document, IMethod method, string methodBody)
		{
			DomRegion methodRegion = GetBodyRegionInDocument(method);
			int startOffset = GetStartOffset(document, methodRegion);
			int endOffset = GetEndOffset(document, methodRegion);

			document.Replace(startOffset, endOffset - startOffset, methodBody);
		}
开发者ID:nylen,项目名称:SharpDevelop,代码行数:8,代码来源:ScriptingDesignerGenerator.cs

示例10: SwapText

		/// <summary>
		/// Swaps 2 ranges of text in a document.
		/// </summary>
		static void SwapText(IDocument document, Location start1, Location end1, Location start2, Location end2)
		{
			if (start1 > start2) {
				Location sw;
				sw = start1; start1 = start2; start2 = sw;
				sw = end1; end1 = end2; end2 = sw;
			}
			if (end1 >= start2)
				throw new InvalidOperationException("Cannot swap overlaping segments");
			int offset1 = document.PositionToOffset(start1);
			int len1 = document.PositionToOffset(end1) - offset1;
			int offset2 = document.PositionToOffset(start2);
			int len2 = document.PositionToOffset(end2) - offset2;
			
			string text1 = document.GetText(offset1, len1);
			string text2 = document.GetText(offset2, len2);
			
			using (var undoGroup = document.OpenUndoGroup()) {
				document.Replace(offset2, len2, text1);
				document.Replace(offset1, len1, text2);
			}
		}
开发者ID:hpsa,项目名称:SharpDevelop,代码行数:25,代码来源:CodeManipulation.cs

示例11: ModifyDocument

		public static void ModifyDocument(List<Modification> modifications, IDocument doc, int offset, int length, string newName)
		{
			using (doc.OpenUndoGroup()) {
				foreach (Modification m in modifications) {
					if (m.Document == doc) {
						if (m.Offset < offset)
							offset += m.LengthDifference;
					}
				}
				int lengthDifference = newName.Length - length;
				doc.Replace(offset, length, newName);
				if (lengthDifference != 0) {
					for (int i = 0; i < modifications.Count; ++i) {
						Modification m = modifications[i];
						if (m.Document == doc) {
							if (m.Offset > offset) {
								m.Offset += lengthDifference;
								modifications[i] = m; // Modification is a value type
							}
						}
					}
					modifications.Add(new Modification(doc, offset, lengthDifference));
				}
			}
		}
开发者ID:lisiynos,项目名称:pascalabcnet,代码行数:25,代码来源:FindReferencesAndRenameHelper.cs

示例12: Convert

		protected override void Convert(IDocument document, int y1, int y2) 
		{
			int  redocounter = 0;
			for (int i = y2; i >= y1; --i) {
				LineSegment line = document.GetLineSegment(i);
				if(line.Length > 0) {
					// note: some users may prefer a more radical ConvertLeadingSpacesToTabs that
					// means there can be no spaces before the first character even if the spaces
					// didn't add up to a whole number of tabs
					string newLine = TextUtilities.LeadingWhiteSpaceToTabs(document.GetText(line.Offset,line.Length), document.TextEditorProperties.TabIndent);
					document.Replace(line.Offset,line.Length,newLine);
					++redocounter;
				}
			}
			
			if (redocounter > 0) {
				document.UndoStack.CombineLast(redocounter); // redo the whole operation (not the single deletes)
			}
		}
开发者ID:stophun,项目名称:fdotoolbox,代码行数:19,代码来源:FormatActions.cs

示例13: ReplaceFieldDeclaration

		/// <summary>
		/// Replaces a field declaration in the source code document.
		/// </summary>
		/// <remarks>
		/// The default implementation assumes that the field region starts at the very beginning
		/// of the line of the field declaration and ends at the end of that line.
		/// Override this method if that is not the case in a specific language.
		/// </remarks>
		protected virtual void ReplaceFieldDeclaration(IDocument document, IField oldField, string newFieldDeclaration)
		{
			int startOffset = document.PositionToOffset(oldField.Region.BeginLine, 1);
			int endOffset   = document.PositionToOffset(oldField.Region.EndLine + 1, 1);
			document.Replace(startOffset, endOffset - startOffset, tabs + newFieldDeclaration + Environment.NewLine);
		}
开发者ID:TiberiuGal,项目名称:SharpDevelop,代码行数:14,代码来源:AbstractDesignerGenerator.cs

示例14: Apply

 public void Apply(IDocument document)
 {
     using (document.OpenUndoGroup()) {
         var changes = oldVersion.GetChangesTo(newVersion);
         foreach (var change in changes)
             document.Replace(change.Offset, change.RemovalLength, change.InsertedText);
     }
 }
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:8,代码来源:SearchResultMatch.cs

示例15: SortLines

		public void SortLines(IDocument document, int startLine, int endLine)
		{
			ArrayList lines = new ArrayList();
			for (int i = startLine; i <= endLine; ++i) {
				LineSegment line = document.GetLineSegment(i);
				lines.Add(document.GetText(line.Offset, line.Length));
			}
			
			lines.Sort(new SortComparer());
			
			bool removeDupes = PropertyService.Get(SortOptionsDialog.removeDupesOption, false);
			if (removeDupes) {
				for (int i = 0; i < lines.Count - 1; ++i) {
					if (lines[i].Equals(lines[i + 1])) {
						lines.RemoveAt(i);
						--i;
					}
				}
			}
			
			for (int i = 0; i < lines.Count; ++i) {
				LineSegment line = document.GetLineSegment(startLine + i);
				document.Replace(line.Offset, line.Length, lines[i].ToString());
			}
			
			// remove removed duplicate lines
			for (int i = startLine + lines.Count; i <= endLine; ++i) {
				LineSegment line = document.GetLineSegment(startLine + lines.Count);
				document.Remove(line.Offset, line.TotalLength);
			}
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:31,代码来源:FormatCommands.cs


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