namespace FileFlows.VideoNodes; /// /// Extension methods /// internal static class ExtensionMethods { /// /// Returns an empty string as null, otherwise returns the original string /// /// the input string /// the string or null if empty public static string? EmptyAsNull(this string str) { return str == string.Empty ? null : str; } /// /// Tries to perform a regex match /// /// the regex /// the input string to match against /// the match if found /// true if matches, otherwise false public static bool TryMatch(this Regex regex, string input, out Match match) { match = regex.Match(input); return match.Success; } /// /// Trims the specified characters from the beginning and end of the string. /// /// The input string to trim. /// The characters to trim from the string. /// A new string that has the specified characters removed from the beginning and end. /// Thrown when input is null. public static string TrimExtra(this string input, string charsToTrim) { if (input == null) throw new ArgumentNullException(nameof(input)); if (string.IsNullOrEmpty(charsToTrim)) return input.Trim(); int startIndex = 0; int endIndex = input.Length - 1; while (startIndex <= endIndex && (input[startIndex] == ' ' || charsToTrim.Contains(input[startIndex]))) { startIndex++; } while (endIndex >= startIndex && (input[endIndex] == ' ' || charsToTrim.Contains(input[endIndex]))) { endIndex--; } return input.Substring(startIndex, endIndex - startIndex + 1); } }