@@ -285,7 +285,7 @@ static bool hasStringOption(const FunctionOptionsMap& opt,
285285LocalPointer<FunctionValue> PersonNameFunction::call (const FunctionContext& context,
286286 const FunctionValue& arg,
287287 const FunctionOptions& opts,
288- UErrorCode& errorCode) {
288+ UErrorCode& errorCode) const {
289289 (void ) context;
290290
291291 if (U_FAILURE (errorCode)) {
@@ -404,7 +404,7 @@ LocalPointer<FunctionValue>
404404GrammarCasesFunction::call (const FunctionContext& context,
405405 const FunctionValue& arg,
406406 const FunctionOptions& opts,
407- UErrorCode& errorCode) {
407+ UErrorCode& errorCode) const {
408408 (void ) context;
409409
410410 if (U_FAILURE (errorCode)) {
@@ -535,7 +535,7 @@ LocalPointer<FunctionValue>
535535ListFunction::call (const FunctionContext& context,
536536 const FunctionValue& arg,
537537 const FunctionOptions& opts,
538- UErrorCode& errorCode) {
538+ UErrorCode& errorCode) const {
539539 if (U_FAILURE (errorCode)) {
540540 return LocalPointer<FunctionValue>();
541541 }
@@ -711,7 +711,7 @@ LocalPointer<FunctionValue>
711711ResourceManager::call (const FunctionContext&,
712712 const FunctionValue& arg,
713713 const FunctionOptions& options,
714- UErrorCode& errorCode) {
714+ UErrorCode& errorCode) const {
715715 if (U_FAILURE (errorCode)) {
716716 return LocalPointer<FunctionValue>();
717717 }
@@ -878,7 +878,7 @@ LocalPointer<FunctionValue>
878878NounFunction::call (const FunctionContext&,
879879 const FunctionValue& arg,
880880 const FunctionOptions& opts,
881- UErrorCode& errorCode) {
881+ UErrorCode& errorCode) const {
882882 if (U_FAILURE (errorCode)) {
883883 return LocalPointer<FunctionValue>();
884884 }
@@ -938,7 +938,7 @@ LocalPointer<FunctionValue>
938938AdjectiveFunction::call (const FunctionContext&,
939939 const FunctionValue& arg,
940940 const FunctionOptions& opts,
941- UErrorCode& errorCode) {
941+ UErrorCode& errorCode) const {
942942 if (U_FAILURE (errorCode)) {
943943 return LocalPointer<FunctionValue>();
944944 }
@@ -1014,7 +1014,7 @@ void TestMessageFormat2::testSingleEvaluation(IcuTestErrorCode& errorCode) {
10141014
10151015 MFFunctionRegistry customRegistry (MFFunctionRegistry::Builder (errorCode)
10161016 .adoptFunction (FunctionName (" counter" ),
1017- new CounterFunction (),
1017+ new CounterFunction (errorCode ),
10181018 errorCode)
10191019 .build ());
10201020 UnicodeString name = " name" ;
@@ -1032,25 +1032,33 @@ void TestMessageFormat2::testSingleEvaluation(IcuTestErrorCode& errorCode) {
10321032 TestUtils::runTestCase (*this , test, errorCode);
10331033}
10341034
1035+ CounterFunction::CounterFunction (UErrorCode& errorCode) {
1036+ if (U_FAILURE (errorCode)) {
1037+ return ;
1038+ }
1039+ Counter* c = new Counter ();
1040+ count = LocalPointer (c, errorCode);
1041+ }
1042+
10351043LocalPointer<FunctionValue>
10361044CounterFunction::call (const FunctionContext&,
10371045 const FunctionValue& arg,
10381046 const FunctionOptions& opts,
1039- UErrorCode& errorCode) {
1047+ UErrorCode& errorCode) const {
10401048 if (U_FAILURE (errorCode)) {
10411049 return LocalPointer<FunctionValue>();
10421050 }
10431051
10441052 LocalPointer<FunctionValue>
1045- v (new CounterFunctionValue (count, arg, std::move (opts), errorCode));
1053+ v (new CounterFunctionValue (count. getAlias () , arg, std::move (opts), errorCode));
10461054 if (!v.isValid ()) {
10471055 errorCode = U_MEMORY_ALLOCATION_ERROR ;
10481056 }
1049- count++ ;
1057+ count-> increment () ;
10501058 return v;
10511059}
10521060
1053- CounterFunctionValue::CounterFunctionValue (int32_t & c,
1061+ CounterFunctionValue::CounterFunctionValue (Counter* c,
10541062 const FunctionValue&,
10551063 const FunctionOptions&,
10561064 UErrorCode&) : count(c) {
@@ -1062,7 +1070,7 @@ UnicodeString CounterFunctionValue::formatToString(UErrorCode& status) const {
10621070 return {};
10631071 }
10641072 number::UnlocalizedNumberFormatter nf = number::NumberFormatter::with ();
1065- number::FormattedNumber formattedNumber = nf.locale (" en-US" ).formatInt (count, status);
1073+ number::FormattedNumber formattedNumber = nf.locale (" en-US" ).formatInt (count-> get () , status);
10661074 return formattedNumber.toString (status);
10671075}
10681076
0 commit comments