From 6f1f32876daaf0ce207e3d181ff8d34e3636256e Mon Sep 17 00:00:00 2001 From: Ivandro Jao Date: Fri, 10 May 2024 09:52:43 +0100 Subject: [PATCH] Refactor method to check string starts with lowercase letter The method formerly known as "BeginsWithLetter" has been optimized and renamed to "IsFirstLetterConvertibleToUppercase". The method now directly checks if the string is not empty and its first character is lowercase, instead of doing these in separate steps. Signed-off-by: Ivandro Jao --- .../FixStartWithUppercaseLetterAfterColon.cs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/libse/Forms/FixCommonErrors/FixStartWithUppercaseLetterAfterColon.cs b/src/libse/Forms/FixCommonErrors/FixStartWithUppercaseLetterAfterColon.cs index ba720d7ad..27caeadc3 100644 --- a/src/libse/Forms/FixCommonErrors/FixStartWithUppercaseLetterAfterColon.cs +++ b/src/libse/Forms/FixCommonErrors/FixStartWithUppercaseLetterAfterColon.cs @@ -91,22 +91,15 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors private static bool CanCapitalize(string input, IFixCallbacks callbacks) { - return !IsAppleNaming(input) && BeginsWithLetter(input); + return !IsAppleNaming(input) && IsFirstLetterConvertibleToUppercase(input); } /// /// Returns true if first character is convertible to uppercase otherwise false /// - private static bool BeginsWithLetter(string input) + private static bool IsFirstLetterConvertibleToUppercase(string input) { - if (input.Length == 0) - { - return false; - } - - var ch = input[0]; - - return char.IsLetter(ch) && char.IsLower(ch); + return input.Length > 0 && char.IsLower(input[0]); } ///