Skip to content

Commit 43c9efa

Browse files
committed
General project cleanup and preparation for final release.
1 parent bb8f432 commit 43c9efa

10 files changed

+72
-54
lines changed

Text.sln Roydl.Text.sln

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.31213.239
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{1A56E219-32AA-48A0-B6F6-33E10D44E0D4}") = "Text", "src\Text.csproj", "{D94B39E9-E923-4347-95CE-992E196853BE}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Roydl.Text", "src\Roydl.Text.csproj", "{D94B39E9-E923-4347-95CE-992E196853BE}"
77
EndProject
8-
Project("{FC7AEAEA-B27D-4A15-B781-06A3574E4F02}") = "Text.Test", "test\Text.Test.csproj", "{EA65D84F-012B-4A83-9471-4DEB0923D081}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Roydl.Text.Test", "test\Roydl.Text.Test.csproj", "{EA65D84F-012B-4A83-9471-4DEB0923D081}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution

Text.sln.DotSettings Roydl.Text.sln.DotSettings

+1
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ ______________________________________________</s:String>
445445
<s:Boolean x:Key="/Default/UserDictionary/Words/=RISC/@EntryIndexedValue">True</s:Boolean>
446446
<s:Boolean x:Key="/Default/UserDictionary/Words/=ROBOCOPY/@EntryIndexedValue">True</s:Boolean>
447447
<s:Boolean x:Key="/Default/UserDictionary/Words/=Sandboxie/@EntryIndexedValue">True</s:Boolean>
448+
<s:Boolean x:Key="/Default/UserDictionary/Words/=skippable/@EntryIndexedValue">True</s:Boolean>
448449
<s:Boolean x:Key="/Default/UserDictionary/Words/=subkey/@EntryIndexedValue">True</s:Boolean>
449450
<s:Boolean x:Key="/Default/UserDictionary/Words/=subkeys/@EntryIndexedValue">True</s:Boolean>
450451
<s:Boolean x:Key="/Default/UserDictionary/Words/=Suppressions/@EntryIndexedValue">True</s:Boolean>

src/BinaryToText/BinaryToTextEncoding.cs

+10-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.IO;
55
using System.Linq;
66
using System.Text;
7-
using Properties;
7+
using Resources;
88

99
/// <summary>
1010
/// Represents the base class from which all implementations of binary-to-text
@@ -15,7 +15,7 @@ public abstract class BinaryToTextEncoding
1515
/// <summary>
1616
/// Gets <see cref="Environment.NewLine"/> as a sequence of bytes used as a
1717
/// line separator within the
18-
/// <see cref="WriteLine(Stream, ReadOnlySpan{byte}, int, ref int)"/> and
18+
/// <see cref="WriteLine(Stream, Span{byte}, int, int, ref int)"/> and
1919
/// <see cref="WriteLine(Stream, byte, int, ref int)"/> methods.
2020
/// </summary>
2121
protected virtual ReadOnlyMemory<byte> Separator { get; } = Encoding.UTF8.GetBytes(Environment.NewLine);
@@ -357,7 +357,7 @@ public byte[] DecodeFile(string path)
357357
}
358358

359359
/// <summary>
360-
/// Determines whether the specified character can be ignored.
360+
/// Determines whether the specified value can be ignored.
361361
/// </summary>
362362
/// <param name="value">
363363
/// The character to check.
@@ -380,7 +380,7 @@ protected static bool IsSkippable(int value, params int[] additional) =>
380380
/// The stream in which to write the single byte.
381381
/// </param>
382382
/// <param name="bytes">
383-
/// An sequence of bytes.
383+
/// A sequence of bytes.
384384
/// </param>
385385
/// <param name="count">
386386
/// The number of bytes to be written to the current stream.
@@ -392,25 +392,23 @@ protected static bool IsSkippable(int value, params int[] additional) =>
392392
/// The current position in the line.
393393
/// </param>
394394
/// <exception cref="ArgumentNullException">
395-
/// stream or buffer is null.
395+
/// stream is null.
396396
/// </exception>
397397
/// <exception cref="ArgumentOutOfRangeException">
398-
/// count is less than 1.
398+
/// count is less than 1, or greater than size of bytes.
399399
/// </exception>
400-
protected void WriteLine(Stream stream, ReadOnlySpan<byte> bytes, int count, int lineLength, ref int linePos)
400+
protected void WriteLine(Stream stream, Span<byte> bytes, int count, int lineLength, ref int linePos)
401401
{
402402
if (stream == null)
403403
throw new ArgumentNullException(nameof(stream));
404-
if (bytes == null)
405-
throw new ArgumentNullException(nameof(bytes));
406-
if (count < 1)
404+
if (count < 1 || count > bytes.Length)
407405
throw new ArgumentOutOfRangeException(nameof(count), count, null);
408406
for (var i = 0; i < count; i++)
409407
WriteLine(stream, bytes[i], lineLength, ref linePos);
410408
}
411409

412-
/// <inheritdoc cref="WriteLine(Stream, ReadOnlySpan{byte}, int, int, ref int)"/>
413-
protected void WriteLine(Stream stream, ReadOnlySpan<byte> bytes, int lineLength, ref int linePos) =>
410+
/// <inheritdoc cref="WriteLine(Stream, Span{byte}, int, int, ref int)"/>
411+
protected void WriteLine(Stream stream, Span<byte> bytes, int lineLength, ref int linePos) =>
414412
WriteLine(stream, bytes, bytes.Length, lineLength, ref linePos);
415413

416414
/// <summary>

src/Properties/ExceptionMessages.Designer.cs src/Resources/ExceptionMessages.Designer.cs

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

src/Text.csproj src/Roydl.Text.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<Version>1.0.0</Version>
2222
<PackageId>Roydl.Text</PackageId>
2323
<Product>Roydl.Text</Product>
24+
<AppDesignerFolder>Resources</AppDesignerFolder>
2425
</PropertyGroup>
2526

2627
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -47,15 +48,15 @@
4748
</ItemGroup>
4849

4950
<ItemGroup>
50-
<Compile Update="Properties\ExceptionMessages.Designer.cs">
51+
<Compile Update="Resources\ExceptionMessages.Designer.cs">
5152
<DesignTime>True</DesignTime>
5253
<AutoGen>True</AutoGen>
5354
<DependentUpon>ExceptionMessages.resx</DependentUpon>
5455
</Compile>
5556
</ItemGroup>
5657

5758
<ItemGroup>
58-
<EmbeddedResource Update="Properties\ExceptionMessages.resx">
59+
<EmbeddedResource Update="Resources\ExceptionMessages.resx">
5960
<Generator>ResXFileCodeGenerator</Generator>
6061
<LastGenOutput>ExceptionMessages.Designer.cs</LastGenOutput>
6162
</EmbeddedResource>

src/TextConvert.cs

+42-30
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
using System.IO;
55
using System.Linq;
66
using System.Text;
7-
using Properties;
7+
using Internal;
8+
using Resources;
89

910
/// <summary>
1011
/// Provides static methods for converting text.
@@ -100,15 +101,15 @@ public static void FormatSeparators(StreamReader inputStream, StreamWriter outpu
100101
try
101102
{
102103
var newLine = TextSeparator.GetSeparator(separator);
103-
var isCrLf = IsCrLf(inputStream.BaseStream);
104+
var isCrLf = LocalIsCrLf(inputStream.BaseStream);
104105
var inRow = 0;
105-
var ba = new char[16384];
106+
var span = new char[Helper.GetBufferSize(inputStream)].AsSpan();
106107
int len;
107-
while ((len = inputStream.Read(ba, 0, ba.Length)) > 0)
108+
while ((len = inputStream.Read(span)) > 0)
108109
{
109110
for (var i = 0; i < len; i++)
110111
{
111-
var c = ba[i];
112+
var c = span[i];
112113
if (isCrLf && c == TextSeparator.CarriageReturnChar)
113114
continue;
114115
if (TextVerify.IsLineSeparator(c))
@@ -119,7 +120,7 @@ public static void FormatSeparators(StreamReader inputStream, StreamWriter outpu
119120
}
120121
if (inRow > 0)
121122
inRow = 0;
122-
outputStream.Write(ba[i]);
123+
outputStream.Write(span[i]);
123124
}
124125
}
125126
}
@@ -131,6 +132,34 @@ public static void FormatSeparators(StreamReader inputStream, StreamWriter outpu
131132
outputStream.Dispose();
132133
}
133134
}
135+
136+
static bool LocalIsCrLf(Stream stream)
137+
{
138+
if (stream == null)
139+
throw new ArgumentNullException(nameof(stream));
140+
var bs = new BufferedStream(stream, Helper.GetBufferSize(stream));
141+
var pos = bs.Position;
142+
var crLf = 0;
143+
try
144+
{
145+
int i;
146+
while ((i = bs.ReadByte()) != -1)
147+
{
148+
if (crLf > 0 && i == TextSeparator.LineFeedChar)
149+
{
150+
crLf++;
151+
break;
152+
}
153+
crLf = i == TextSeparator.CarriageReturnChar ? 1 : 0;
154+
}
155+
}
156+
finally
157+
{
158+
bs.Position = pos;
159+
bs.Flush();
160+
}
161+
return crLf > 1;
162+
}
134163
}
135164

136165
/// <inheritdoc cref="FormatSeparators(StreamReader, StreamWriter, TextNewLine, int, bool)"/>
@@ -229,34 +258,17 @@ public static bool FormatSeparators(string srcPath, string destPath, TextNewLine
229258
/// <inheritdoc cref="FormatSeparators(StreamReader, StreamWriter, TextNewLine, int, bool)"/>
230259
public static string FormatSeparators(string text, TextNewLine separator = TextNewLine.WindowsDefault, int maxInRow = -1)
231260
{
232-
if (text == null)
233-
throw new ArgumentNullException(nameof(text));
234-
if (text == string.Empty)
235-
return text;
261+
switch (text)
262+
{
263+
case null:
264+
throw new ArgumentNullException(nameof(text));
265+
case "":
266+
return text;
267+
}
236268
using var msi = new MemoryStream(Encoding.UTF8.GetBytes(text));
237269
using var mso = new MemoryStream();
238270
FormatSeparators(msi, mso, separator, maxInRow);
239271
return Encoding.UTF8.GetString(mso.ToArray());
240272
}
241-
242-
private static bool IsCrLf(Stream stream)
243-
{
244-
if (stream == null)
245-
throw new ArgumentNullException(nameof(stream));
246-
var pos = stream.Position;
247-
var crLf = 0;
248-
int i;
249-
while ((i = stream.ReadByte()) != -1)
250-
{
251-
if (crLf > 0 && i == TextSeparator.LineFeedChar)
252-
{
253-
crLf++;
254-
break;
255-
}
256-
crLf = i == TextSeparator.CarriageReturnChar ? 1 : 0;
257-
}
258-
stream.Position = pos;
259-
return crLf > 1;
260-
}
261273
}
262274
}

src/TextVerify.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ public static bool IsLatin1Letter(char ch) =>
6262

6363
/// <summary>
6464
/// Indicates whether the specified character is categorized as line separator.
65-
/// <para>
66-
/// See <see cref="TextNewLine"/> for more information.
67-
/// </para>
6865
/// </summary>
66+
/// <remarks>
67+
/// See <seealso cref="TextNewLine"/> for more information.
68+
/// </remarks>
6969
/// <param name="ch">
7070
/// The character to evaluate.
7171
/// </param>

test/Text.Test.csproj test/Roydl.Text.Test.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</ItemGroup>
3939

4040
<ItemGroup>
41-
<ProjectReference Include="..\src\Text.csproj" />
41+
<ProjectReference Include="..\src\Roydl.Text.csproj" />
4242
</ItemGroup>
4343

4444
</Project>

test/TestVars.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,15 @@ public static class TestVars
2525

2626
public static string RangeStr { get; } = new(Enumerable.Range(byte.MinValue, byte.MaxValue).Select(i => (char)i).ToArray());
2727

28-
public static byte[] GetRandomBytes()
28+
public static byte[] GetRandomBytes(int size = 0)
2929
{
30-
var bytes = new byte[Randomizer.Next(4096, short.MaxValue)];
30+
if (size < 1)
31+
{
32+
size = Randomizer.Next(byte.MaxValue, short.MaxValue);
33+
if (size % 2 == 0)
34+
--size;
35+
}
36+
var bytes = new byte[size];
3137
Randomizer.NextBytes(bytes);
3238
return bytes;
3339
}

0 commit comments

Comments
 (0)