Utils: Add SplitAddress and SplitName
This commit is contained in:
@ -25,6 +25,7 @@ namespace Elwig.Helpers {
|
||||
public static readonly Regex PartialDateRegex = GeneratedPartialDateRegex();
|
||||
public static readonly Regex FromToRegex = GeneratedFromToRegex();
|
||||
public static readonly Regex FromToTimeRegex = GeneratedFromToTimeRegex();
|
||||
public static readonly Regex AddressRegex = GeneratedAddressRegex();
|
||||
|
||||
[GeneratedRegex("^serial://([A-Za-z0-9]+):([0-9]+)(,([5-9]),([NOEMSnoems]),(0|1|1\\.5|2|))?$", RegexOptions.Compiled)]
|
||||
private static partial Regex GeneratedSerialRegex();
|
||||
@ -41,6 +42,9 @@ namespace Elwig.Helpers {
|
||||
[GeneratedRegex(@"^([0-9]{1,2}:[0-9]{2})?-([0-9]{1,2}:[0-9]{2})?$", RegexOptions.Compiled)]
|
||||
private static partial Regex GeneratedFromToTimeRegex();
|
||||
|
||||
[GeneratedRegex(@"^(.*?) +([0-9].*)$", RegexOptions.Compiled)]
|
||||
private static partial Regex GeneratedAddressRegex();
|
||||
|
||||
private static readonly ushort[] Crc16ModbusTable = {
|
||||
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
|
||||
0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
|
||||
@ -292,5 +296,30 @@ namespace Elwig.Helpers {
|
||||
public static string GenerateLsNr(Delivery d) => GenerateLsNr(d.Date, d.ZwstId, d.LNr);
|
||||
|
||||
public static string GenerateLsNr(DateOnly date, string zwstid, int lnr) => $"{date:yyyyMMdd}{zwstid}{lnr:000}";
|
||||
|
||||
public static (string, string?) SplitAddress(string address) {
|
||||
var m = AddressRegex.Match(address);
|
||||
return (m.Groups[1].Value, m.Groups[2].Value);
|
||||
}
|
||||
|
||||
public static (string, string?) SplitName(string fullName, string? familyName) {
|
||||
if (familyName == null) return (fullName, null);
|
||||
var p0 = fullName.ToLower().IndexOf(familyName.ToLower());
|
||||
if (p0 == -1) return (fullName, null);
|
||||
var p1 = fullName.IndexOf(" und ");
|
||||
var p2 = fullName.ToLower().LastIndexOf(" und ");
|
||||
if (p1 != p2) {
|
||||
if (p0 > p1) {
|
||||
// A und B familyName [und ...]
|
||||
return (fullName[p0..^0], fullName[0..(p0 - 1)]);
|
||||
} else {
|
||||
// familyName und ... A und B
|
||||
var p3 = fullName.LastIndexOf(' ', p2 - 1);
|
||||
return (fullName[0..p3], fullName[(p3 + 1)..^0]);
|
||||
}
|
||||
} else {
|
||||
return (familyName, fullName.Replace(familyName, "").Replace(" ", " ").Trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user