@@ -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 ;
@@ -300,7 +302,7 @@ ldml_processor::process_event(
300302 ctxtstr.pop_back ();
301303 ctxtstr.pop_back ();
302304 ctxtstr.pop_back ();
303- // push a special backsapce to delete the marker
305+ // push a special backspace to delete the marker
304306 state->actions ().push_backspace (KM_KBP_BT_MARKER, c->marker );
305307 }
306308 }
@@ -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 &) {
@@ -399,7 +400,6 @@ ldml_processor::context_to_string(km_kbp_state *state, std::u32string &str) {
399400 str.clear ();
400401 auto &cp = state->context ();
401402 size_t ctxlen = 0 ; // TODO-LDML: is this needed?
402- // We're only interested in as much of the context as is a KM_KBP_BT_CHAR.
403403 uint8_t last_type = KM_KBP_BT_UNKNOWN;
404404 for (auto c = cp.rbegin (); c != cp.rend (); c++, ctxlen++) {
405405 last_type = c->type ;
0 commit comments