Skip to content

intl extension, follow up on #10006 for numfmt_set_pattern #10073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 9 additions & 3 deletions ext/intl/formatter/formatter_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ PHP_FUNCTION( numfmt_set_pattern )
size_t value_len = 0;
int32_t slength = 0;
UChar* svalue = NULL;
UParseError spattern_error = {0};
FORMATTER_METHOD_INIT_VARS;

/* Parse parameters. */
Expand All @@ -347,12 +348,17 @@ PHP_FUNCTION( numfmt_set_pattern )
intl_convert_utf8_to_utf16(&svalue, &slength, value, value_len, &INTL_DATA_ERROR_CODE(nfo));
INTL_METHOD_CHECK_STATUS( nfo, "Error converting pattern to UTF-16" );

/* TODO: add parse error information */
unum_applyPattern(FORMATTER_OBJECT(nfo), 0, svalue, slength, NULL, &INTL_DATA_ERROR_CODE(nfo));
unum_applyPattern(FORMATTER_OBJECT(nfo), 0, svalue, slength, &spattern_error, &INTL_DATA_ERROR_CODE(nfo));
if (svalue) {
efree(svalue);
}
INTL_METHOD_CHECK_STATUS( nfo, "Error setting pattern value" );
if (U_FAILURE(INTL_DATA_ERROR_CODE(nfo))) {
char *msg;
spprintf(&msg, 0, "Error setting pattern value at line %d, offset %d", spattern_error.line, spattern_error.offset);
intl_errors_set_custom_msg(INTL_DATA_ERROR_P(nfo), msg, 1);
efree(msg);
RETURN_FALSE;
}

RETURN_TRUE;
}
Expand Down
5 changes: 5 additions & 0 deletions ext/intl/tests/formatter_get_set_pattern2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ function ut_main()
ut_nfmt_set_pattern($fmt, str_repeat('@', 200));
$res_str .= "New pattern: '" . ut_nfmt_get_pattern( $fmt ) . "'\n";
$res_str .= "Formatted number: " . ut_nfmt_format( $fmt, $test_value ) . "\n";
$res = ut_nfmt_set_pattern( $fmt, "0.0 .#.#.#");
if ($res !== false)
die("ut_nfmt_set_pattern should have failed");
$res_str .= ut_nfmt_get_error_message( $fmt ) . " (" . ut_nfmt_get_error_code( $fmt ) . ")\n";

return $res_str;
}
Expand All @@ -52,3 +56,4 @@ New pattern: '0.0'
Formatted number: 12345.1
New pattern: '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
Formatted number: 12345.123456000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Error setting pattern value at line 0, offset 0: U_UNQUOTED_SPECIAL (65555)