-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathExtensions.cs
55 lines (48 loc) · 1.55 KB
/
Extensions.cs
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.Collections.Generic;
using System.Numerics;
using System.Text.RegularExpressions;
using ExileCore.PoEMemory.Components;
using GameOffsets.Native;
namespace Radar;
public static class Extensions
{
public static Vector3 GridPos(this Render render)
{
return render.PosNum / Radar.GridToWorldMultiplier;
}
public static Vector2i Truncate(this Vector2 v)
{
return new Vector2i((int)v.X, (int)v.Y);
}
public static IEnumerable<T> GetEveryNth<T>(this IEnumerable<T> source, int n)
{
var i = 0;
foreach (var item in source)
{
if (i == 0)
{
yield return item;
}
i++;
i %= n;
}
}
/// <summary>
/// Compares the string against a given pattern.
/// </summary>
/// <param name="str">The string.</param>
/// <param name="pattern">The pattern to match, where "*" means any sequence of characters, and "?" means any single character.</param>
/// <returns><c>true</c> if the string matches the given pattern; otherwise <c>false</c>.</returns>
public static bool Like(this string str, string pattern)
{
return ToLikeRegex(pattern).IsMatch(str);
}
public static Regex ToLikeRegex(this string pattern)
{
return new Regex("^" +
Regex.Escape(pattern)
.Replace(@"\*", ".*")
.Replace(@"\?", ".")
+ "$", RegexOptions.IgnoreCase | RegexOptions.Singleline);
}
}