project: the repository skeleton
The SMS app for imsd's net.catcrafts.IMS1.Messaging interface starts
here: the licence (GPL-3.0-only), FUNDING.yml, README and AGENTS, a
project.cpp with the three build products (imsd-messages-core: std and
Crafter.DB; imsd-messages-bus: GLib; the imsd-messages executable),
their module units as stubs, the version constant, the bundled Noto Sans
font with its OFL text, and the first test. This commit is the base every
later range is reviewed against.
Tested: crafter-build builds the three products and --version answers,
crafter-build test passes the one test, lint and format --check are clean
on every text rule and on the AST rules for the eleven files without a
global module fragment; the four files that include gio/gio.h are not
parsed by the lint driver's libclang (no C++ standard library on its
include path: 'type_traits' file not found), which is a Crafter.Build
matter.
2026-10-17 23:14:00 +02:00
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
// Number normalisation: the raw address a user types or the network sends
Number: the conversation key of an address
An address becomes one conversation key. A number in international form
becomes E.164, and one in national form gets the given country code in
front — nine digits or more with a leading 0, or eight or more without
one, as a plan without a trunk prefix writes its numbers, the latter
only while the result is no longer than a number can be; the country
code of an E.164 number is found by the ITU length rule; short codes and
alphanumeric senders are their own keys. The display form puts a space
after the country code.
The key groups; a text goes to the address as dialled (DialledNumber:
the separators gone, a parenthesised trunk zero after a country code
dropped — not after Italy's code or San Marino's, where no zero is a
trunk prefix (a landline's is part of its number, a mobile has none):
such an address names two numbers and is none — nothing added), since
imsd sends a national number or a short code with the type unknown and
the network reads it by its own dialling plan — a country code completed
for the key would be dialled for real. A national number's leading 0 is
taken for the trunk prefix and goes when the country code is added — not
under Italy's code or San Marino's, where it is the number's and stays.
The key's known limits are of grouping: a number written with its
country code and no '+' is completed as a national one, one of a plan
whose trunk prefix is not a lone 0 (Hungary's 06, Russia's 8) is
completed wrongly, and a national number shorter than those lengths
(Iceland's seven digits) stays its digits.
Tested: tests/Number, thirty-two normalisation cases (the parenthesised
trunk zero of an international number, one after San Marino's code left
as no number, a national number's zero kept under Italy's code and San
Marino's, the numbers without a trunk prefix and both rules' shortest
numbers among them), twelve dialled forms (two with a zero in
parentheses after Italy's code, left as typed, among them), the country
codes of one-, two- and three-digit countries, the display forms.
2026-10-17 23:25:34 +02:00
// becomes the conversation key — E.164 for numbers, short codes and
// alphanumeric senders verbatim — the display form of a key, and the
// dialled form of an address (its separators gone, nothing added).
project: the repository skeleton
The SMS app for imsd's net.catcrafts.IMS1.Messaging interface starts
here: the licence (GPL-3.0-only), FUNDING.yml, README and AGENTS, a
project.cpp with the three build products (imsd-messages-core: std and
Crafter.DB; imsd-messages-bus: GLib; the imsd-messages executable),
their module units as stubs, the version constant, the bundled Noto Sans
font with its OFL text, and the first test. This commit is the base every
later range is reviewed against.
Tested: crafter-build builds the three products and --version answers,
crafter-build test passes the one test, lint and format --check are clean
on every text rule and on the AST rules for the eleven files without a
global module fragment; the four files that include gio/gio.h are not
parsed by the lint driver's libclang (no C++ standard library on its
include path: 'type_traits' file not found), which is a Crafter.Build
matter.
2026-10-17 23:14:00 +02:00
import std ;
import ImsdMessages ;
Number: the conversation key of an address
An address becomes one conversation key. A number in international form
becomes E.164, and one in national form gets the given country code in
front — nine digits or more with a leading 0, or eight or more without
one, as a plan without a trunk prefix writes its numbers, the latter
only while the result is no longer than a number can be; the country
code of an E.164 number is found by the ITU length rule; short codes and
alphanumeric senders are their own keys. The display form puts a space
after the country code.
The key groups; a text goes to the address as dialled (DialledNumber:
the separators gone, a parenthesised trunk zero after a country code
dropped — not after Italy's code or San Marino's, where no zero is a
trunk prefix (a landline's is part of its number, a mobile has none):
such an address names two numbers and is none — nothing added), since
imsd sends a national number or a short code with the type unknown and
the network reads it by its own dialling plan — a country code completed
for the key would be dialled for real. A national number's leading 0 is
taken for the trunk prefix and goes when the country code is added — not
under Italy's code or San Marino's, where it is the number's and stays.
The key's known limits are of grouping: a number written with its
country code and no '+' is completed as a national one, one of a plan
whose trunk prefix is not a lone 0 (Hungary's 06, Russia's 8) is
completed wrongly, and a national number shorter than those lengths
(Iceland's seven digits) stays its digits.
Tested: tests/Number, thirty-two normalisation cases (the parenthesised
trunk zero of an international number, one after San Marino's code left
as no number, a national number's zero kept under Italy's code and San
Marino's, the numbers without a trunk prefix and both rules' shortest
numbers among them), twelve dialled forms (two with a zero in
parentheses after Italy's code, left as typed, among them), the country
codes of one-, two- and three-digit countries, the display forms.
2026-10-17 23:25:34 +02:00
using namespace ImsdMessages ;
project: the repository skeleton
The SMS app for imsd's net.catcrafts.IMS1.Messaging interface starts
here: the licence (GPL-3.0-only), FUNDING.yml, README and AGENTS, a
project.cpp with the three build products (imsd-messages-core: std and
Crafter.DB; imsd-messages-bus: GLib; the imsd-messages executable),
their module units as stubs, the version constant, the bundled Noto Sans
font with its OFL text, and the first test. This commit is the base every
later range is reviewed against.
Tested: crafter-build builds the three products and --version answers,
crafter-build test passes the one test, lint and format --check are clean
on every text rule and on the AST rules for the eleven files without a
global module fragment; the four files that include gio/gio.h are not
parsed by the lint driver's libclang (no C++ standard library on its
include path: 'type_traits' file not found), which is a Crafter.Build
matter.
2026-10-17 23:14:00 +02:00
namespace {
std : : int32_t failures = 0 ;
void Check ( bool ok , std : : string_view what ) {
std : : println ( " {} {} " , ok ? " PASS " : " FAIL " , what ) ;
if ( ! ok ) + + failures ;
}
Number: the conversation key of an address
An address becomes one conversation key. A number in international form
becomes E.164, and one in national form gets the given country code in
front — nine digits or more with a leading 0, or eight or more without
one, as a plan without a trunk prefix writes its numbers, the latter
only while the result is no longer than a number can be; the country
code of an E.164 number is found by the ITU length rule; short codes and
alphanumeric senders are their own keys. The display form puts a space
after the country code.
The key groups; a text goes to the address as dialled (DialledNumber:
the separators gone, a parenthesised trunk zero after a country code
dropped — not after Italy's code or San Marino's, where no zero is a
trunk prefix (a landline's is part of its number, a mobile has none):
such an address names two numbers and is none — nothing added), since
imsd sends a national number or a short code with the type unknown and
the network reads it by its own dialling plan — a country code completed
for the key would be dialled for real. A national number's leading 0 is
taken for the trunk prefix and goes when the country code is added — not
under Italy's code or San Marino's, where it is the number's and stays.
The key's known limits are of grouping: a number written with its
country code and no '+' is completed as a national one, one of a plan
whose trunk prefix is not a lone 0 (Hungary's 06, Russia's 8) is
completed wrongly, and a national number shorter than those lengths
(Iceland's seven digits) stays its digits.
Tested: tests/Number, thirty-two normalisation cases (the parenthesised
trunk zero of an international number, one after San Marino's code left
as no number, a national number's zero kept under Italy's code and San
Marino's, the numbers without a trunk prefix and both rules' shortest
numbers among them), twelve dialled forms (two with a zero in
parentheses after Italy's code, left as typed, among them), the country
codes of one-, two- and three-digit countries, the display forms.
2026-10-17 23:25:34 +02:00
void CheckEqual ( std : : string_view actual , std : : string_view expected , std : : string_view what ) {
const bool ok = actual = = expected ;
if ( ok ) std : : println ( " PASS {} " , what ) ;
else std : : println ( " FAIL {} — expected \" {} \" , got \" {} \" " , what , expected , actual ) ;
if ( ! ok ) + + failures ;
}
project: the repository skeleton
The SMS app for imsd's net.catcrafts.IMS1.Messaging interface starts
here: the licence (GPL-3.0-only), FUNDING.yml, README and AGENTS, a
project.cpp with the three build products (imsd-messages-core: std and
Crafter.DB; imsd-messages-bus: GLib; the imsd-messages executable),
their module units as stubs, the version constant, the bundled Noto Sans
font with its OFL text, and the first test. This commit is the base every
later range is reviewed against.
Tested: crafter-build builds the three products and --version answers,
crafter-build test passes the one test, lint and format --check are clean
on every text rule and on the AST rules for the eleven files without a
global module fragment; the four files that include gio/gio.h are not
parsed by the lint driver's libclang (no C++ standard library on its
include path: 'type_traits' file not found), which is a Crafter.Build
matter.
2026-10-17 23:14:00 +02:00
}
int main ( ) {
Number: the conversation key of an address
An address becomes one conversation key. A number in international form
becomes E.164, and one in national form gets the given country code in
front — nine digits or more with a leading 0, or eight or more without
one, as a plan without a trunk prefix writes its numbers, the latter
only while the result is no longer than a number can be; the country
code of an E.164 number is found by the ITU length rule; short codes and
alphanumeric senders are their own keys. The display form puts a space
after the country code.
The key groups; a text goes to the address as dialled (DialledNumber:
the separators gone, a parenthesised trunk zero after a country code
dropped — not after Italy's code or San Marino's, where no zero is a
trunk prefix (a landline's is part of its number, a mobile has none):
such an address names two numbers and is none — nothing added), since
imsd sends a national number or a short code with the type unknown and
the network reads it by its own dialling plan — a country code completed
for the key would be dialled for real. A national number's leading 0 is
taken for the trunk prefix and goes when the country code is added — not
under Italy's code or San Marino's, where it is the number's and stays.
The key's known limits are of grouping: a number written with its
country code and no '+' is completed as a national one, one of a plan
whose trunk prefix is not a lone 0 (Hungary's 06, Russia's 8) is
completed wrongly, and a national number shorter than those lengths
(Iceland's seven digits) stays its digits.
Tested: tests/Number, thirty-two normalisation cases (the parenthesised
trunk zero of an international number, one after San Marino's code left
as no number, a national number's zero kept under Italy's code and San
Marino's, the numbers without a trunk prefix and both rules' shortest
numbers among them), twelve dialled forms (two with a zero in
parentheses after Italy's code, left as typed, among them), the country
codes of one-, two- and three-digit countries, the display forms.
2026-10-17 23:25:34 +02:00
Check ( ! version . empty ( ) , " the version constant is set " ) ;
struct Case {
std : : string_view raw ;
std : : string_view countryCode ;
std : : string_view key ;
} ;
constexpr std : : array < Case , 25 > cases = { {
{ " +31612345678 " , " 31 " , " +31612345678 " } ,
{ " 0612345678 " , " 31 " , " +31612345678 " } ,
{ " 06 1234 5678 " , " 31 " , " +31612345678 " } ,
{ " 06-1234-5678 " , " 31 " , " +31612345678 " } ,
{ " 0031612345678 " , " " , " +31612345678 " } ,
{ " +31612345678 " , " " , " +31612345678 " } ,
{ " +1 (555) 123-4567 " , " 31 " , " +15551234567 " } ,
{ " 0612345678 " , " " , " 0612345678 " } ,
{ " 0612345678 " , " 39 " , " +390612345678 " } ,
{ " 0549123456 " , " 378 " , " +3780549123456 " } ,
{ " 021234567 " , " 32 " , " +3221234567 " } ,
{ " 02123456 " , " 32 " , " 02123456 " } ,
{ " 1234 " , " 31 " , " 1234 " } ,
{ " KPN " , " 31 " , " KPN " } ,
{ " Odido Info " , " 31 " , " Odido Info " } ,
{ " " , " 31 " , " " } ,
{ " + " , " 31 " , " + " } ,
{ " +3161234567890123456 " , " 31 " , " +3161234567890123456 " } ,
{ " +31612345678# " , " 31 " , " +31612345678# " } ,
{ " 612345678 " , " 34 " , " +34612345678 " } ,
{ " 555 123 4567 " , " 1 " , " +15551234567 " } ,
{ " 41234567 " , " 47 " , " +4741234567 " } ,
{ " 4123456 " , " 47 " , " 4123456 " } ,
{ " 612345678 " , " " , " 612345678 " } ,
{ " 123456789012345 " , " 31 " , " 123456789012345 " } ,
} } ;
for ( const Case & c : cases ) CheckEqual ( NormalizeNumber ( c . raw , c . countryCode ) , c . key , std : : format ( " NormalizeNumber( \" {} \" , \" {} \" ) " , c . raw , c . countryCode ) ) ;
CheckEqual ( CountryCodeOf ( " +31653131313 " ) , " 31 " , " country code of the KPN service centre " ) ;
CheckEqual ( CountryCodeOf ( " +15551234567 " ) , " 1 " , " one-digit code 1 " ) ;
CheckEqual ( CountryCodeOf ( " +79161234567 " ) , " 7 " , " one-digit code 7 " ) ;
CheckEqual ( CountryCodeOf ( " +212612345678 " ) , " 212 " , " three-digit code 212 " ) ;
CheckEqual ( CountryCodeOf ( " +4915112345678 " ) , " 49 " , " two-digit code 49 " ) ;
CheckEqual ( CountryCodeOf ( " +3912345678 " ) , " 39 " , " two-digit code 39 " ) ;
CheckEqual ( CountryCodeOf ( " KPN " ) , " " , " no code for an alphanumeric sender " ) ;
CheckEqual ( CountryCodeOf ( " 0612345678 " ) , " " , " no code for a national number " ) ;
CheckEqual ( NormalizeNumber ( " +31 (0)6 1234 5678 " , " 31 " ) , " +31612345678 " , " the parenthesised trunk zero of an international number is dropped " ) ;
CheckEqual ( NormalizeNumber ( " +44 (0)20 7946 0018 " , " 31 " ) , " +442079460018 " , " the same under another country code " ) ;
CheckEqual ( NormalizeNumber ( " 0031 (0)6 1234 5678 " , " 31 " ) , " +31612345678 " , " and after the 00 prefix " ) ;
CheckEqual ( NormalizeNumber ( " (06) 1234 5678 " , " 31 " ) , " +31612345678 " , " parentheses around a national number stay separators " ) ;
CheckEqual ( NormalizeNumber ( " (+44) (0)20 7946 0018 " , " 31 " ) , " +442079460018 " , " a country code in parentheses is the international form too " ) ;
CheckEqual ( NormalizeNumber ( " (+31) (0)6 1234 5678 " , " " ) , " +31612345678 " , " the same without a default code " ) ;
CheckEqual ( NormalizeNumber ( " (+378) (0)549 123456 " , " 31 " ) , " (+378) (0)549 123456 " , " after San Marino's code, as after Italy's, no zero is a trunk prefix: not a number, the address is the key " ) ;
// The dialled form: the separators gone, nothing added — the network's
// own dialling plan reads a national number or a short code.
struct DialCase {
std : : string_view raw ;
std : : string_view dialled ;
} ;
constexpr std : : array < DialCase , 12 > dials = { {
{ " +31 6 1234 5678 " , " +31612345678 " } ,
{ " (+44) (0)20 7946 0018 " , " +442079460018 " } ,
{ " 06 1234 5678 " , " 0612345678 " } ,
{ " (06) 1234-5678 " , " 0612345678 " } ,
{ " +31 (0)6 1234 5678 " , " +31612345678 " } ,
{ " +39 (0)6 1234 5678 " , " +39 (0)6 1234 5678 " } ,
{ " 0039 (0)347 1234567 " , " 0039 (0)347 1234567 " } ,
{ " 0031 6 1234 5678 " , " 0031612345678 " } ,
{ " 1234 " , " 1234 " } ,
{ " KPN " , " KPN " } ,
{ " + " , " + " } ,
{ " " , " " } ,
} } ;
for ( const DialCase & c : dials ) CheckEqual ( DialledNumber ( c . raw ) , c . dialled , std : : format ( " DialledNumber( \" {} \" ) " , c . raw ) ) ;
CheckEqual ( DisplayNumber ( " +31612345678 " ) , " +31 612345678 " , " display of an E.164 number " ) ;
CheckEqual ( DisplayNumber ( " +15551234567 " ) , " +1 5551234567 " , " display with a one-digit code " ) ;
CheckEqual ( DisplayNumber ( " 1234 " ) , " 1234 " , " display of a short code " ) ;
CheckEqual ( DisplayNumber ( " KPN " ) , " KPN " , " display of an alphanumeric sender " ) ;
project: the repository skeleton
The SMS app for imsd's net.catcrafts.IMS1.Messaging interface starts
here: the licence (GPL-3.0-only), FUNDING.yml, README and AGENTS, a
project.cpp with the three build products (imsd-messages-core: std and
Crafter.DB; imsd-messages-bus: GLib; the imsd-messages executable),
their module units as stubs, the version constant, the bundled Noto Sans
font with its OFL text, and the first test. This commit is the base every
later range is reviewed against.
Tested: crafter-build builds the three products and --version answers,
crafter-build test passes the one test, lint and format --check are clean
on every text rule and on the AST rules for the eleven files without a
global module fragment; the four files that include gio/gio.h are not
parsed by the lint driver's libclang (no C++ standard library on its
include path: 'type_traits' file not found), which is a Crafter.Build
matter.
2026-10-17 23:14:00 +02:00
return failures = = 0 ? 0 : 1 ;
}