1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-10 03:05:42 +00:00

(#42) Throw exceptions on invalid string arguments

This commit is contained in:
Oliver Booth 2021-07-19 11:39:08 +01:00
parent 92d60a6db8
commit 61c122c9ea
No known key found for this signature in database
GPG Key ID: A4AC17007530E9B4

View File

@ -190,6 +190,11 @@ namespace X10D
/// </returns> /// </returns>
public static bool IsLower(this string value) public static bool IsLower(this string value)
{ {
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
for (var index = 0; index < value.Length; index++) for (var index = 0; index < value.Length; index++)
{ {
if (!char.IsLetter(value[index])) if (!char.IsLetter(value[index]))
@ -216,6 +221,11 @@ namespace X10D
/// </returns> /// </returns>
public static bool IsUpper(this string value) public static bool IsUpper(this string value)
{ {
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
for (var index = 0; index < value.Length; index++) for (var index = 0; index < value.Length; index++)
{ {
if (!char.IsLetter(value[index])) if (!char.IsLetter(value[index]))
@ -315,6 +325,11 @@ namespace X10D
throw new ArgumentNullException(nameof(value)); throw new ArgumentNullException(nameof(value));
} }
if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count), ExceptionMessages.CountMustBeGreaterThanOrEqualTo0);
}
var builder = new StringBuilder(value.Length * count); var builder = new StringBuilder(value.Length * count);
for (var i = 0; i < count; i++) for (var i = 0; i < count; i++)
@ -337,7 +352,7 @@ namespace X10D
throw new ArgumentNullException(nameof(value)); throw new ArgumentNullException(nameof(value));
} }
if (value.Length == 1) if (value.Length < 2)
{ {
return value; return value;
} }