diff --git a/OpenNest.Data/NestNames.cs b/OpenNest.Data/NestNames.cs index 5c17ab40..a2cc2353 100644 --- a/OpenNest.Data/NestNames.cs +++ b/OpenNest.Data/NestNames.cs @@ -2,12 +2,13 @@ namespace OpenNest.Data; /// /// Generated nest names: "N" + two-digit year + "-" + the year's sequence number in an -/// unambiguous base-30 alphabet, padded to three digits with its zero digit ('2'). -/// The sequence runs for the whole year; three digits cover 27,000 nests before a fourth appears. +/// unambiguous base-29 alphabet, padded to three digits with its zero digit ('2'). +/// No S (it reads as 5). The sequence runs for the whole year; three digits cover 24,389 nests +/// before a fourth appears. /// public static class NestNames { - private const string Base30Digits = "2345679ACDEFGHJKLMNPQRSTUVWXYZ"; + private const string Base29Digits = "2345679ACDEFGHJKLMNPQRTUVWXYZ"; /// Earliest and latest years a sequence may be allocated for. public const int MinYear = 2000, MaxYear = 2099; @@ -15,7 +16,7 @@ public static class NestNames public static string Format(int year, int number) { ArgumentOutOfRangeException.ThrowIfNegative(number); - var seq = ToBase30(number).PadLeft(3, Base30Digits[0]); + var seq = ToBase29(number).PadLeft(3, Base29Digits[0]); return $"N{year % 100:D2}-{seq}"; } @@ -33,10 +34,10 @@ public static class NestNames long value = 0; foreach (var c in name.AsSpan(prefix.Length)) { - var digit = Base30Digits.IndexOf(c); + var digit = Base29Digits.IndexOf(c); if (digit < 0) return false; - value = value * Base30Digits.Length + digit; + value = value * Base29Digits.Length + digit; if (value > int.MaxValue) return false; } @@ -45,16 +46,16 @@ public static class NestNames return Format(year, number) == name; } - private static string ToBase30(int value) + private static string ToBase29(int value) { if (value == 0) - return Base30Digits[0].ToString(); + return Base29Digits[0].ToString(); var result = ""; while (value > 0) { - result = Base30Digits[value % Base30Digits.Length] + result; - value /= Base30Digits.Length; + result = Base29Digits[value % Base29Digits.Length] + result; + value /= Base29Digits.Length; } return result; } diff --git a/OpenNest.Tests/Data/NestNamesTests.cs b/OpenNest.Tests/Data/NestNamesTests.cs index c2a9beba..40ef798c 100644 --- a/OpenNest.Tests/Data/NestNamesTests.cs +++ b/OpenNest.Tests/Data/NestNamesTests.cs @@ -7,11 +7,11 @@ public class NestNamesTests [Theory] [InlineData(0, "N26-222")] [InlineData(1, "N26-223")] - [InlineData(29, "N26-22Z")] - [InlineData(30, "N26-232")] - [InlineData(900, "N26-322")] - [InlineData(27000, "N26-3222")] - public void NamesUseTwoDigitYearAndPaddedBase30Sequence(int number, string expected) + [InlineData(28, "N26-22Z")] + [InlineData(29, "N26-232")] + [InlineData(841, "N26-322")] + [InlineData(24389, "N26-3222")] + public void NamesUseTwoDigitYearAndPaddedBase29Sequence(int number, string expected) { Assert.Equal(expected, NestNames.Format(2026, number)); Assert.True(NestNames.TryParse(expected, 2026, out var parsed)); @@ -25,6 +25,7 @@ public class NestNamesTests [InlineData("N26-23")] [InlineData("N26-2223")] [InlineData("N26-22B")] + [InlineData("N26-22S")] [InlineData("n26-223")] [InlineData("N26-223 copy")] [InlineData("N26-ZZZZZZZZZ")] diff --git a/docs/nest-storage.md b/docs/nest-storage.md index 02970577..83b7049f 100644 --- a/docs/nest-storage.md +++ b/docs/nest-storage.md @@ -198,8 +198,8 @@ The note never blocks the dialog, save or post, and posting is not gated on hold ### Generated nest names **File > New** names a nest `N-` (`OpenNest.Data.NestNames`): the -two-digit year and the year's sequence number in a base-30 alphabet without -look-alike characters, padded to three digits (27,000 a year before a fourth +two-digit year and the year's sequence number in a base-29 alphabet without +look-alike characters (no S, which reads as 5), padded to three digits (24,389 a year before a fourth appears). The sequence runs for the whole year. In Database mode the desktop asks `POST /api/nest-names/next` for the number, so every PC shares one counter per year (`nest_sequences`, schema version 6). The server also keeps