Browse Source

Removed the wrapping of comments because tools ignore empty lines.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/573/head
Dimitar Dobrev 10 years ago
parent
commit
c2202bbfc0
  1. 23
      src/Generator/Generators/Template.cs
  2. 102
      src/Generator/Utils/Utils.cs

23
src/Generator/Generators/Template.cs

@ -126,22 +126,6 @@ namespace CppSharp.Generators @@ -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 @@ -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))

102
src/Generator/Utils/Utils.cs

@ -3,7 +3,6 @@ using System.Collections.Generic; @@ -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 @@ -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 @@ -46,84 +42,6 @@ namespace CppSharp
return ss[0]; // all strings identical
}
/// <summary>
/// Word wraps the given text to fit within the specified width.
/// </summary>
/// <param name="text">Text to be word wrapped</param>
/// <param name="width">Width, in characters, to which the text
/// should be word wrapped</param>
/// <returns>The modified text</returns>
public static List<string> WordWrapLines(string text, int width)
{
int pos, next;
var lines = new List<string>();
// 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;
}
/// <summary>
/// Locates position to break the given line so as to avoid
/// breaking words.
/// </summary>
/// <param name="text">String that contains line of text</param>
/// <param name="pos">Index where line of text starts</param>
/// <param name="max">Maximum line length</param>
/// <returns>The modified line length</returns>
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 @@ -146,13 +64,9 @@ namespace CppSharp
public static IEnumerable<string> 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 @@ -206,8 +120,8 @@ namespace CppSharp
public static class AssemblyHelpers
{
public static IEnumerable<System.Type> FindDerivedTypes(this Assembly assembly,
System.Type baseType)
public static IEnumerable<Type> FindDerivedTypes(this Assembly assembly,
Type baseType)
{
return assembly.GetTypes().Where(baseType.IsAssignableFrom);
}
@ -220,8 +134,8 @@ namespace CppSharp @@ -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();
}

Loading…
Cancel
Save