30 lines
807 B
C#
30 lines
807 B
C#
namespace GParse;
|
|
|
|
internal static class StringExtensions
|
|
{
|
|
internal static string SafeSubstring(this string subject, int startIndex, int size)
|
|
{
|
|
return startIndex >= 0
|
|
? startIndex <= subject.Length - 1
|
|
? subject.Length - 1 >= startIndex + size - 1
|
|
? subject.Substring(startIndex, size)
|
|
: subject.Substring(startIndex)
|
|
: string.Empty
|
|
: string.Empty;
|
|
}
|
|
}
|
|
|
|
public static class PublicStringExtensions
|
|
{
|
|
public static string Unquote(this string subject, string openQuote, string closeQuote)
|
|
{
|
|
const StringComparison stringComparison = StringComparison.Ordinal;
|
|
|
|
string s = subject.StartsWith(openQuote, stringComparison) && subject.EndsWith(closeQuote, stringComparison)
|
|
? subject[openQuote.Length..(subject.Length - closeQuote.Length)]
|
|
: subject;
|
|
|
|
return s;
|
|
}
|
|
}
|