diff --git a/CommentFormattingTests/CommentFormattingTests.cs b/CommentFormattingTests/CommentFormattingTests.cs
index 119a05d..d1de61b 100644
--- a/CommentFormattingTests/CommentFormattingTests.cs
+++ b/CommentFormattingTests/CommentFormattingTests.cs
@@ -10,10 +10,10 @@ namespace UnitTestProject1
[TestMethod]
public void InnerIsntLongEnoughTest()
{
- var xml = @"Initializes a new instance of the class.";
+ var xmlComment = @"Initializes a new instance of the class.";
var expected = @"/// Initializes a new instance of the class.\r\n";
- var actual = CommentFormatting.FormatInnerSummary(xml);
+ var actual = CommentFormatting.FormatInnerSummary(xmlComment);
Assert.AreEqual(expected, actual);
}
@@ -21,10 +21,10 @@ namespace UnitTestProject1
[TestMethod]
public void SimpleInnerTest()
{
- var xml = @"Indicates that the first week of the year begins on the first occurrence of the designated first day of the week on or after the first day of the year. The value is 1.";
+ var xmlComment = @"Indicates that the first week of the year begins on the first occurrence of the designated first day of the week on or after the first day of the year. The value is 1.";
var expected = "/// Indicates that the first week of the year begins on the first occurrence of the designated\r\n/// first day of the week on or after the first day of the year. The value is 1.\r\n";
- var actual = CommentFormatting.FormatInnerSummary(xml);
+ var actual = CommentFormatting.FormatInnerSummary(xmlComment);
Assert.AreEqual(expected, actual);
}
@@ -32,10 +32,10 @@ namespace UnitTestProject1
[TestMethod]
public void LongerSimpleInnerTest()
{
- var xml = @"Searches for the specified character and returns the zero - based index of the first occurrence within the section of the source string that starts at the specified index and contains the specified number of elements.";
+ var xmlComment = @"Searches for the specified character and returns the zero - based index of the first occurrence within the section of the source string that starts at the specified index and contains the specified number of elements.";
var expected = "/// Searches for the specified character and returns the zero - based index of the first occurrence\r\n/// within the section of the source string that starts at the specified index and contains the specified\r\n/// number of elements.\r\n";
- var actual = CommentFormatting.FormatInnerSummary(xml);
+ var actual = CommentFormatting.FormatInnerSummary(xmlComment);
Assert.AreEqual(expected, actual);
}
@@ -43,9 +43,20 @@ namespace UnitTestProject1
[TestMethod]
public void HasAnXmlTagTest()
{
- var str = @"asdasdasdasdasdasd asd as asd asd asd ";
+ var xmlComment = @"asdasdasdasdasdasd asd as asd asd asd ";
- Assert.IsTrue(CommentFormatting.HasAnXmlTag(str));
+ Assert.IsTrue(CommentFormatting.HasAnXmlTag(xmlComment));
+ }
+
+ [TestMethod]
+ public void HasXmlTagAtLowerBoundAndBeyondLimitTest()
+ {
+ var xmlComment = @"Initializes a new instance of the super duper duper duper class.";
+
+ var expected = "/// Initializes a new instance of the super duper duper duper\r\n/// class.\r\n";
+ var actual = CommentFormatting.FormatInnerSummary(xmlComment);
+
+ Assert.AreEqual(expected, actual);
}
}
}
diff --git a/ImportComments/CommentFormatting.cs b/ImportComments/CommentFormatting.cs
index 88701a3..5f60b63 100644
--- a/ImportComments/CommentFormatting.cs
+++ b/ImportComments/CommentFormatting.cs
@@ -1,11 +1,5 @@
using System;
using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Text.RegularExpressions;
-using System.Threading.Tasks;
-using System.Xml;
namespace ImportComments
{
@@ -19,7 +13,8 @@ namespace ImportComments
if (hastag)
{
- // we know to be a bit more careful here
+ var substrings = GetSubstrings(innerXml);
+ return $"/// {string.Join("\r\n/// ", substrings)}\r\n";
}
else
{
@@ -36,7 +31,7 @@ namespace ImportComments
var substrings = new List();
int start = 0;
- int low = 90;
+ int lowerBound = 90;
bool inTag = false;
for (int i = 0; i < s.Length; i++)
@@ -51,31 +46,37 @@ namespace ImportComments
inTag = false;
}
- if (IsLongEnough(i, low) && char.IsWhiteSpace(s[i]))
+ if (IsLongEnough(i, lowerBound) && char.IsWhiteSpace(s[i]))
{
if (inTag)
{
- // if end of tag <= 120 and if what follows isn't punctuation, split at end
- // if what follows is a period and we're at the end, break out
+ var endAndOkay = EndOfTagAndIsItOkay(s, i, limit: 120);
- var endOfTagAndIsItOkay = EndOfTagAndIsItOkay(s, i, limit: 120);
-
- if (endOfTagAndIsItOkay.Item2)
+ if (endAndOkay.Item2)
{
- int end = endOfTagAndIsItOkay.Item1;
+ int end = endAndOkay.Item1;
if (end < s.Length && IsPunctuation(s[end + 1]))
{
- // split after the punctuation
+ // Split after the punctuation.
substrings.Add(s.Substring(start, end + 1 - start).Trim());
}
}
+ else // The tag exceeds our limit of 120 chars, so we split at the beginning of the tag.
+ {
+ int endOfTag = endAndOkay.Item1;
+ substrings.Add(s.Substring(start, endOfTag - start).Trim());
+
+ start += endOfTag - start;
+ }
}
+ else
+ {
+ substrings.Add(s.Substring(start, i - start).Trim());
- substrings.Add(s.Substring(start, i - start).Trim());
-
- start += i - start;
- low += 100;
+ start += i - start;
+ lowerBound += 100;
+ }
}
}
@@ -84,6 +85,7 @@ namespace ImportComments
return substrings;
}
+ // Boy it sure would be nice to have those C# 7 tuples.
private static Tuple EndOfTagAndIsItOkay(string s, int i, int limit)
{
for (; i <= limit; i++)
@@ -94,7 +96,9 @@ namespace ImportComments
}
}
- return Tuple.Create(limit, false);
+ while (s[++i] != '>') ; // Scan until we reach the end of the tag.
+
+ return Tuple.Create(i, false);
}
private static bool IsPunctuation(char c) => c == '.' || c == ',' || c == '!' || c == '?';
@@ -104,16 +108,16 @@ namespace ImportComments
var substrings = new List();
int start = 0;
- int low = 90;
+ int lowerBound = 90;
for (int i = 0; i < s.Length; i++)
{
- if (IsLongEnough(i, low) && char.IsWhiteSpace(s[i]))
+ if (IsLongEnough(i, lowerBound) && char.IsWhiteSpace(s[i]))
{
substrings.Add(s.Substring(start, i - start).Trim());
start += i - start;
- low += 100;
+ lowerBound += 100;
}
}