From 61c122c9eac0a776bc2b8bb81d2ce2935b07f305 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Mon, 19 Jul 2021 11:39:08 +0100 Subject: [PATCH] (#42) Throw exceptions on invalid string arguments --- X10D/src/StringExtensions/StringExtensions.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/X10D/src/StringExtensions/StringExtensions.cs b/X10D/src/StringExtensions/StringExtensions.cs index d0e8e80..0c64baf 100644 --- a/X10D/src/StringExtensions/StringExtensions.cs +++ b/X10D/src/StringExtensions/StringExtensions.cs @@ -190,6 +190,11 @@ namespace X10D /// public static bool IsLower(this string value) { + if (value is null) + { + throw new ArgumentNullException(nameof(value)); + } + for (var index = 0; index < value.Length; index++) { if (!char.IsLetter(value[index])) @@ -216,6 +221,11 @@ namespace X10D /// public static bool IsUpper(this string value) { + if (value is null) + { + throw new ArgumentNullException(nameof(value)); + } + for (var index = 0; index < value.Length; index++) { if (!char.IsLetter(value[index])) @@ -315,6 +325,11 @@ namespace X10D throw new ArgumentNullException(nameof(value)); } + if (count < 0) + { + throw new ArgumentOutOfRangeException(nameof(count), ExceptionMessages.CountMustBeGreaterThanOrEqualTo0); + } + var builder = new StringBuilder(value.Length * count); for (var i = 0; i < count; i++) @@ -337,7 +352,7 @@ namespace X10D throw new ArgumentNullException(nameof(value)); } - if (value.Length == 1) + if (value.Length < 2) { return value; }