@@ -245,24 +245,22 @@ ldml_processor::process_event(
245245 break ; // ----- commit and exit
246246 }
247247
248- /* *
249- * a copy of the current/changed context, for transform use.
250- *
251- */
252- std::u32string ctxtstr;
253-
254- if (!!transforms) {
255- (void )context_to_string (state, ctxtstr);
256- } // else, don't bother populating
257-
258248 // found a string - push it into the context and actions
259249 // we convert it here instead of using the emit_text() overload
260250 // so that we don't have to reconvert it inside the transform code.
261251 const std::u32string str32 = kmx::u16string_to_u32string (str);
262- emit_text (state, str32);
263252
264- // Now, process the actual transforms
265- if (!!transforms) {
253+ if (!transforms) {
254+ // No transforms: just emit the string.
255+ emit_text (state, str32);
256+ } else {
257+ // Process transforms here
258+ /* *
259+ * a copy of the current/changed context, for transform use.
260+ *
261+ */
262+ std::u32string ctxtstr;
263+ (void )context_to_string (state, ctxtstr);
266264 // add the newly added key output to ctxtstr
267265 ctxtstr.append (str32);
268266
@@ -272,11 +270,15 @@ ldml_processor::process_event(
272270 // apply the transform, get how much matched (at the end)
273271 const size_t matchedContext = transforms->apply (ctxtstr, outputString);
274272
275- if (matchedContext > 0 ) {
273+ if (matchedContext == 0 ) {
274+ // No match, just emit the original string
275+ emit_text (state, str32);
276+ } else {
276277 // We have a match.
277278
279+ ctxtstr.resize (ctxtstr.length () - str32.length ());
278280 /* * how many chars of the context we need to clear */
279- auto charsToDelete = matchedContext;
281+ auto charsToDelete = matchedContext - str32. length (); /* we don't need to clear the output of the current key */
280282
281283 /* * how many context items need to be removed */
282284 size_t contextRemoved = 0 ;
@@ -314,11 +316,10 @@ ldml_processor::process_event(
314316 // If we needed it further. we could update ctxtstr here:
315317 // ctxtstr.append(outputString);
316318 // ... but it is no longer needed at this point.
317- }
318- // else: no match
319- }
320- }
321- }
319+ } // end of transform match
320+ } // end of processing transforms
321+ } // end of processing a 'normal' vk
322+ } // end of switch
322323 // end of normal processing: commit and exit
323324 state->actions ().commit ();
324325 } catch (std::bad_alloc &) {
0 commit comments