From c2202bbfc09c85a2afa67615dbd9c0c91ac34b58 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 6 Oct 2015 03:39:22 +0300 Subject: [PATCH] Removed the wrapping of comments because tools ignore empty lines. Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/Template.cs | 23 ++---- src/Generator/Utils/Utils.cs | 102 +++------------------------ 2 files changed, 15 insertions(+), 110 deletions(-) diff --git a/src/Generator/Generators/Template.cs b/src/Generator/Generators/Template.cs index 9748f745..6dcf2caa 100644 --- a/src/Generator/Generators/Template.cs +++ b/src/Generator/Generators/Template.cs @@ -126,22 +126,6 @@ namespace CppSharp.Generators if (childBlock.isSubBlock) totalIndent = 0; - if (childBlock.Kind == BlockKind.BlockComment) - { - // Wrap the comment to the max line width. - var maxSize = options.MaxIndent - totalIndent; - maxSize -= options.CommentPrefix.Length + 2; - - lines = StringHelpers.WordWrapLines(childText, (int)maxSize); - - for (var i = 0; i < lines.Count; ++i) - { - var line = lines[i]; - if (!line.StartsWith(options.CommentPrefix)) - lines[i] = options.CommentPrefix + " " + line; - } - } - foreach (var line in lines) { if (string.IsNullOrEmpty(line)) @@ -150,6 +134,13 @@ namespace CppSharp.Generators if (!string.IsNullOrWhiteSpace(line)) builder.Append(new string(' ', (int)totalIndent)); + + if (childBlock.Kind == BlockKind.BlockComment && + !line.StartsWith(options.CommentPrefix)) + { + builder.Append(options.CommentPrefix); + builder.Append(' '); + } builder.Append(line); if (!line.EndsWith(Environment.NewLine)) diff --git a/src/Generator/Utils/Utils.cs b/src/Generator/Utils/Utils.cs index d5f7375e..dc9d4256 100644 --- a/src/Generator/Utils/Utils.cs +++ b/src/Generator/Utils/Utils.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text.RegularExpressions; -using CppSharp.AST; namespace CppSharp { @@ -33,12 +32,9 @@ namespace CppSharp foreach (char c in ss[0]) { - foreach (string s in ss) + if (ss.Any(s => s.Length <= prefixLength || s[prefixLength] != c)) { - if (s.Length <= prefixLength || s[prefixLength] != c) - { - return ss[0].Substring(0, prefixLength); - } + return ss[0].Substring(0, prefixLength); } prefixLength++; } @@ -46,84 +42,6 @@ namespace CppSharp return ss[0]; // all strings identical } - /// - /// Word wraps the given text to fit within the specified width. - /// - /// Text to be word wrapped - /// Width, in characters, to which the text - /// should be word wrapped - /// The modified text - public static List WordWrapLines(string text, int width) - { - int pos, next; - var lines = new List(); - - // Lucidity check - if (width < 1) - { - lines.Add(text); - return lines; - } - - // Parse each line of text - for (pos = 0; pos < text.Length; pos = next) - { - // Find end of line - int eol = text.IndexOf(Environment.NewLine, pos, - System.StringComparison.Ordinal); - if (eol == -1) - next = eol = text.Length; - else - next = eol + Environment.NewLine.Length; - - // Copy this line of text, breaking into smaller lines as needed - if (eol > pos) - { - do - { - int len = eol - pos; - if (len > width) - len = BreakLine(text, pos, width); - lines.Add(text.Substring(pos, len)); - - // Trim whitespace following break - pos += len; - while (pos < eol && Char.IsWhiteSpace(text[pos])) - pos++; - } while (eol > pos); - } - else lines.Add(string.Empty); // Empty line - } - return lines; - } - - /// - /// Locates position to break the given line so as to avoid - /// breaking words. - /// - /// String that contains line of text - /// Index where line of text starts - /// Maximum line length - /// The modified line length - private static int BreakLine(string text, int pos, int max) - { - // Find last whitespace in line - int i = max; - while (i >= 0 && !Char.IsWhiteSpace(text[pos + i])) - i--; - - // If no whitespace found, break at maximum length - if (i < 0) - return max; - - // Find start of whitespace - while (i >= 0 && Char.IsWhiteSpace(text[pos + i])) - i--; - - // Return length of text before whitespace - return i + 1; - } - public static void CleanupText(ref string debugText) { // Strip off newlines from the debug text. @@ -146,13 +64,9 @@ namespace CppSharp public static IEnumerable SplitAndKeep(this string s, string seperator) { - string[] obj = s.Split(new string[] { seperator }, StringSplitOptions.None); + string[] obj = s.Split(new[] { seperator }, StringSplitOptions.None); - for (int i = 0; i < obj.Length; i++) - { - string result = i == obj.Length - 1 ? obj[i] : obj[i] + seperator; - yield return result; - } + return obj.Select((t, i) => i == obj.Length - 1 ? t : t + seperator); } public static string UppercaseFirst(string s) @@ -206,8 +120,8 @@ namespace CppSharp public static class AssemblyHelpers { - public static IEnumerable FindDerivedTypes(this Assembly assembly, - System.Type baseType) + public static IEnumerable FindDerivedTypes(this Assembly assembly, + Type baseType) { return assembly.GetTypes().Where(baseType.IsAssignableFrom); } @@ -220,8 +134,8 @@ namespace CppSharp var path1 = fromPath.Trim('\\', '/'); var path2 = toPath.Trim('\\', '/'); - var uri1 = new System.Uri("c:\\" + path1 + "\\"); - var uri2 = new System.Uri("c:\\" + path2 + "\\"); + var uri1 = new Uri("c:\\" + path1 + "\\"); + var uri2 = new Uri("c:\\" + path2 + "\\"); return uri1.MakeRelativeUri(uri2).ToString(); }