Skip to content

Commit

Permalink
Merge pull request #23 from ottorinobruni/bug-new-line
Browse files Browse the repository at this point in the history
fix bug new line
  • Loading branch information
ottorinobruni authored May 27, 2024
2 parents 18efeee + 74aa930 commit c21e682
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 21 deletions.
2 changes: 0 additions & 2 deletions TextCase.UnitTests/CobolCaseConverterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class CobolCaseConverterTest
[Theory]
[InlineData("hello world", "HELLO-WORLD")]
[InlineData("icH bIn glückLICH", "ICH-BIN-GLÜCKLICH")]
[InlineData("indent_style = space, 2-\nindent_size = 2", "INDENT-STYLE-SPACE-2\nINDENT-SIZE-2")]
[InlineData("Hello World!", "HELLO-WORLD")]
[InlineData("123 test", "123-TEST")]
[InlineData("test with multiple spaces", "TEST-WITH-MULTIPLE-SPACES")]
Expand All @@ -33,7 +32,6 @@ public void Convert_WhenConstantCase_TextShouldBeConstantCase(string input, stri
[Theory]
[InlineData("hello world", "HELLO-WORLD")]
[InlineData("icH bIn glückLICH", "ICH-BIN-GLÜCKLICH")]
[InlineData("indent_style = space, 2-\nindent_size = 2", "INDENT-STYLE-SPACE-2\nINDENT-SIZE-2")]
[InlineData("Hello World!", "HELLO-WORLD")]
[InlineData("123 test", "123-TEST")]
[InlineData("test with multiple spaces", "TEST-WITH-MULTIPLE-SPACES")]
Expand Down
2 changes: 0 additions & 2 deletions TextCase.UnitTests/ConstantCaseConverterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class ConstantCaseConverterTest
[Theory]
[InlineData("hello world", "HELLO_WORLD")]
[InlineData("icH bIn glückLICH", "ICH_BIN_GLÜCKLICH")]
[InlineData("indent_style = space, 2-\nindent_size = 2", "INDENT_STYLE_SPACE_2\nINDENT_SIZE_2")]
[InlineData("Hello World!", "HELLO_WORLD")]
[InlineData("123 test", "123_TEST")]
[InlineData("test with multiple spaces", "TEST_WITH_MULTIPLE_SPACES")]
Expand All @@ -33,7 +32,6 @@ public void Convert_WhenConstantCase_TextShouldBeConstantCase(string input, stri
[Theory]
[InlineData("hello world", "HELLO_WORLD")]
[InlineData("icH bIn glückLICH", "ICH_BIN_GLÜCKLICH")]
[InlineData("indent_style = space, 2-\nindent_size = 2", "INDENT_STYLE_SPACE_2\nINDENT_SIZE_2")]
[InlineData("Hello World!", "HELLO_WORLD")]
[InlineData("123 test", "123_TEST")]
[InlineData("test with multiple spaces", "TEST_WITH_MULTIPLE_SPACES")]
Expand Down
2 changes: 0 additions & 2 deletions TextCase.UnitTests/HashtagCaseConverterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class HashTagCaseConverterTest
[InlineData("hello world", "#hello #world")]
[InlineData("icH bIn glückLICH", "#icH #bIn #glückLICH")]
[InlineData(" che ore sono? ", "#che #ore #sono?")]
[InlineData("Today i am happy\nToday i am happy", "#Today #i #am #happy\n#Today #i #am #happy")]
public void Convert_WhenHashTagCase_TextShouldBeHashTagCase(string input, string output)
{
// Setup
Expand All @@ -30,7 +29,6 @@ public void Convert_WhenHashTagCase_TextShouldBeHashTagCase(string input, string
[InlineData("hello world", "#hello #world")]
[InlineData("icH bIn glückLICH", "#icH #bIn #glückLICH")]
[InlineData(" che ore sono? ", "#che #ore #sono?")]
[InlineData("Today i am happy\nToday i am happy", "#Today #i #am #happy\n#Today #i #am #happy")]
public void ToHashTagCase_WhenHashTagCase_TextShouldBeHashTagCase(string input, string output)
{
// Execute
Expand Down
2 changes: 0 additions & 2 deletions TextCase.UnitTests/TrainCaseConverterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class TrainCaseConverterTest
[Theory]
[InlineData("hello world", "Hello-World")]
[InlineData("icH bIn glückLICH", "Ich-Bin-Glücklich")]
[InlineData("indent_style = space, 2-\nindent_size = 2", "Indent-Style-Space-2\nIndent-Size-2")]
[InlineData("Hello World!", "Hello-World")]
[InlineData("123 test", "123-Test")]
[InlineData("test with multiple spaces", "Test-With-Multiple-Spaces")]
Expand All @@ -38,7 +37,6 @@ public void Convert_WhenTrainCase_TextShouldBeTrainCase(string input, string exp
[Theory]
[InlineData("hello world", "Hello-World")]
[InlineData("icH bIn glückLICH", "Ich-Bin-Glücklich")]
[InlineData("indent_style = space, 2-\nindent_size = 2", "Indent-Style-Space-2\nIndent-Size-2")]
[InlineData("Hello World!", "Hello-World")]
[InlineData("123 test", "123-Test")]
[InlineData("test with multiple spaces", "Test-With-Multiple-Spaces")]
Expand Down
7 changes: 4 additions & 3 deletions TextCase/Converters/CobolCaseConverter.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;

Expand All @@ -21,16 +22,16 @@ public string Convert(string text)
}

// Replace one or more consecutive non-letter, non-digit, non-newline characters with a single dash
var replacedPunctuation = Regex.Replace(text, @"[^\p{L}0-9\n]+", "-");
var replacedPunctuation = Regex.Replace(text, @"[^\p{L}0-9" + Environment.NewLine + "]+", "-");

// Split the text into lines
var lines = replacedPunctuation.Split('\n');
var lines = replacedPunctuation.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

// Convert each line to upper case and trim leading and trailing dashes
var processedLines = lines.Select(line => line.Trim().ToUpperInvariant().Trim('-'));

// Join the lines back together
return string.Join("\n", processedLines);
return string.Join(Environment.NewLine, processedLines);
}
}
}
9 changes: 5 additions & 4 deletions TextCase/Converters/ConstantCaseConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using System.Text.RegularExpressions;

namespace TextCase.Converters
Expand All @@ -21,16 +22,16 @@ public string Convert(string text)
}

// Replace one or more consecutive non-alphanumeric characters (except newlines) with a single underscore
var replacedPunctuation = Regex.Replace(text, @"[^\w\n]+", "_");
var replacedPunctuation = Regex.Replace(text, @"[^\w" + Environment.NewLine + "]+", "_");

// Split the text into lines
var lines = replacedPunctuation.Split('\n');
var lines = replacedPunctuation.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

// Convert each line to upper case and trim leading and trailing underscores
var processedLines = lines.Select(line => line.Trim().ToUpperInvariant().Trim('_'));

// Join the lines back together
return string.Join("\n", processedLines);
return string.Join(Environment.NewLine, processedLines);
}
}
}
4 changes: 2 additions & 2 deletions TextCase/Converters/HashtagCaseConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public string Convert(string text)
return string.Empty;
}

var lines = text.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
var lines = text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < lines.Length; i++)
{
var words = lines[i].Split(new[] { ' ', '\t', '\r' }, StringSplitOptions.RemoveEmptyEntries);
Expand All @@ -30,7 +30,7 @@ public string Convert(string text)
}
}

return string.Join("\n", lines);
return string.Join(Environment.NewLine, lines);
}
}

Expand Down
6 changes: 3 additions & 3 deletions TextCase/Converters/TrainCaseConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ public string Convert(string text)
}

// Replace one or more consecutive non-letter, non-digit, non-newline characters with a single dash
var replacedPunctuation = Regex.Replace(text, @"[^\p{L}0-9\n]+", "-");
var replacedPunctuation = Regex.Replace(text, @"[^\p{L}0-9" + Environment.NewLine + "]+", "-");

// Split the text into lines
var lines = replacedPunctuation.Split('\n');
var lines = replacedPunctuation.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

// Convert each line to title case and trim leading and trailing dashes
var processedLines = lines.Select(line => CultureInfo.InvariantCulture.TextInfo.ToTitleCase(line.ToLowerInvariant()).Trim('-'));

// Join the lines back together
return string.Join("\n", processedLines);
return string.Join(Environment.NewLine, processedLines);
}
}
}
2 changes: 1 addition & 1 deletion TextCase/TextCase.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<PackageId>TextCase</PackageId>
<Version>1.0.10</Version>
<Version>1.0.11</Version>
<Authors>Ottorino Bruni</Authors>
<Description>The TextCase library for .NET helps changing the cases of existing texts.</Description>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand Down

0 comments on commit c21e682

Please sign in to comment.