Hierarchical account numbers. Do we
really need zero-padded same-width numbers as humans?
So each "digit" represents a level of hierarchy. for example 1234 is:
1
--2
----3
------4
using base 10, each level can only have 10 sections, 0-9. We can switch to something like base62 and use 0-9A-Z-a-z or some other base greater than 10, but what if we use the backtick to separate the level, providing practically an unlimited number of sections in each level. also drop an rightmost "zeroes" which are not followed by a non-zero number.
The issues for humans:
1
is the same as
100
is the same as
100000
Examples:
`12`34`4556` = 12 34 4556
12345 = 1 2 3 4 5
`12`34`455`= 12 34 455
12`34`455 = 1 2 34 4 5 5
12345, `12`34`455` and 12`34`455 are different numbers
traditional methods: (Microsoft, Oracle, etc offer options to represent numbers in this way, but not the "new" way)
12345 = 0001-0002-0003-0004-0005-0000
`12`34`455` = 0012-0034-0455-0000-0000-0000
12`34`455 = 0001-0002-0034-0004-0005-0005
so it looks super-pretty i guess, but not really "more" readable IMHO
(also uses more ink and energy)
0001-0002-0003-0004-0005-0000
0012-0034-0455-0000-0000-0000
0001-0002-0034-0004-0005-0005
QString normalizeAccount(const QString &input)
{
QString v = input.trimmed();
v.replace(QRegularExpression(QStringLiteral("[^0-9]")), QStringLiteral(" "));
v.replace(QRegularExpression(QStringLiteral("\\s+")), QStringLiteral(" "));
QStringList parts = v.split(' ', Qt::SkipEmptyParts);
QVector<QString> x(6, QStringLiteral("0"));
for (int i = 0; i < 6 && i < parts.size(); ++i) {
bool ok = false;
int num = parts.at(i).toInt(&ok);
if (ok && num > 9) {
x[i] = QStringLiteral(R"(`%1`)").arg(parts.at(i));
} else {
x[i] = parts.at(i);
}
}
QString ac;
for (auto &slot : x)
ac += slot;
while (ac.contains(QStringLiteral("``")))
ac.replace(QStringLiteral("``"), QStringLiteral("`"));
while (ac.endsWith('0'))
ac.chop(1);
if (ac.isEmpty())
return QStringLiteral("000000");
return ac;
}
POLL: POLL: POLL: POLL: POLL:
1) I like the new way: `12`34`455`
0 Votes | 0%
2) I like the old way: 0012-0034-0455-0000-0000-0000
0 Votes | 0%
Poll has ended.