AvalonStudio.Languages.CPlusPlus.ClangFormat.FormatXml C# (CSharp) 메소드

FormatXml() 공개 정적인 메소드

public static FormatXml ( string text, uint offset, uint length, uint cursor, ClangFormatSettings settings ) : System.Xml.Linq.XDocument
text string
offset uint
length uint
cursor uint
settings ClangFormatSettings
리턴 System.Xml.Linq.XDocument
		public static XDocument FormatXml(string text, uint offset, uint length, uint cursor, ClangFormatSettings settings)
		{
			var startInfo = new ProcessStartInfo();
			var resultText = string.Empty;

			startInfo.FileName = Path.Combine(Platform.PluginsDirectory, "clang-format" + Platform.ExecutableExtension);
			startInfo.Arguments = string.Format("-offset={0} -length={1} -cursor={2} -style=\"{3}\" -output-replacements-xml",
				offset, length, cursor, settings);

			// Hide console window
			startInfo.UseShellExecute = false;
			startInfo.RedirectStandardOutput = true;
			startInfo.RedirectStandardError = true; //we can get the erros text now.
			startInfo.RedirectStandardInput = true;
			startInfo.CreateNoWindow = true;

			using (var process = Process.Start(startInfo))
			{
				using (var streamWriter = process.StandardInput)
				{
					streamWriter.Write(text);
					streamWriter.Close();

					using (var streamReader = process.StandardOutput)
					{
						resultText = streamReader.ReadToEnd();
					}
				}
			}

			return XDocument.Parse(resultText);
		}
	}

Usage Example

        public int Format(TextDocument textDocument, uint offset, uint length, int cursor)
        {
            var replacements = ClangFormat.FormatXml(textDocument.Text, offset, length, (uint)cursor,
                                                     ClangFormatSettings.Default);

            return(ApplyReplacements(textDocument, cursor, replacements));
        }
All Usage Examples Of AvalonStudio.Languages.CPlusPlus.ClangFormat::FormatXml
ClangFormat