namespace QRScript.Extensions;
using System.Text;
///
/// Provides extension methods for common string transformations and validations.
///
public static class StringExtensions
{
///
/// Encodes the current string instance to Base64 using Unicode encoding.
///
/// The input string to encode.
/// A Base64-encoded version of the input string.
///
/// This uses Unicode (UTF-16) encoding, which is standard in .NET strings.
///
public static string ToBase64(this string input)
{
if (input is null)
throw new ArgumentNullException(nameof(input));
byte[] bytes = Encoding.Unicode.GetBytes(input);
return Convert.ToBase64String(bytes);
}
///
/// Joins an array of strings into a single string separated by the system's newline.
///
/// Array of strings to join.
/// A single string composed of all input lines, separated by newlines.
public static string JoinLines(this IEnumerable lines)
{
if (lines is null)
throw new ArgumentNullException(nameof(lines));
return string.Join(Environment.NewLine, lines);
}
///
/// Determines whether the string exceeds the specified character length limit.
///
/// The input string to evaluate.
/// The maximum number of allowed characters.
/// true if the string's length is greater than or equal to ; otherwise, false.
public static bool ExceedsLengthLimit(this string text, int limit)
{
if (text is null)
throw new ArgumentNullException(nameof(text));
if (limit < 0)
throw new ArgumentOutOfRangeException(nameof(limit), "Limit must be non-negative.");
return text.Length >= limit;
}
}