Browse Source

TextGenerator now indents multiple lines of the given string

pull/1/head
marcos henrich 12 years ago
parent
commit
9d2da916ec
  1. 18
      src/Generator/Utils/TextGenerator.cs
  2. 11
      src/Generator/Utils/Utils.cs

18
src/Generator/Utils/TextGenerator.cs

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -24,16 +25,19 @@ namespace Cxxi
public void Write(string msg, params object[] args) public void Write(string msg, params object[] args)
{ {
if (isStartOfLine)
sb.Append(new string(' ', (int)CurrentIndent.Sum(u => u)));
if (args.Length > 0) if (args.Length > 0)
msg = string.Format(msg, args); msg = string.Format(msg, args);
if (msg.Length > 0) foreach(var line in msg.SplitAndKeep(Environment.NewLine))
isStartOfLine = msg.EndsWith(System.Environment.NewLine); {
if (isStartOfLine && !string.IsNullOrWhiteSpace(line))
sb.Append(new string(' ', (int) CurrentIndent.Sum(u => u)));
if (line.Length > 0)
isStartOfLine = line.EndsWith(Environment.NewLine);
sb.Append(msg); sb.Append(line);
}
} }
public void WriteLine(string msg, params object[] args) public void WriteLine(string msg, params object[] args)

11
src/Generator/Utils/Utils.cs

@ -164,6 +164,17 @@ namespace Cxxi
var str = Regex.Replace(input, "([A-Z])", " $1", RegexOptions.Compiled); var str = Regex.Replace(input, "([A-Z])", " $1", RegexOptions.Compiled);
return str.Trim().Split(); return str.Trim().Split();
} }
public static IEnumerable<string> SplitAndKeep(this string s, string seperator)
{
string[] obj = s.Split(new string[] { 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;
}
}
} }
public static class AssemblyHelpers public static class AssemblyHelpers

Loading…
Cancel
Save