git.iko.soy/typeable/libphonenumber
on 06f0bc4 help sign in
.github/workflows/ci.yaml+8−12
since splitsnapshots
unifiedsplit
@@ -22,19 +22,15 @@ jobs:
22 - "8.8.4"
22 - "8.8.4"
23 - "8.10.7"
23 - "8.10.7"
24 - "9.0.2"
24 - "9.0.2"
25− - "9.2.8"
25+ - "9.2.7"
26− - "9.4.8"
27− - "9.6.7"
28− - "9.8.4"
26+ - "9.4.4"
29− - "9.10.3"
27+ - "9.6.1"
30− - "9.12.2"
31− - "9.14.1"
32 fail-fast: false
28 fail-fast: false
33 name: Build on Linux, GHC ${{ matrix.ghc_version }}
29 name: Build on Linux, GHC ${{ matrix.ghc_version }}
34 runs-on: ${{ matrix.platform }}
30 runs-on: ${{ matrix.platform }}
35 steps:
31 steps:
36− - uses: actions/checkout@v4
32+ - uses: actions/checkout@v3
37− - uses: haskell-actions/setup@v2
33+ - uses: haskell/actions/setup@v2
38 with:
34 with:
39 ghc-version: ${{ matrix.ghc_version }}
35 ghc-version: ${{ matrix.ghc_version }}
40 cabal-version: "3.10.1.0"
36 cabal-version: "3.10.1.0"
@@ -70,7 +66,7 @@ jobs:
70 if: github.event_name == 'release'
66 if: github.event_name == 'release'
71 steps:
67 steps:
72 - uses: actions/checkout@v3
68 - uses: actions/checkout@v3
73− - uses: haskell-actions/setup@v2
69+ - uses: haskell/actions/setup@v2
74 with:
70 with:
75 cabal-version: "3.10.1.0"
71 cabal-version: "3.10.1.0"
76 - name: Install C++ library
72 - name: Install C++ library
@@ -85,11 +81,11 @@ jobs:
85 run: |
81 run: |
86 cabal haddock --builddir "$GITHUB_WORKSPACE/doc" --haddock-for-hackage --enable-doc
82 cabal haddock --builddir "$GITHUB_WORKSPACE/doc" --haddock-for-hackage --enable-doc
87 echo "docs=$(find "$GITHUB_WORKSPACE/doc" -maxdepth 1 -type f -name '*-docs.tar.gz')" >> "$GITHUB_ENV"
83 echo "docs=$(find "$GITHUB_WORKSPACE/doc" -maxdepth 1 -type f -name '*-docs.tar.gz')" >> "$GITHUB_ENV"
88− - uses: actions/upload-artifact@v6
84+ - uses: actions/upload-artifact@v2
89 with:
85 with:
90 name: Source tarball
86 name: Source tarball
91 path: ${{ env.dist }}
87 path: ${{ env.dist }}
92− - uses: svenstaro/upload-release-action@2.11.3
88+ - uses: svenstaro/upload-release-action@2.2.1
93 with:
89 with:
94 repo_token: ${{ secrets.GITHUB_TOKEN }}
90 repo_token: ${{ secrets.GITHUB_TOKEN }}
95 file: ${{ env.dist }}
91 file: ${{ env.dist }}
cxxbits/c_phonenumber.cpp+4−6
@@ -55,7 +55,7 @@ static country_code_source unmarshal_country_code_source(PhoneNumber::CountryCod
55 return static_cast<country_code_source>(value);
55 return static_cast<country_code_source>(value);
56}
56}
57
57
58−extern "C" CxxPhoneNumber *c_phone_number_marshal(phone_number const *c_number)
58+extern "C" PhoneNumber *c_phone_number_marshal(phone_number const *c_number)
59{
59{
60 PhoneNumber *number = new PhoneNumber();
60 PhoneNumber *number = new PhoneNumber();
61 if (c_number->extension != nullptr)
61 if (c_number->extension != nullptr)
@@ -72,12 +72,11 @@ extern "C" CxxPhoneNumber *c_phone_number_marshal(phone_number const *c_number)
72 number->set_country_code_source(marshal_country_code_source(c_number->country_code_source));
72 number->set_country_code_source(marshal_country_code_source(c_number->country_code_source));
73 if (c_number->has_number_of_leading_zeros)
73 if (c_number->has_number_of_leading_zeros)
74 number->set_number_of_leading_zeros(c_number->number_of_leading_zeros);
74 number->set_number_of_leading_zeros(c_number->number_of_leading_zeros);
75− return reinterpret_cast<CxxPhoneNumber *>(number);
75+ return number;
76}
76}
77
77
78−extern "C" void c_phone_number_unmarshal(CxxPhoneNumber const *ptr, phone_number *c_number)
78+extern "C" void c_phone_number_unmarshal(PhoneNumber const *number, phone_number *c_number)
79{
79{
80− auto number = reinterpret_cast<PhoneNumber const *>(ptr);
81 if (number->has_extension())
80 if (number->has_extension())
82 unmarshal_string_size(number->extension(), c_number->extension, c_number->extension_size);
81 unmarshal_string_size(number->extension(), c_number->extension, c_number->extension_size);
83 else
82 else
@@ -100,8 +99,7 @@ extern "C" void c_phone_number_unmarshal(CxxPhoneNumber const *ptr, phone_number
100 c_number->number_of_leading_zeros = number->number_of_leading_zeros();
99 c_number->number_of_leading_zeros = number->number_of_leading_zeros();
101}
100}
102
101
103−extern "C" void c_phone_number_free(CxxPhoneNumber *ptr)
102+extern "C" void c_phone_number_free(PhoneNumber *number)
104{
103{
105− auto number = reinterpret_cast<PhoneNumber *>(ptr);
106 delete number;
104 delete number;
107}
105}
cxxbits/c_phonenumberutil.cpp+26−45
@@ -310,11 +310,10 @@ extern "C" void c_phone_number_util_normalize_dialable_chars_only(
310}
310}
311
311
312extern "C" void c_phone_number_util_get_national_significant_number(
312extern "C" void c_phone_number_util_get_national_significant_number(
313− CxxPhoneNumber const *ptr,
313+ PhoneNumber const *number,
314 c_string *c_nsn
314 c_string *c_nsn
315)
315)
316{
316{
317− auto number = reinterpret_cast<PhoneNumber const *>(ptr);
318 std::string nsn;
317 std::string nsn;
319 PhoneNumberUtil::GetInstance()->GetNationalSignificantNumber(*number, &nsn);
318 PhoneNumberUtil::GetInstance()->GetNationalSignificantNumber(*number, &nsn);
320 unmarshal_c_string(nsn, *c_nsn);
319 unmarshal_c_string(nsn, *c_nsn);
@@ -331,25 +330,23 @@ extern "C" void c_phone_number_util_get_country_mobile_token(
331}
330}
332
331
333extern "C" void c_phone_number_util_format(
332extern "C" void c_phone_number_util_format(
334− CxxPhoneNumber const *ptr,
333+ PhoneNumber const *number,
335 phone_number_format format,
334 phone_number_format format,
336 c_string *c_string
335 c_string *c_string
337)
336)
338{
337{
339− auto number = reinterpret_cast<PhoneNumber const *>(ptr);
340 std::string string;
338 std::string string;
341 PhoneNumberUtil::GetInstance()->Format(*number, marshal_phone_number_format(format), &string);
339 PhoneNumberUtil::GetInstance()->Format(*number, marshal_phone_number_format(format), &string);
342 unmarshal_c_string(string, *c_string);
340 unmarshal_c_string(string, *c_string);
343}
341}
344
342
345extern "C" void c_phone_number_util_format_national_number_with_carrier_code(
343extern "C" void c_phone_number_util_format_national_number_with_carrier_code(
346− CxxPhoneNumber const *ptr,
344+ PhoneNumber const *number,
347 char const *c_carrier_code,
345 char const *c_carrier_code,
348 size_t c_carrier_code_size,
346 size_t c_carrier_code_size,
349 c_string *c_string
347 c_string *c_string
350)
348)
351{
349{
352− auto number = reinterpret_cast<PhoneNumber const *>(ptr);
353 std::string const carrier_code(c_carrier_code, c_carrier_code_size);
350 std::string const carrier_code(c_carrier_code, c_carrier_code_size);
354 std::string string;
351 std::string string;
355 PhoneNumberUtil::GetInstance()->FormatNationalNumberWithCarrierCode(*number, carrier_code, &string);
352 PhoneNumberUtil::GetInstance()->FormatNationalNumberWithCarrierCode(*number, carrier_code, &string);
@@ -357,13 +354,12 @@ extern "C" void c_phone_number_util_format_national_number_with_carrier_code(
357}
354}
358
355
359extern "C" void c_phone_number_util_format_national_number_with_preferred_carrier_code(
356extern "C" void c_phone_number_util_format_national_number_with_preferred_carrier_code(
360− CxxPhoneNumber const *ptr,
357+ PhoneNumber const *number,
361 char const *c_carrier_code,
358 char const *c_carrier_code,
362 size_t c_carrier_code_size,
359 size_t c_carrier_code_size,
363 c_string *c_string
360 c_string *c_string
364)
361)
365{
362{
366− auto number = reinterpret_cast<PhoneNumber const *>(ptr);
367 std::string const carrier_code(c_carrier_code, c_carrier_code_size);
363 std::string const carrier_code(c_carrier_code, c_carrier_code_size);
368 std::string string;
364 std::string string;
369 PhoneNumberUtil::GetInstance()->FormatNationalNumberWithPreferredCarrierCode(*number, carrier_code, &string);
365 PhoneNumberUtil::GetInstance()->FormatNationalNumberWithPreferredCarrierCode(*number, carrier_code, &string);
@@ -371,14 +367,13 @@ extern "C" void c_phone_number_util_format_national_number_with_preferred_carrie
371}
367}
372
368
373extern "C" void c_phone_number_util_format_number_for_mobile_dialing(
369extern "C" void c_phone_number_util_format_number_for_mobile_dialing(
374− CxxPhoneNumber const *ptr,
370+ PhoneNumber const *number,
375 char const *c_region,
371 char const *c_region,
376 size_t c_region_size,
372 size_t c_region_size,
377 int with_formatting,
373 int with_formatting,
378 c_string *c_string
374 c_string *c_string
379)
375)
380{
376{
381− auto number = reinterpret_cast<PhoneNumber const *>(ptr);
382 std::string const region(c_region, c_region_size);
377 std::string const region(c_region, c_region_size);
383 std::string string;
378 std::string string;
384 PhoneNumberUtil::GetInstance()->FormatNumberForMobileDialing(*number, region, with_formatting, &string);
379 PhoneNumberUtil::GetInstance()->FormatNumberForMobileDialing(*number, region, with_formatting, &string);
@@ -386,13 +381,12 @@ extern "C" void c_phone_number_util_format_number_for_mobile_dialing(
386}
381}
387
382
388extern "C" void c_phone_number_util_format_out_of_country_calling_number(
383extern "C" void c_phone_number_util_format_out_of_country_calling_number(
389− CxxPhoneNumber const *ptr,
384+ PhoneNumber const *number,
390 char const *c_region,
385 char const *c_region,
391 size_t c_region_size,
386 size_t c_region_size,
392 c_string *c_string
387 c_string *c_string
393)
388)
394{
389{
395− auto number = reinterpret_cast<PhoneNumber const *>(ptr);
396 std::string const region(c_region, c_region_size);
390 std::string const region(c_region, c_region_size);
397 std::string string;
391 std::string string;
398 PhoneNumberUtil::GetInstance()->FormatOutOfCountryCallingNumber(*number, region, &string);
392 PhoneNumberUtil::GetInstance()->FormatOutOfCountryCallingNumber(*number, region, &string);
@@ -400,13 +394,12 @@ extern "C" void c_phone_number_util_format_out_of_country_calling_number(
400}
394}
401
395
402extern "C" void c_phone_number_util_format_in_original_format(
396extern "C" void c_phone_number_util_format_in_original_format(
403− CxxPhoneNumber const *ptr,
397+ PhoneNumber const *number,
404 char const *c_region,
398 char const *c_region,
405 size_t c_region_size,
399 size_t c_region_size,
406 c_string *c_string
400 c_string *c_string
407)
401)
408{
402{
409− auto number = reinterpret_cast<PhoneNumber const *>(ptr);
410 std::string const region(c_region, c_region_size);
403 std::string const region(c_region, c_region_size);
411 std::string string;
404 std::string string;
412 PhoneNumberUtil::GetInstance()->FormatInOriginalFormat(*number, region, &string);
405 PhoneNumberUtil::GetInstance()->FormatInOriginalFormat(*number, region, &string);
@@ -414,26 +407,24 @@ extern "C" void c_phone_number_util_format_in_original_format(
414}
407}
415
408
416extern "C" void c_phone_number_util_format_out_of_country_keeping_alpha_chars(
409extern "C" void c_phone_number_util_format_out_of_country_keeping_alpha_chars(
417− CxxPhoneNumber const *ptr,
410+ PhoneNumber const *number,
418 char const *c_region,
411 char const *c_region,
419 size_t c_region_size,
412 size_t c_region_size,
420 c_string *c_string
413 c_string *c_string
421)
414)
422{
415{
423− auto number = reinterpret_cast<PhoneNumber const *>(ptr);
424 std::string const region(c_region, c_region_size);
416 std::string const region(c_region, c_region_size);
425 std::string string;
417 std::string string;
426 PhoneNumberUtil::GetInstance()->FormatOutOfCountryKeepingAlphaChars(*number, region, &string);
418 PhoneNumberUtil::GetInstance()->FormatOutOfCountryKeepingAlphaChars(*number, region, &string);
427 unmarshal_c_string(string, *c_string);
419 unmarshal_c_string(string, *c_string);
428}
420}
429
421
430−extern "C" CxxPhoneNumber *c_phone_number_util_truncate_too_long_number(CxxPhoneNumber const *ptr)
422+extern "C" PhoneNumber *c_phone_number_util_truncate_too_long_number(PhoneNumber const *input)
431{
423{
432− auto input = reinterpret_cast<PhoneNumber const *>(ptr);
433 auto *output = new PhoneNumber(*input);
424 auto *output = new PhoneNumber(*input);
434 if (PhoneNumberUtil::GetInstance()->TruncateTooLongNumber(output))
425 if (PhoneNumberUtil::GetInstance()->TruncateTooLongNumber(output))
435 {
426 {
436− return reinterpret_cast<CxxPhoneNumber *>(output);
427+ return output;
437 }
428 }
438 else
429 else
439 {
430 {
@@ -442,37 +433,33 @@ extern "C" CxxPhoneNumber *c_phone_number_util_truncate_too_long_number(CxxPhone
442 }
433 }
443}
434}
444
435
445−extern "C" phone_number_type c_phone_number_util_get_number_type(CxxPhoneNumber const *ptr)
436+extern "C" phone_number_type c_phone_number_util_get_number_type(PhoneNumber const *number)
446{
437{
447− auto number = reinterpret_cast<PhoneNumber const *>(ptr);
448 return unmarshal_phone_number_type(
438 return unmarshal_phone_number_type(
449 PhoneNumberUtil::GetInstance()->GetNumberType(*number)
439 PhoneNumberUtil::GetInstance()->GetNumberType(*number)
450 );
440 );
451}
441}
452
442
453−extern "C" int c_phone_number_util_is_valid_number(CxxPhoneNumber const *ptr)
443+extern "C" int c_phone_number_util_is_valid_number(PhoneNumber const *number)
454{
444{
455− auto number = reinterpret_cast<PhoneNumber const *>(ptr);
456 return PhoneNumberUtil::GetInstance()->IsValidNumber(*number);
445 return PhoneNumberUtil::GetInstance()->IsValidNumber(*number);
457}
446}
458
447
459extern "C" int c_phone_number_util_is_valid_number_for_region(
448extern "C" int c_phone_number_util_is_valid_number_for_region(
460− CxxPhoneNumber const *ptr,
449+ PhoneNumber const *number,
461 char const *c_region,
450 char const *c_region,
462 size_t c_region_size
451 size_t c_region_size
463)
452)
464{
453{
465− auto number = reinterpret_cast<PhoneNumber const *>(ptr);
466 std::string const region(c_region, c_region_size);
454 std::string const region(c_region, c_region_size);
467 return PhoneNumberUtil::GetInstance()->IsValidNumberForRegion(*number, region);
455 return PhoneNumberUtil::GetInstance()->IsValidNumberForRegion(*number, region);
468}
456}
469
457
470extern "C" void c_phone_number_util_get_region_code_for_number(
458extern "C" void c_phone_number_util_get_region_code_for_number(
471− CxxPhoneNumber const *ptr,
459+ PhoneNumber const *number,
472 c_string *c_region
460 c_string *c_region
473)
461)
474{
462{
475− auto number = reinterpret_cast<PhoneNumber const *>(ptr);
476 std::string region;
463 std::string region;
477 PhoneNumberUtil::GetInstance()->GetRegionCodeForNumber(*number, &region);
464 PhoneNumberUtil::GetInstance()->GetRegionCodeForNumber(*number, &region);
478 unmarshal_c_string(region, *c_region);
465 unmarshal_c_string(region, *c_region);
@@ -531,11 +518,10 @@ extern "C" void c_phone_number_util_get_ndd_prefix_for_region(
531}
518}
532
519
533extern "C" validation_result c_phone_number_util_is_possible_number_for_type_with_reason(
520extern "C" validation_result c_phone_number_util_is_possible_number_for_type_with_reason(
534− CxxPhoneNumber const *ptr,
521+ PhoneNumber const *number,
535 phone_number_type ntype
522 phone_number_type ntype
536)
523)
537{
524{
538− auto number = reinterpret_cast<PhoneNumber const *>(ptr);
539 return unmarshal_validation_result(
525 return unmarshal_validation_result(
540 PhoneNumberUtil::GetInstance()->IsPossibleNumberForTypeWithReason(
526 PhoneNumberUtil::GetInstance()->IsPossibleNumberForTypeWithReason(
541 *number,
527 *number,
@@ -544,15 +530,13 @@ extern "C" validation_result c_phone_number_util_is_possible_number_for_type_wit
544 );
530 );
545}
531}
546
532
547−extern "C" int c_phone_number_util_can_be_internationally_dialed(CxxPhoneNumber const *ptr)
533+extern "C" int c_phone_number_util_can_be_internationally_dialed(PhoneNumber const *number)
548{
534{
549− auto number = reinterpret_cast<PhoneNumber const *>(ptr);
550 return PhoneNumberUtil::GetInstance()->CanBeInternationallyDialled(*number);
535 return PhoneNumberUtil::GetInstance()->CanBeInternationallyDialled(*number);
551}
536}
552
537
553−extern "C" int c_phone_number_util_is_number_geographical_1(CxxPhoneNumber const *ptr)
538+extern "C" int c_phone_number_util_is_number_geographical_1(PhoneNumber const *number)
554{
539{
555− auto number = reinterpret_cast<PhoneNumber const *>(ptr);
556 return PhoneNumberUtil::GetInstance()->IsNumberGeographical(*number);
540 return PhoneNumberUtil::GetInstance()->IsNumberGeographical(*number);
557}
541}
558
542
@@ -572,14 +556,14 @@ extern "C" error_type c_phone_number_util_parse(
572 size_t c_string_size,
556 size_t c_string_size,
573 char const *c_region,
557 char const *c_region,
574 size_t c_region_size,
558 size_t c_region_size,
575− CxxPhoneNumber **number
559+ PhoneNumber **number
576)
560)
577{
561{
578 std::string const string(c_string, c_string_size);
562 std::string const string(c_string, c_string_size);
579 std::string const region(c_region, c_region_size);
563 std::string const region(c_region, c_region_size);
580− *number = reinterpret_cast<CxxPhoneNumber *>(new PhoneNumber());
564+ *number = new PhoneNumber();
581 return unmarshal_error_type(
565 return unmarshal_error_type(
582− PhoneNumberUtil::GetInstance()->Parse(string, region, reinterpret_cast<PhoneNumber *>(*number))
566+ PhoneNumberUtil::GetInstance()->Parse(string, region, *number)
583 );
567 );
584}
568}
585
569
@@ -588,24 +572,22 @@ extern "C" error_type c_phone_number_util_parse_and_keep_raw_input(
588 size_t c_string_size,
572 size_t c_string_size,
589 char const *c_region,
573 char const *c_region,
590 size_t c_region_size,
574 size_t c_region_size,
591− CxxPhoneNumber **number
575+ PhoneNumber **number
592)
576)
593{
577{
594 std::string const string(c_string, c_string_size);
578 std::string const string(c_string, c_string_size);
595 std::string const region(c_region, c_region_size);
579 std::string const region(c_region, c_region_size);
596− *number = reinterpret_cast<CxxPhoneNumber *>(new PhoneNumber());
580+ *number = new PhoneNumber();
597 return unmarshal_error_type(
581 return unmarshal_error_type(
598− PhoneNumberUtil::GetInstance()->ParseAndKeepRawInput(string, region, reinterpret_cast<PhoneNumber *>(*number))
582+ PhoneNumberUtil::GetInstance()->ParseAndKeepRawInput(string, region, *number)
599 );
583 );
600}
584}
601
585
602extern "C" match_type c_phone_number_util_is_number_match(
586extern "C" match_type c_phone_number_util_is_number_match(
603− CxxPhoneNumber const *ptr1,
587+ PhoneNumber const *number1,
604− CxxPhoneNumber const *ptr2
588+ PhoneNumber const *number2
605)
589)
606{
590{
607− auto number1 = reinterpret_cast<PhoneNumber const *>(ptr1);
608− auto number2 = reinterpret_cast<PhoneNumber const *>(ptr2);
609 return unmarshal_match_type(
591 return unmarshal_match_type(
610 PhoneNumberUtil::GetInstance()->IsNumberMatch(*number1, *number2)
592 PhoneNumberUtil::GetInstance()->IsNumberMatch(*number1, *number2)
611 );
593 );
@@ -626,12 +608,11 @@ extern "C" match_type c_phone_number_util_is_number_match_with_two_strings(
626}
608}
627
609
628extern "C" match_type c_phone_number_util_is_number_match_with_one_string(
610extern "C" match_type c_phone_number_util_is_number_match_with_one_string(
629− CxxPhoneNumber const *ptr1,
611+ PhoneNumber const *number1,
630 char const *c_number2,
612 char const *c_number2,
631 size_t c_number2_size
613 size_t c_number2_size
632)
614)
633{
615{
634− auto number1 = reinterpret_cast<PhoneNumber const *>(ptr1);
635 std::string const number2(c_number2, c_number2_size);
616 std::string const number2(c_number2, c_number2_size);
636 return unmarshal_match_type(
617 return unmarshal_match_type(
637 PhoneNumberUtil::GetInstance()->IsNumberMatchWithOneString(*number1, number2)
618 PhoneNumberUtil::GetInstance()->IsNumberMatchWithOneString(*number1, number2)
include/c_phonenumber.h+8−4
@@ -43,16 +43,20 @@ typedef struct
43 char has_number_of_leading_zeros;
43 char has_number_of_leading_zeros;
44} phone_number;
44} phone_number;
45
45
46−struct CxxPhoneNumber;
46+#ifdef __cplusplus
47+typedef i18n::phonenumbers::PhoneNumber PhoneNumber;
48+#else
49+typedef struct PhoneNumber PhoneNumber;
50+#endif
47
51
48// The returned object is allocated by `new` and managed by C++ RAII, and it is
52// The returned object is allocated by `new` and managed by C++ RAII, and it is
49// haskell's responsibility to call its finalizer (c_phone_number_free).
53// haskell's responsibility to call its finalizer (c_phone_number_free).
50−struct CxxPhoneNumber *c_phone_number_marshal(phone_number const *);
54+PhoneNumber *c_phone_number_marshal(phone_number const *);
51
55
52// phone_number * points to an area which will be filled with the data of the
56// phone_number * points to an area which will be filled with the data of the
53// given PhoneNumber.
57// given PhoneNumber.
54−void c_phone_number_unmarshal(struct CxxPhoneNumber const *, phone_number *);
58+void c_phone_number_unmarshal(PhoneNumber const *, phone_number *);
55
59
56−void c_phone_number_free(struct CxxPhoneNumber *);
60+void c_phone_number_free(PhoneNumber *);
57
61
58#endif
62#endif
include/c_phonenumberutil.h+20−20
@@ -97,34 +97,34 @@ int c_phone_number_util_is_alpha_number(char const *, size_t);
97void c_phone_number_util_convert_alpha_characters_in_number(char const *, size_t, c_string *);
97void c_phone_number_util_convert_alpha_characters_in_number(char const *, size_t, c_string *);
98void c_phone_number_util_normalize_digits_only(char const *, size_t, c_string *);
98void c_phone_number_util_normalize_digits_only(char const *, size_t, c_string *);
99void c_phone_number_util_normalize_dialable_chars_only(char const *, size_t, c_string *);
99void c_phone_number_util_normalize_dialable_chars_only(char const *, size_t, c_string *);
100−void c_phone_number_util_get_national_significant_number(struct CxxPhoneNumber const *, c_string *);
100+void c_phone_number_util_get_national_significant_number(PhoneNumber const *, c_string *);
101void c_phone_number_util_get_country_mobile_token(int, c_string *);
101void c_phone_number_util_get_country_mobile_token(int, c_string *);
102−void c_phone_number_util_format(struct CxxPhoneNumber const *, enum phone_number_format, c_string *);
102+void c_phone_number_util_format(PhoneNumber const *, enum phone_number_format, c_string *);
103−void c_phone_number_util_format_national_number_with_carrier_code(struct CxxPhoneNumber const *, char const *, size_t, c_string *);
103+void c_phone_number_util_format_national_number_with_carrier_code(PhoneNumber const *, char const *, size_t, c_string *);
104−void c_phone_number_util_format_national_number_with_preferred_carrier_code(struct CxxPhoneNumber const *, char const *, size_t, c_string *);
104+void c_phone_number_util_format_national_number_with_preferred_carrier_code(PhoneNumber const *, char const *, size_t, c_string *);
105−void c_phone_number_util_format_number_for_mobile_dialing(struct CxxPhoneNumber const *, char const *, size_t, int, c_string *);
105+void c_phone_number_util_format_number_for_mobile_dialing(PhoneNumber const *, char const *, size_t, int, c_string *);
106−void c_phone_number_util_format_out_of_country_calling_number(struct CxxPhoneNumber const *, char const *, size_t, c_string *);
106+void c_phone_number_util_format_out_of_country_calling_number(PhoneNumber const *, char const *, size_t, c_string *);
107−void c_phone_number_util_format_in_original_format(struct CxxPhoneNumber const *, char const *, size_t, c_string *);
107+void c_phone_number_util_format_in_original_format(PhoneNumber const *, char const *, size_t, c_string *);
108−void c_phone_number_util_format_out_of_country_keeping_alpha_chars(struct CxxPhoneNumber const *, char const *, size_t, c_string *);
108+void c_phone_number_util_format_out_of_country_keeping_alpha_chars(PhoneNumber const *, char const *, size_t, c_string *);
109// /!\ May return NULL
109// /!\ May return NULL
110−struct CxxPhoneNumber *c_phone_number_util_truncate_too_long_number(struct CxxPhoneNumber const *);
110+PhoneNumber *c_phone_number_util_truncate_too_long_number(PhoneNumber const *);
111−enum phone_number_type c_phone_number_util_get_number_type(struct CxxPhoneNumber const *);
111+enum phone_number_type c_phone_number_util_get_number_type(PhoneNumber const *);
112−int c_phone_number_util_is_valid_number(struct CxxPhoneNumber const *);
112+int c_phone_number_util_is_valid_number(PhoneNumber const *);
113−int c_phone_number_util_is_valid_number_for_region(struct CxxPhoneNumber const *, char const *, size_t);
113+int c_phone_number_util_is_valid_number_for_region(PhoneNumber const *, char const *, size_t);
114−void c_phone_number_util_get_region_code_for_number(struct CxxPhoneNumber const *, c_string *);
114+void c_phone_number_util_get_region_code_for_number(PhoneNumber const *, c_string *);
115int c_phone_number_util_get_country_code_for_region(char const *, size_t);
115int c_phone_number_util_get_country_code_for_region(char const *, size_t);
116void c_phone_number_util_get_region_code_for_country_code(int, c_string *);
116void c_phone_number_util_get_region_code_for_country_code(int, c_string *);
117void c_phone_number_util_get_region_codes_for_country_calling_code(int, c_string **, size_t *);
117void c_phone_number_util_get_region_codes_for_country_calling_code(int, c_string **, size_t *);
118int c_phone_number_util_is_nanpa_country(char const *, size_t);
118int c_phone_number_util_is_nanpa_country(char const *, size_t);
119void c_phone_number_util_get_ndd_prefix_for_region(char const *, size_t, int, c_string *);
119void c_phone_number_util_get_ndd_prefix_for_region(char const *, size_t, int, c_string *);
120−enum validation_result c_phone_number_util_is_possible_number_for_type_with_reason(struct CxxPhoneNumber const *, enum phone_number_type);
120+enum validation_result c_phone_number_util_is_possible_number_for_type_with_reason(PhoneNumber const *, enum phone_number_type);
121−int c_phone_number_util_can_be_internationally_dialed(struct CxxPhoneNumber const *);
121+int c_phone_number_util_can_be_internationally_dialed(PhoneNumber const *);
122−int c_phone_number_util_is_number_geographical_1(struct CxxPhoneNumber const *);
122+int c_phone_number_util_is_number_geographical_1(PhoneNumber const *);
123int c_phone_number_util_is_number_geographical_2(enum phone_number_type, int);
123int c_phone_number_util_is_number_geographical_2(enum phone_number_type, int);
124−enum error_type c_phone_number_util_parse(char const *, size_t, char const *, size_t, struct CxxPhoneNumber **);
124+enum error_type c_phone_number_util_parse(char const *, size_t, char const *, size_t, PhoneNumber **);
125−enum error_type c_phone_number_util_parse_and_keep_raw_input(char const *, size_t, char const *, size_t, struct CxxPhoneNumber **);
125+enum error_type c_phone_number_util_parse_and_keep_raw_input(char const *, size_t, char const *, size_t, PhoneNumber **);
126−enum match_type c_phone_number_util_is_number_match(struct CxxPhoneNumber const *, struct CxxPhoneNumber const *);
126+enum match_type c_phone_number_util_is_number_match(PhoneNumber const *, PhoneNumber const *);
127enum match_type c_phone_number_util_is_number_match_with_two_strings(char const *, size_t, char const *, size_t);
127enum match_type c_phone_number_util_is_number_match_with_two_strings(char const *, size_t, char const *, size_t);
128−enum match_type c_phone_number_util_is_number_match_with_one_string(struct CxxPhoneNumber const *, char const *, size_t);
128+enum match_type c_phone_number_util_is_number_match_with_one_string(PhoneNumber const *, char const *, size_t);
129
129
130#endif
130#endif
libphonenumber.cabal+12−16
@@ -1,6 +1,6 @@
1cabal-version: 3.0
1cabal-version: 3.0
2name: libphonenumber
2name: libphonenumber
3−version: 0.1.4.0
3+version: 0.1.1.0
4category: Data
4category: Data
5synopsis: Parsing, formatting, and validating international phone
5synopsis: Parsing, formatting, and validating international phone
6 numbers
6 numbers
@@ -25,7 +25,7 @@ description:
25 and to avoid a dependency on @text@, we use 'ByteString'
25 and to avoid a dependency on @text@, we use 'ByteString'
26 throughout the library instead of 'Data.Text.Text'.
26 throughout the library instead of 'Data.Text.Text'.
27
27
28−copyright: 2023-2025 Typeable
28+copyright: 2023 Typeable
29author: Typeable
29author: Typeable
30maintainer: mniip@typeable.io
30maintainer: mniip@typeable.io
31homepage: https://github.com/typeable/libphonenumber/
31homepage: https://github.com/typeable/libphonenumber/
@@ -37,13 +37,9 @@ tested-with:
37 , GHC == 8.8.4
37 , GHC == 8.8.4
38 , GHC == 8.10.7
38 , GHC == 8.10.7
39 , GHC == 9.0.2
39 , GHC == 9.0.2
40− , GHC == 9.2.8
40+ , GHC == 9.2.7
41− , GHC == 9.4.8
42− , GHC == 9.6.7
43− , GHC == 9.8.4
41+ , GHC == 9.4.4
44− , GHC == 9.10.3
42+ , GHC == 9.6.1
45− , GHC == 9.12.2
46− , GHC == 9.14.1
47
43
48build-type: Simple
44build-type: Simple
49
45
@@ -64,13 +60,12 @@ library
64 , Data.PhoneNumber.Internal.Number
60 , Data.PhoneNumber.Internal.Number
65 , Data.PhoneNumber.Internal.Util
61 , Data.PhoneNumber.Internal.Util
66 build-depends:
62 build-depends:
67− , base >= 4.12 && < 4.23
63+ , base >= 4.12 && < 4.19
68− , bytestring >= 0.10.8 && < 0.13
64+ , bytestring >= 0.10.8 && < 0.12
69− , containers >= 0.6.0 && < 0.9
65+ , containers >= 0.6.0 && < 0.7
70− , deepseq >= 1.4.4 && < 1.6
66+ , deepseq >= 1.4.4 && < 1.5
71 , transformers >= 0.5.5 && < 0.7
67 , transformers >= 0.5.5 && < 0.7
72 build-tool-depends: c2hs:c2hs
68 build-tool-depends: c2hs:c2hs
73− pkgconfig-depends: protobuf
74 include-dirs: include
69 include-dirs: include
75 includes:
70 includes:
76 , c_phonenumber.h
71 , c_phonenumber.h
@@ -80,6 +75,7 @@ library
80 , cxxbits/c_phonenumberutil.cpp
75 , cxxbits/c_phonenumberutil.cpp
81 extra-libraries:
76 extra-libraries:
82 , phonenumber
77 , phonenumber
78+ , protobuf
83 if impl(ghc >= 9.4)
79 if impl(ghc >= 9.4)
84 build-depends: system-cxx-std-lib
80 build-depends: system-cxx-std-lib
85 else
81 else
@@ -109,9 +105,9 @@ test-suite spec_test
109 , base
105 , base
110 , bytestring
106 , bytestring
111 , containers
107 , containers
112− , hspec >= 2.10.8 && < 2.12
108+ , hspec >= 2.10.8 && < 2.11
113 , libphonenumber
109 , libphonenumber
114− , QuickCheck >= 2.13.1 && < 2.16
110+ , QuickCheck >= 2.13.1 && < 2.15
115 main-is: Spec.hs
111 main-is: Spec.hs
116 hs-source-dirs: test
112 hs-source-dirs: test
117 default-language: Haskell2010
113 default-language: Haskell2010
src/Data/PhoneNumber/Internal/Number.chs+1−1
@@ -126,7 +126,7 @@ acquireCPhoneNumber p = do
126-- , 'Data.PhoneNumber.Number.numberOfLeadingZeros' :: !('Maybe' 'Int')
126-- , 'Data.PhoneNumber.Number.numberOfLeadingZeros' :: !('Maybe' 'Int')
127-- }
127-- }
128-- @
128-- @
129−{#pointer *CxxPhoneNumber as PhoneNumber foreign finalizer c_phone_number_free newtype#}
129+{#pointer *PhoneNumber foreign finalizer c_phone_number_free newtype#}
130
130
131{#fun unsafe c_phone_number_marshal
131{#fun unsafe c_phone_number_marshal
132 { withCPhoneNumber* `CPhoneNumber'
132 { withCPhoneNumber* `CPhoneNumber'
src/Data/PhoneNumber/Number.hs+10−4
@@ -21,10 +21,16 @@ module Data.PhoneNumber.Number
21 ) where
21 ) where
22
22
23import Data.ByteString (ByteString)
23import Data.ByteString (ByteString)
24−import Data.PhoneNumber.Internal.Number
24+import Data.PhoneNumber.Internal.Number hiding
25− ( CPhoneNumber(CPhoneNumber), PhoneNumber, CountryCodeSource, toCPhoneNumber
25+ ( pattern PhoneNumber
26− , fromCPhoneNumber
26+ , extension
27− )
27+ , rawInput
28+ , preferredDomesticCarrierCode
29+ , nationalNumber
30+ , countryCode
31+ , italianLeadingZero
32+ , countryCodeSource
33+ , numberOfLeadingZeros )
28import qualified Data.PhoneNumber.Internal.Number as I
34import qualified Data.PhoneNumber.Internal.Number as I
29
35
30-- | A country calling code (International Subscriber Dialing code, ISD code),
36-- | A country calling code (International Subscriber Dialing code, ISD code),
test/Spec.hs+23−24
@@ -53,13 +53,11 @@ data ParsedNumber = ParsedNumber (ParseMode, Maybe Region, ParserInput) PhoneNum
53 deriving stock (Show)
53 deriving stock (Show)
54
54
55instance Arbitrary ParsedNumber where
55instance Arbitrary ParsedNumber where
56− arbitrary = do
57− mode <- elements [Canonicalize, KeepRawInput]
56+ arbitrary = liftA3 (,,) (elements [Canonicalize, KeepRawInput]) arbitrary arbitrary
58− liftA2 ((,,) mode) arbitrary arbitrary
59− `suchThatMap` \(_, MReg mRegion, ParserInput input) ->
57+ `suchThatMap` \(mode, MReg mRegion, ParserInput input) ->
60− case parseNumber mode mRegion input of
58+ case parseNumber mode mRegion input of
61− Right pn -> Just $ ParsedNumber (mode, mRegion, ParserInput input) pn
59+ Right pn -> Just $ ParsedNumber (mode, mRegion, ParserInput input) pn
62− _ -> Nothing
60+ _ -> Nothing
63 shrink (ParsedNumber (mode, region, input) _) = do
61 shrink (ParsedNumber (mode, region, input) _) = do
64 ParserInput input' <- shrink input
62 ParserInput input' <- shrink input
65 case parseNumber mode region input' of
63 case parseNumber mode region input' of
@@ -115,7 +113,7 @@ main = hspec $ modifyMaxSuccess (* 10) $ do
115 .&&. not (BS.null $ normalizeNumber Digits $ BS.pack str <> "0")
113 .&&. not (BS.null $ normalizeNumber Digits $ BS.pack str <> "0")
116 describe "Dialable" $ do
114 describe "Dialable" $ do
117 -- PhoneNumberUtil::NormalizeDiallableCharsOnly will error on any invalid UTF8
115 -- PhoneNumberUtil::NormalizeDiallableCharsOnly will error on any invalid UTF8
118− prop "doesn't randomly fail" $ \str ->
116+ xprop "doesn't randomly fail" $ \str ->
119 not (BS.null $ normalizeNumber Digits $ "0" <> BS.pack str)
117 not (BS.null $ normalizeNumber Digits $ "0" <> BS.pack str)
120 .&&. not (BS.null $ normalizeNumber Digits $ BS.pack str <> "0")
118 .&&. not (BS.null $ normalizeNumber Digits $ BS.pack str <> "0")
121
119
@@ -125,9 +123,15 @@ main = hspec $ modifyMaxSuccess (* 10) $ do
125 prop "returns only ASCII digits" $ \(ParsedNumber _ pn) ->
123 prop "returns only ASCII digits" $ \(ParsedNumber _ pn) ->
126 BSC.all (`elem` ['0'..'9']) $ nationalSignificantNumber pn
124 BSC.all (`elem` ['0'..'9']) $ nationalSignificantNumber pn
127 modifyMaxDiscardRatio (* 10) $ do
125 modifyMaxDiscardRatio (* 10) $ do
128− prop "concatenated with country code parses to the original (if valid)" $
126+ prop "concatenated with country code parses to the original (if valid and not MX)" $
129− \(ParsedNumber _ pn) ->
127+ \(ParsedNumber (_, mReg, ParserInput input) pn) ->
128+ -- Apparently "+52112210000000" makes the parser/formatter do weird
129+ -- stuff as it tries to handle the deprecated (?) mobile token ("1"
130+ -- after "+52")
131+ if "5211" `BS.isPrefixOf` normalizeNumber Digits input ||
132+ mReg == Just "MX" && "11" `BS.isPrefixOf` normalizeNumber Digits input
133+ then discard
130− isValidNumber Nothing pn ==>
134+ else isValidNumber Nothing pn ==>
131 let
135 let
132 cc = countryCode pn
136 cc = countryCode pn
133 nsn = nationalSignificantNumber pn
137 nsn = nationalSignificantNumber pn
@@ -151,19 +155,14 @@ main = hspec $ modifyMaxSuccess (* 10) $ do
151 extension pn == Nothing ==>
155 extension pn == Nothing ==>
152 isRight $ parseNumber Canonicalize Nothing
156 isRight $ parseNumber Canonicalize Nothing
153 $ formatNumber International pn
157 $ formatNumber International pn
154− modifyMaxDiscardRatio (* 10) $ do
155− prop "with E164 produces a parseable result (if Canonicalize)" $
158+ prop "with E164 produces a parseable result" $
156− \(ParsedNumber (mode, _, _) pn) ->
157− -- KeepRawInput with pn == "0000" breaks E164 formatting
158− possibleNumber Unknown pn == IsPossible && mode == Canonicalize ==>
159+ \(ParsedNumber _ pn) -> possibleNumber Unknown pn == IsPossible ==>
159− isRight $ parseNumber Canonicalize Nothing
160+ isRight $ parseNumber Canonicalize Nothing
160− $ formatNumber E164 pn
161+ $ formatNumber E164 pn
161− prop "with RFC3966 produces a parseable result (if Canonicalize)" $
162+ prop "with RFC3966 produces a parseable result" $
162− \(ParsedNumber (mode, _, _) pn) ->
163− -- KeepRawInput with pn == "0000" breaks RFC3966 formatting
164− possibleNumber Unknown pn == IsPossible && mode == Canonicalize ==>
163+ \(ParsedNumber _ pn) -> possibleNumber Unknown pn == IsPossible ==>
165− isRight $ parseNumber Canonicalize Nothing
164+ isRight $ parseNumber Canonicalize Nothing
166− $ formatNumber RFC3966 pn
165+ $ formatNumber RFC3966 pn
167
166
168 describe "truncateTooLongNumber" $ do
167 describe "truncateTooLongNumber" $ do
169 pure ()
168 pure ()