mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-09 15:27:54 +00:00
feat: initial 6-character HID rework
This commit is contained in:
parent
73f43b8cb3
commit
9f56697241
30 changed files with 208 additions and 91 deletions
|
|
@ -9,7 +9,7 @@ namespace PluralKit.Core;
|
|||
internal class DatabaseMigrator
|
||||
{
|
||||
private const string RootPath = "PluralKit.Core.Database"; // "resource path" root for SQL files
|
||||
private const int TargetSchemaVersion = 41;
|
||||
private const int TargetSchemaVersion = 42;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public DatabaseMigrator(ILogger logger)
|
||||
|
|
|
|||
35
PluralKit.Core/Database/Utils/HidUtils.cs
Normal file
35
PluralKit.Core/Database/Utils/HidUtils.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace PluralKit.Core;
|
||||
|
||||
public static class HidUtils
|
||||
{
|
||||
private static readonly Regex _hidRegex = new(@"^[a-zA-Z]{5,6}$");
|
||||
|
||||
public static string? ParseHid(string input)
|
||||
{
|
||||
input = input.ToLower().Replace("-", null);
|
||||
if (!_hidRegex.IsMatch(input))
|
||||
return null;
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
public static bool TryParseHid(this string input, out string hid)
|
||||
{
|
||||
hid = ParseHid(input);
|
||||
return hid != null;
|
||||
}
|
||||
|
||||
public static string HidTransform(string input, bool split = false)
|
||||
{
|
||||
if (split && input.Length > 5)
|
||||
{
|
||||
var len = (int)Math.Floor(input.Length / 2.0);
|
||||
input = string.Concat(input.AsSpan(0, len), "-", input.AsSpan(len));
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue