Skip to content

Commit ee28b82

Browse files
committed
Comments and refactoring
1 parent 6c34cb9 commit ee28b82

File tree

4 files changed

+126
-27
lines changed

4 files changed

+126
-27
lines changed

Diff for: CodeJam.sln

+7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "T4.Reusable", "T4.Reusable"
4343
T4.Reusable\Transform.ttinclude = T4.Reusable\Transform.ttinclude
4444
EndProjectSection
4545
EndProject
46+
Project("{7CF6DF6D-3B04-46F8-A40B-537D21BCA0B4}") = "CodeJamDoc", "CodeJamDoc.shfbproj", "{383368D3-567C-4BF6-96D4-7A292DA5D486}"
47+
EndProject
4648
Global
4749
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4850
Debug|Any CPU = Debug|Any CPU
@@ -69,6 +71,10 @@ Global
6971
{8EDF4429-251A-416D-BB68-93F227191BCF}.Debug|Any CPU.Build.0 = Debug|Any CPU
7072
{8EDF4429-251A-416D-BB68-93F227191BCF}.Release|Any CPU.ActiveCfg = Release|Any CPU
7173
{8EDF4429-251A-416D-BB68-93F227191BCF}.Release|Any CPU.Build.0 = Release|Any CPU
74+
{383368D3-567C-4BF6-96D4-7A292DA5D486}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
75+
{383368D3-567C-4BF6-96D4-7A292DA5D486}.Debug|Any CPU.Build.0 = Debug|Any CPU
76+
{383368D3-567C-4BF6-96D4-7A292DA5D486}.Release|Any CPU.ActiveCfg = Release|Any CPU
77+
{383368D3-567C-4BF6-96D4-7A292DA5D486}.Release|Any CPU.Build.0 = Release|Any CPU
7278
EndGlobalSection
7379
GlobalSection(SolutionProperties) = preSolution
7480
HideSolutionNode = FALSE
@@ -79,5 +85,6 @@ Global
7985
{7BD77DA2-A731-400C-A88E-215FC592E6E3} = {D56CF63D-0A29-4F5A-8E2C-0DAF338119EE}
8086
{F6F97573-4D26-4217-89F6-819DF96FCB4A} = {D56CF63D-0A29-4F5A-8E2C-0DAF338119EE}
8187
{8EDF4429-251A-416D-BB68-93F227191BCF} = {C99F66F0-32AA-45EB-B112-D18498754A6B}
88+
{383368D3-567C-4BF6-96D4-7A292DA5D486} = {C99F66F0-32AA-45EB-B112-D18498754A6B}
8289
EndGlobalSection
8390
EndGlobal

Diff for: CodeJam.sln.GhostDoc.xml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<GhostDoc>
2+
<IgnoreFilePatterns>
3+
<IgnoreFilePattern>*.min.js</IgnoreFilePattern>
4+
<IgnoreFilePattern>jquery*.js</IgnoreFilePattern>
5+
</IgnoreFilePatterns>
6+
<SpellChecker>
7+
<IncludeExtensions>
8+
</IncludeExtensions>
9+
<IgnoreExtensions>
10+
</IgnoreExtensions>
11+
<IgnoreFiles>
12+
</IgnoreFiles>
13+
</SpellChecker>
14+
<HelpConfigurations selected="HelpFile">
15+
<HelpConfiguration name="HelpFile">
16+
<OutputPath>.\Help</OutputPath>
17+
<CleanupOutputPath>true</CleanupOutputPath>
18+
<HelpFileName>CodeJam</HelpFileName>
19+
<ImageFolderPath />
20+
<Theme />
21+
<HtmlFormats>
22+
<HtmlHelp>true</HtmlHelp>
23+
<MSHelpViewer>false</MSHelpViewer>
24+
<MSHelp2>false</MSHelp2>
25+
<Website>false</Website>
26+
</HtmlFormats>
27+
<IncludeScopes>
28+
<Public>true</Public>
29+
<Internal>false</Internal>
30+
<Protected>false</Protected>
31+
<Private>false</Private>
32+
<Inherited>true</Inherited>
33+
<InheritedFromReferences>true</InheritedFromReferences>
34+
<EnableTags>false</EnableTags>
35+
<TagList />
36+
<AutoGeneratedDocs />
37+
<DocsThatRequireEditing />
38+
</IncludeScopes>
39+
<SyntaxLanguages>
40+
<CSharp>true</CSharp>
41+
<VisualBasic>true</VisualBasic>
42+
<CPlusPlus>true</CPlusPlus>
43+
</SyntaxLanguages>
44+
<ResolveCrefLinks>true</ResolveCrefLinks>
45+
<HeaderText />
46+
<FooterText />
47+
<SelectedProjects />
48+
</HelpConfiguration>
49+
</HelpConfigurations>
50+
<GeneralProperties>
51+
</GeneralProperties>
52+
</GhostDoc>

Diff for: CodeJamDoc.shfbproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<RootNamespace>Documentation</RootNamespace>
1414
<Name>Documentation</Name>
1515
<!-- SHFB properties -->
16-
<FrameworkVersion>.NET Framework 4.6</FrameworkVersion>
16+
<FrameworkVersion>.NET Framework 4.5.2</FrameworkVersion>
1717
<OutputPath>.\Help\</OutputPath>
1818
<HtmlHelpName>CodeJamDoc</HtmlHelpName>
1919
<Language>en-US</Language>

Diff for: Main/src/Strings/StringExtensions.cs

+66-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Globalization;
43

54
using JetBrains.Annotations;
65

@@ -13,24 +12,26 @@ namespace CodeJam.Strings
1312
public partial class StringExtensions
1413
{
1514
/// <summary>
16-
/// Retrieves a substring from <paramref name="str"/>.
15+
/// Retrieves a substring from <paramref name="str" />.
1716
/// </summary>
18-
/// <param name="str"></param>
17+
/// <param name="str">
18+
/// String to retrieve substring from.
19+
/// </param>
1920
/// <param name="origin">
2021
/// Specifies the beginning, or the end as a reference point for offset, using a value of type
21-
/// <see cref="StringOrigin"/>.
22+
/// <see cref="StringOrigin" />.
2223
/// </param>
2324
/// <param name="length">The number of characters in the substring.</param>
2425
/// <returns>
25-
/// A string that is equivalent to the substring of length <paramref name="length"/> that begins at
26-
/// <paramref name="origin"/> in <paramref name="str"/>, or Empty if length of <paramref name="str"/>
27-
/// or <paramref name="length"/> is zero.
26+
/// A string that is equivalent to the substring of length <paramref name="length" /> that begins at
27+
/// <paramref name="origin" /> in <paramref name="str" />, or Empty if length of <paramref name="str" />
28+
/// or <paramref name="length" /> is zero.
2829
/// </returns>
2930
[NotNull]
3031
[Pure]
3132
public static string Substring([NotNull] this string str, StringOrigin origin, int length)
3233
{
33-
if (str == null) throw new ArgumentNullException(nameof(str));
34+
Code.NotNull(str, nameof(str));
3435

3536
// Fast path
3637
var strLen = str.Length;
@@ -45,40 +46,61 @@ public static string Substring([NotNull] this string str, StringOrigin origin, i
4546
case StringOrigin.End:
4647
return str.Substring(strLen - length, length);
4748
default:
48-
throw new ArgumentOutOfRangeException(nameof(origin), origin, null);
49+
throw CodeExceptions.Argument(nameof(origin), $"Invalid {nameof(StringOrigin)} value.");
4950
}
5051
}
5152

5253
/// <summary>
5354
/// Retrieves prefix of length <paramref name="length"/>.
5455
/// </summary>
55-
/// <param name="str"></param>
56+
/// <param name="str">String to retrieve prefix from.</param>
5657
/// <param name="length">The number of characters in the substring.</param>
58+
/// <returns>
59+
/// Prefix of specified length, or <paramref name="str"/> itself, if total length less than required.
60+
/// </returns>
5761
[NotNull]
5862
[Pure]
5963
public static string Prefix([NotNull] this string str, int length) => str.Substring(StringOrigin.Begin, length);
6064

6165
/// <summary>
6266
/// Retrieves prefix of length <paramref name="length"/>.
6367
/// </summary>
64-
/// <param name="str"></param>
68+
/// <param name="str">String to retrieve suffix from.</param>
6569
/// <param name="length">The number of characters in the substring.</param>
70+
/// <returns>
71+
/// Suffix of specified length, or <paramref name="str"/> itself, if total length less than required.
72+
/// </returns>
6673
[NotNull]
6774
[Pure]
6875
public static string Suffix([NotNull] this string str, int length) => str.Substring(StringOrigin.End, length);
6976

7077
/// <summary>
7178
/// Trims <paramref name="str"/> prefix if it equals to <paramref name="prefix"/>.
7279
/// </summary>
80+
/// <param name="str">String to trim.</param>
81+
/// <param name="prefix">Prefix to trim.</param>
82+
/// <returns>Trimmed <paramref name="str"/>, or original <paramref name="str"/> if prefix not exists.</returns>
83+
[NotNull]
84+
[Pure]
85+
public static string TrimPrefix([NotNull] this string str, [CanBeNull] string prefix) =>
86+
TrimPrefix(str, prefix, StringComparer.CurrentCulture);
87+
88+
/// <summary>
89+
/// Trims <paramref name="str"/> prefix if it equals to <paramref name="prefix"/>.
90+
/// </summary>
91+
/// <param name="str">String to trim.</param>
92+
/// <param name="prefix">Prefix to trim.</param>
93+
/// <param name="comparer">Comparer to compare value of prefix.</param>
94+
/// <returns>Trimmed <paramref name="str"/>, or original <paramref name="str"/> if prefix not exists.</returns>
7395
[NotNull]
7496
[Pure]
7597
public static string TrimPrefix(
7698
[NotNull] this string str,
7799
[CanBeNull] string prefix,
78100
[NotNull] IEqualityComparer<string> comparer)
79101
{
80-
if (str == null) throw new ArgumentNullException(nameof(str));
81-
if (comparer == null) throw new ArgumentNullException(nameof(comparer));
102+
Code.NotNull(str, nameof(str));
103+
Code.NotNull(comparer, nameof(comparer));
82104

83105
// FastPath
84106
if (prefix == null)
@@ -91,26 +113,22 @@ public static string TrimPrefix(
91113
return !comparer.Equals(prefix, actPrefix) ? str : str.Substring(prefixLen);
92114
}
93115

94-
/// <summary>
95-
/// Trims <paramref name="str"/> prefix if it equals to <paramref name="prefix"/>.
96-
/// </summary>
97-
[NotNull]
98-
[Pure]
99-
public static string TrimPrefix([NotNull] this string str, [CanBeNull] string prefix) =>
100-
TrimPrefix(str, prefix, StringComparer.CurrentCulture);
101-
102116
/// <summary>
103117
/// Trims <paramref name="str"/> suffix if it equals to <paramref name="suffix"/>.
104118
/// </summary>
119+
/// <param name="str">String to trim.</param>
120+
/// <param name="suffix">Suffix to trim.</param>
121+
/// <param name="comparer">Comparer to compare value of suffix.</param>
122+
/// <returns>Trimmed <paramref name="str"/>, or original <paramref name="str"/> if suffix does not exists.</returns>
105123
[NotNull]
106124
[Pure]
107125
public static string TrimSuffix(
108126
[NotNull] this string str,
109127
[CanBeNull] string suffix,
110128
[NotNull] IEqualityComparer<string> comparer)
111129
{
112-
if (str == null) throw new ArgumentNullException(nameof(str));
113-
if (comparer == null) throw new ArgumentNullException(nameof(comparer));
130+
Code.NotNull(str, nameof(str));
131+
Code.NotNull(comparer, nameof(comparer));
114132

115133
// FastPath
116134
if (suffix == null)
@@ -127,6 +145,9 @@ public static string TrimSuffix(
127145
/// <summary>
128146
/// Trims <paramref name="str"/> prefix if it equals to <paramref name="suffix"/>.
129147
/// </summary>
148+
/// <param name="str">String to trim.</param>
149+
/// <param name="suffix">Suffix to trim.</param>
150+
/// <returns>Trimmed <paramref name="str"/>, or original <paramref name="str"/> if suffix does not exists.</returns>
130151
[NotNull]
131152
[Pure]
132153
public static string TrimSuffix([NotNull] this string str, [CanBeNull] string suffix) =>
@@ -137,13 +158,18 @@ public static string TrimSuffix([NotNull] this string str, [CanBeNull] string su
137158
/// <summary>
138159
/// Returns size in bytes string representation.
139160
/// </summary>
161+
/// <param name="value">Value to represent.</param>
162+
/// <returns>Value as size in bytes</returns>
140163
[NotNull]
141164
[Pure]
142-
public static string ToByteSizeString(this long value) => ToByteSizeString(value, CultureInfo.CurrentCulture);
165+
public static string ToByteSizeString(this long value) => ToByteSizeString(value, null);
143166

144167
/// <summary>
145168
/// Returns size in bytes string representation.
146169
/// </summary>
170+
/// <param name="value">Value to represent.</param>
171+
/// <param name="provider">Format provider for number part of value</param>
172+
/// <returns>Value as size in bytes</returns>
147173
[NotNull]
148174
[Pure]
149175
public static string ToByteSizeString(this long value, [CanBeNull] IFormatProvider provider)
@@ -180,10 +206,8 @@ public static IEnumerable<string> SplitWithTrim([NotNull] this string source, pa
180206
// TODO: For performance reasons must be reimplemented using FSM parser.
181207
var parts = source.Split(separators);
182208
foreach (var part in parts)
183-
{
184209
if (!part.IsNullOrWhiteSpace())
185210
yield return part.Trim();
186-
}
187211
}
188212

189213
/// <summary>
@@ -199,6 +223,7 @@ public static IEnumerable<string> SplitWithTrim([NotNull] this string source, pa
199223
public static unsafe string ToHexString([NotNull] this byte[] data)
200224
{
201225
Code.NotNull(data, nameof(data));
226+
202227
if (data.Length == 0)
203228
return string.Empty;
204229

@@ -272,6 +297,10 @@ public static unsafe string ToHexString([NotNull] this byte[] data, [CanBeNull]
272297
/// <summary>
273298
/// Remove one set of leading and trailing double quote characters, if both are present.
274299
/// </summary>
300+
/// <param name="arg">String to unquote.</param>
301+
/// <returns>
302+
/// Unquoted <paramref name="arg"/>, if <paramref name="arg"/> is quoted, or <paramref name="arg"/> itself.
303+
/// </returns>
275304
public static string Unquote(this string arg)
276305
{
277306
bool quoted;
@@ -281,11 +310,22 @@ public static string Unquote(this string arg)
281310
/// <summary>
282311
/// Remove one set of leading and trailing double quote characters, if both are present.
283312
/// </summary>
313+
/// <param name="arg">String to unquote.</param>
314+
/// <param name="quoted">Set to true, if <paramref name="arg"/> was quoted.</param>
315+
/// <returns>
316+
/// Unquoted <paramref name="arg"/>, if <paramref name="arg"/> is quoted, or <paramref name="arg"/> itself.
317+
/// </returns>
284318
public static string Unquote(this string arg, out bool quoted) => Unquote(arg, '"', out quoted);
285319

286320
/// <summary>
287321
/// Remove one set of leading and trailing d<paramref name="quotationChar"/>, if both are present.
288322
/// </summary>
323+
/// <param name="arg">String to unquote.</param>
324+
/// <param name="quotationChar">Quotation char</param>
325+
/// <param name="quoted">Set to true, if <paramref name="arg"/> was quoted.</param>
326+
/// <returns>
327+
/// Unquoted <paramref name="arg"/>, if <paramref name="arg"/> is quoted, or <paramref name="arg"/> itself.
328+
/// </returns>
289329
public static string Unquote(this string arg, char quotationChar, out bool quoted)
290330
{
291331
if (arg.Length > 1 && arg[0] == quotationChar && arg[arg.Length - 1] == quotationChar)

0 commit comments

Comments
 (0)