-
Notifications
You must be signed in to change notification settings - Fork 372
Expand file tree
/
Copy pathStringExtensions.cs
More file actions
41 lines (36 loc) · 1.47 KB
/
StringExtensions.cs
File metadata and controls
41 lines (36 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Linq;
namespace FFImageLoading
{
public static class StringExtensions
{
public static string ToSanitizedKey(this string key)
{
return new string(key.ToCharArray()
.Where(c => (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'))
.ToArray());
}
public static bool Contains(this string source, string toCheck, StringComparison comp)
{
return source.IndexOf(toCheck, comp) >= 0;
}
public static bool IsDataUrl(this string str)
{
return !string.IsNullOrWhiteSpace(str) && (
str.StartsWith("data:", StringComparison.OrdinalIgnoreCase)
|| str.StartsWith("<", StringComparison.OrdinalIgnoreCase));
}
public static bool IsSvgFileUrl(this string str)
{
return !string.IsNullOrWhiteSpace(str)
&& str.Split(new[] { '?' }, StringSplitOptions.RemoveEmptyEntries)[0].EndsWith("svg", StringComparison.OrdinalIgnoreCase);
}
public static bool IsSvgDataUrl(this string str)
{
return !string.IsNullOrWhiteSpace(str) && (
str.StartsWith("data:image/svg", StringComparison.OrdinalIgnoreCase)
|| str.StartsWith("data:text", StringComparison.OrdinalIgnoreCase)
|| str.StartsWith("<", StringComparison.OrdinalIgnoreCase));
}
}
}