Skip to content

Commit 6ef4a87

Browse files
BogdanUngureanudevnexen
authored andcommitted
ext/intl: Add IntlNumberRangeFormatter class.
to format an interval of two numbers with a given skeleton, locale, collapse type and identity fallback close GH-19232
1 parent 65b9306 commit 6ef4a87

15 files changed

+1214
-0
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.6.0alpha1
44

5+
- Intl:
6+
. Added IntlNumberRangeFormatter class to format an interval of two numbers
7+
with a given skeleton, locale, collapse type and identity fallback.
8+
(BogdanUngureanu)
9+
510
<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>

UPGRADING

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ PHP 8.6 UPGRADE NOTES
2323
2. New Features
2424
========================================
2525

26+
- Intl:
27+
. Added IntlNumberRangeFormatter class to format an interval of two numbers with a given skeleton, locale, IntlNumberRangeFormatter::COLLAPSE_AUTO, IntlNumberRangeFormatter::COLLAPSE_NONE, IntlNumberRangeFormatter::COLLAPSE_UNIT, IntlNumberRangeFormatter::COLLAPSE_ALL collapse and
28+
IntlNumberRangeFormatter::IDENTITY_FALLBACK_SINGLE_VALUE, IntlNumberRangeFormatter::IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE, IntlNumberRangeFormatter::IDENTITY_FALLBACK_APPROXIMATELY and
29+
IntlNumberRangeFormatter::IDENTITY_FALLBACK_RANGE identity fallbacks.
30+
It is supported from icu 63.
2631
========================================
2732
3. Changes in SAPI modules
2833
========================================

ext/intl/config.m4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ if test "$PHP_INTL" != "no"; then
6060
dateformat/datepatterngenerator_class.cpp \
6161
dateformat/datepatterngenerator_methods.cpp \
6262
msgformat/msgformat_helpers.cpp \
63+
rangeformatter/rangeformatter_class.cpp \
6364
timezone/timezone_class.cpp \
6465
timezone/timezone_methods.cpp \
6566
calendar/calendar_class.cpp \
@@ -123,6 +124,7 @@ if test "$PHP_INTL" != "no"; then
123124
$ext_builddir/listformatter
124125
$ext_builddir/msgformat
125126
$ext_builddir/normalizer
127+
$ext_builddir/rangeformatter
126128
$ext_builddir/resourcebundle
127129
$ext_builddir/spoofchecker
128130
$ext_builddir/timezone

ext/intl/config.w32

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ if (PHP_INTL != "no") {
6363
normalizer_class.cpp \
6464
normalizer_normalize.cpp \
6565
", "intl");
66+
ADD_SOURCES(configure_module_dirname + "/rangeformatter", "\
67+
rangeformatter_class.cpp \
68+
", "intl");
6669
ADD_SOURCES(configure_module_dirname + "/dateformat", "\
6770
dateformat.c \
6871
dateformat_class.c \

ext/intl/php_intl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "locale/locale_class.h"
4343

4444
#include "listformatter/listformatter_class.h"
45+
#include "rangeformatter/rangeformatter_class.h"
4546

4647
#include "dateformat/dateformat.h"
4748
#include "dateformat/dateformat_class.h"
@@ -189,6 +190,9 @@ PHP_MINIT_FUNCTION( intl )
189190
/* Register 'ListFormatter' PHP class */
190191
listformatter_register_class( );
191192

193+
/* Register 'NumberRangeFormatter' PHP class */
194+
rangeformatter_register_class( );
195+
192196
/* Register 'Normalizer' PHP class */
193197
normalizer_register_Normalizer_class( );
194198

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/** @generate-class-entries */
4+
5+
/**
6+
* @not-serializable
7+
* @strict-properties
8+
*/
9+
final class IntlNumberRangeFormatter {
10+
#if U_ICU_VERSION_MAJOR_NUM >= 63
11+
/** @cvalue UNUM_RANGE_COLLAPSE_AUTO */
12+
public const int COLLAPSE_AUTO = UNKNOWN;
13+
14+
/** @cvalue UNUM_RANGE_COLLAPSE_NONE */
15+
public const int COLLAPSE_NONE = UNKNOWN;
16+
17+
/** @cvalue UNUM_RANGE_COLLAPSE_UNIT */
18+
public const int COLLAPSE_UNIT = UNKNOWN;
19+
20+
/** @cvalue UNUM_RANGE_COLLAPSE_ALL */
21+
public const int COLLAPSE_ALL = UNKNOWN;
22+
23+
/** @cvalue UNUM_IDENTITY_FALLBACK_SINGLE_VALUE */
24+
public const int IDENTITY_FALLBACK_SINGLE_VALUE = UNKNOWN;
25+
26+
/** @cvalue UNUM_IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE */
27+
public const int IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE = UNKNOWN;
28+
29+
/** @cvalue UNUM_IDENTITY_FALLBACK_APPROXIMATELY */
30+
public const int IDENTITY_FALLBACK_APPROXIMATELY = UNKNOWN;
31+
32+
/** @cvalue UNUM_IDENTITY_FALLBACK_RANGE */
33+
public const int IDENTITY_FALLBACK_RANGE = UNKNOWN;
34+
#else
35+
public const int COLLAPSE_AUTO = 0;
36+
37+
public const int COLLAPSE_NONE = 1;
38+
39+
public const int COLLAPSE_UNIT = 2;
40+
41+
public const int COLLAPSE_ALL = 3;
42+
43+
public const int IDENTITY_FALLBACK_SINGLE_VALUE = 0;
44+
45+
public const int IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE = 1;
46+
47+
public const int IDENTITY_FALLBACK_APPROXIMATELY = 2;
48+
49+
public const int IDENTITY_FALLBACK_RANGE = 3;
50+
#endif
51+
52+
private function __construct() {}
53+
54+
public static function createFromSkeleton(string $skeleton, string $locale, int $collapse, int $identityFallback): IntlNumberRangeFormatter {}
55+
56+
public function format(float|int $start, float|int $end): string {}
57+
58+
public function getErrorCode(): int {}
59+
60+
public function getErrorMessage(): string {}
61+
}

ext/intl/rangeformatter/rangeformatter_arginfo.h

Lines changed: 148 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)