From 08178ed2315790a73f1b6353ae4b0ad94fe7b532 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Apr 2018 12:53:24 +0200 Subject: [PATCH] Use recommended options for explicit UnicodeString constructors --- acinclude.m4 | 3 +++ ext/intl/config.w32 | 2 +- ext/intl/msgformat/msgformat_helpers.cpp | 16 +++++++++------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 4e5f055272..89910930bd 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -2239,6 +2239,9 @@ AC_DEFUN([PHP_SETUP_ICU],[ PHP_EVAL_LIBLINE($ICU_LIBS, $1) ICU_EXTRA_FLAGS=`$ICU_CONFIG --cxxflags` + if test "$icu_version" -lt "49000"; then + ICU_EXTRA_FLAGS="$ICU_EXTRA_FLAGS -DUNISTR_FROM_CHAR_EXPLICIT=explicit -DUNISTR_FROM_STRING_EXPLICIT=explicit" + fi fi ]) diff --git a/ext/intl/config.w32 b/ext/intl/config.w32 index 2aa408fac0..1f527dc7da 100644 --- a/ext/intl/config.w32 +++ b/ext/intl/config.w32 @@ -129,7 +129,7 @@ if (PHP_INTL != "no") { ADD_FLAG("LIBS_INTL", "iculx.lib"); } - ADD_FLAG("CFLAGS_INTL", "/EHsc"); + ADD_FLAG("CFLAGS_INTL", "/EHsc /DUNISTR_FROM_CHAR_EXPLICIT=explicit /DUNISTR_FROM_STRING_EXPLICIT=explicit"); AC_DEFINE("HAVE_INTL", 1, "Internationalization support enabled"); } else { WARNING("intl not enabled; libraries and/or headers not found"); diff --git a/ext/intl/msgformat/msgformat_helpers.cpp b/ext/intl/msgformat/msgformat_helpers.cpp index 287139bb93..90d60acbd2 100644 --- a/ext/intl/msgformat/msgformat_helpers.cpp +++ b/ext/intl/msgformat/msgformat_helpers.cpp @@ -237,15 +237,16 @@ static HashTable *umsg_parse_format(MessageFormatter_object *mfo, UnicodeString typeString = mp.getSubstring(type_part); /* This is all based on the rules in the docs for MessageFormat * @see http://icu-project.org/apiref/icu4c/classMessageFormat.html */ - if (typeString == "number") { +#define ASCII_LITERAL(s) UNICODE_STRING(s, sizeof(s)-1) + if (typeString == ASCII_LITERAL("number")) { MessagePattern::Part style_part = mp.getPart(i + 1); /* Not advancing i */ if (style_part.getType() == UMSGPAT_PART_TYPE_ARG_STYLE) { UnicodeString styleString = mp.getSubstring(style_part); - if (styleString == "integer") { + if (styleString == ASCII_LITERAL("integer")) { type = Formattable::kInt64; - } else if (styleString == "currency") { + } else if (styleString == ASCII_LITERAL("currency")) { type = Formattable::kDouble; - } else if (styleString == "percent") { + } else if (styleString == ASCII_LITERAL("percent")) { type = Formattable::kDouble; } else { /* some style invalid/unknown to us */ type = Formattable::kDouble; @@ -253,12 +254,13 @@ static HashTable *umsg_parse_format(MessageFormatter_object *mfo, } else { // if missing style, part, make it a double type = Formattable::kDouble; } - } else if ((typeString == "date") || (typeString == "time")) { + } else if ((typeString == ASCII_LITERAL("date")) || (typeString == ASCII_LITERAL("time"))) { type = Formattable::kDate; - } else if ((typeString == "spellout") || (typeString == "ordinal") - || (typeString == "duration")) { + } else if ((typeString == ASCII_LITERAL("spellout")) || (typeString == ASCII_LITERAL("ordinal")) + || (typeString == ASCII_LITERAL("duration"))) { type = Formattable::kDouble; } +#undef ASCII_LITERAL } else { /* If there's no UMSGPAT_PART_TYPE_ARG_TYPE right after a * UMSGPAT_ARG_TYPE_SIMPLE argument, then the pattern -- 2.40.0