public void ToCodeLine(ref CodeLine result, ITextSyntaxFormatter builder) { int lineCount = LineCount(); if (lineCount == 0) { result.formatted = ""; result.unformatted = ""; return; } var sbUnformatted = new StringBuilder(25); var sb = new StringBuilder(25); int count = blocks.Count; for (int n = 0; n < count; n++) { var block = blocks[n]; if (block.IsLineBreak()) { break; } sbUnformatted.Append(block.ContentUnformatted); block.ToString(ref sb, builder); } result.unformatted = sbUnformatted.ToString(); result.formatted = sb.ToString(); }
public static void Replace(ref CodeLine replace, string unformatted, ITextSyntaxFormatter builder) { if (replace == null) { replace = Create(unformatted, builder); } else { replace.Set(unformatted, builder); } }
public static CodeLine Create(string unformatted, ITextSyntaxFormatter builder) { CodeLine result; if (!pool.TryGet(out result)) { return(new CodeLine(unformatted, builder)); } result.Set(unformatted, builder); return(result); }
public void ToString(ref StringBuilder sb, ITextSyntaxFormatter builder) { switch (type) { case CodeBlockType.PreprocessorDirective: sb.Append(InspectorUtility.Preferences.theme.SyntaxHighlight.PreprocessorDirectiveColorTag); sb.Append(ContentWithTabToSpace); sb.Append("</color>"); return; case CodeBlockType.CommentLine: case CodeBlockType.CommentBlock: sb.Append(builder.CommentColorTag); sb.Append(ContentWithTabToSpace); sb.Append("</color>"); return; case CodeBlockType.Number: sb.Append(builder.NumberColorTag); sb.Append(content); sb.Append("</color>"); return; case CodeBlockType.Type: sb.Append(InspectorUtility.Preferences.theme.SyntaxHighlight.TypeColorTag); sb.Append(content); sb.Append("</color>"); return; case CodeBlockType.String: case CodeBlockType.Char: sb.Append(builder.StringColorTag); sb.Append(ContentWithTabToSpace); sb.Append("</color>"); return; case CodeBlockType.Keyword: sb.Append(builder.KeywordColorTag); sb.Append(content); sb.Append("</color>"); return; case CodeBlockType.LineBreak: case CodeBlockType.Unformatted: sb.Append(content); return; default: sb.Append(ContentWithTabToSpace); return; } }
public void Dispose() { if (builder != null) { builder.Dispose(); builder = null; } for (int n = LineCount - 1; n >= 0; n--) { CodeLinePool.Dispose(ref lines[n]); } }
public void Set(string value, ITextSyntaxFormatter builder) { unformatted = value; if (value.Length == 0) { formatted = value; } else { //this isn't perfect, would need to recreate syntax formatting //for whole code to handle stuff like /*-blocks builder.SetCode(value); builder.BuildAllBlocks(); var val = this; builder.GeneratedBlocks.ToCodeLine(ref val, builder); } }
private void ToCodeLines(ref CodeLine[] result, ITextSyntaxFormatter builder) { int lineCount = LineCount(); if (result == null) { result = new CodeLine[0]; } else if (result.Length != lineCount) { Array.Resize(ref result, lineCount); } if (lineCount == 0) { return; } var sbUnformatted = new StringBuilder(25); var sb = new StringBuilder(25); int lineIndex = 0; int count = blocks.Count; for (int n = 0; n < count; n++) { var block = blocks[n]; if (block.IsLineBreak()) { result[lineIndex] = new CodeLine(sbUnformatted.ToString(), sb.ToString()); sbUnformatted.Length = 0; sb.Length = 0; lineIndex++; } else { sbUnformatted.Append(block.ContentUnformatted); block.ToString(ref sb, builder); } } result[lineIndex] = new CodeLine(sbUnformatted.ToString(), sb.ToString()); }
public void ToCode(ref Code result, ITextSyntaxFormatter builder, FontCharSizes fontCharSizes) { ToCodeLines(ref result.lines, builder); result.width = Width(fontCharSizes); }
public CodeLine(string unformatted, ITextSyntaxFormatter builder) { Set(unformatted, builder); }
public static void Create(string[] linesUnformatted, string[] linesFormatted, ITextSyntaxFormatter builder, ref CodeLine[] result) { int count = linesFormatted.Length; int unformattedCount = linesUnformatted.Length; if (unformattedCount != count) { //TO DO: set a boolean flag or something that triggers this warning from the main thread instead #if !USE_THREADING Debug.Log("WARNING: linesFormatted.Length (" + count + ") != linesUnformatted.Length (" + unformattedCount + ")"); #endif Array.Resize(ref linesUnformatted, count); } int oldCount = result.Length; if (oldCount != count) { for (int n = oldCount - 1; n >= count; n--) { Dispose(ref result[n]); } Array.Resize(ref result, count); } for (int n = count - 1; n >= 0; n--) { Replace(ref result[n], linesUnformatted[n], builder); } }
public Code(ITextSyntaxFormatter codeBuilder) { lines = new CodeLine[0]; builder = codeBuilder; }