Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ext/intl/locale/locale.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,9 @@ public static function canonicalize(string $locale): ?string {}
* @alias locale_accept_from_http
*/
public static function acceptFromHttp(string $header): string|false {}

/**
* @alias locale_is_right_to_left
*/
public static function isRightToLeft(string $locale): bool {}
}
8 changes: 7 additions & 1 deletion ext/intl/locale/locale_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions ext/intl/locale/locale_methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -1619,3 +1619,19 @@ PHP_FUNCTION(locale_accept_from_http)
RETURN_STRINGL(resultLocale, len);
}
/* }}} */

PHP_FUNCTION(locale_is_right_to_left)
{
char *locale;
size_t locale_len;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(locale, locale_len)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Seems like this could be PATH_STRING because NULL bytes are treated as the end of the string.
Although it seems this is not done in this file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that s something I planned to revisit separately, the whole bunch.

ZEND_PARSE_PARAMETERS_END();

if (!locale_len) {
locale = (char *)intl_locale_get_default();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about make the argument nullable and have this behavior when it's null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is mostly about consistency, end users expect the same behaviour throughout (e.g. see here or here).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, understand.
thanks!

}

RETURN_BOOL(uloc_isRightToLeft((const char *)locale));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: you don't need the cast to const char*, this will happen implicitly

}
2 changes: 2 additions & 0 deletions ext/intl/php_intl.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ function locale_lookup(array $languageTag, string $locale, bool $canonicalize =

function locale_accept_from_http(string $header): string|false {}

function locale_is_right_to_left(string $locale): bool {}

/* msgformat */

function msgfmt_create(string $locale, string $pattern): ?MessageFormatter {}
Expand Down
8 changes: 7 additions & 1 deletion ext/intl/php_intl_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions ext/intl/tests/locale_is_right_to_left.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
locale_is_right_to_left
--EXTENSIONS--
intl
--FILE--
<?php
var_dump(Locale::isRightToLeft("en-US"));
var_dump(Locale::isRightToLeft("\INVALID\\"));
var_dump(Locale::isRightToLeft(""));
var_dump(Locale::isRightToLeft("ar"));
?>
--EXPECT--
bool(false)
bool(false)
bool(false)
bool(true)
Loading