From 6bed2de9752d83ce30ce4317eac788015bfe85e7 Mon Sep 17 00:00:00 2001 From: varunghat Date: Mon, 10 Aug 2026 18:36:58 +0200 Subject: [PATCH] Fix malformed MD-swap block accidentally merged in #387 --- scripts/aggregation-helper-functions.R | 30 +++++++++++--------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/scripts/aggregation-helper-functions.R b/scripts/aggregation-helper-functions.R index ddf767d..27ea2c2 100644 --- a/scripts/aggregation-helper-functions.R +++ b/scripts/aggregation-helper-functions.R @@ -299,23 +299,19 @@ order_ipa <- function(strings, keep_stars=FALSE, keep_brackets=TRUE) { } ## If a diacritic comes right after a modifier letter, swap their order if (stri_detect_fixed(typestring, "MD")) { - ixs <- stri_locate_all_fixed(typestring, "MD")[[1]] - for (row in seq_len(dim(ixs)[1])) { - ix <- ixs[row, 1] - if (string[ix] %in% clicks) next - # SWAP LOGIC REMAINS SAME - } } - - ix <- stri_locate_first_fixed(typestring, "MD")[1] - # If the modifier letter is a click, don't swap it with the diacritic - if (string[ix] %in% clicks) break - if (ix == 1) neworder <- c(2, 1, 3:lenstr) - else if (ix == lenstr-1) neworder <- c(1:(ix-1), ix+1, ix) - else neworder <- c(1:(ix-1), ix+1, ix, (ix+2):lenstr) - string <- string[neworder] - typstr <- typstr[neworder] - typestring <- paste(typstr, collapse="") - } + ixs <- stri_locate_all_fixed(typestring, "MD")[[1]] + # Iterate through the rows of the matrix of indices, swapping modifier and diacritic. + for (row in seq_len(dim(ixs)[1])) { + ix <- ixs[row, 1] + # If the modifier letter is a click, don't swap it with the diacritic + if (string[ix] %in% clicks) next + if (ix == 1) neworder <- c(2, 1, 3:lenstr) + else if (ix == lenstr-1) neworder <- c(1:(ix-1), ix+1, ix) + else neworder <- c(1:(ix-1), ix+1, ix, (ix+2):lenstr) + string <- string[neworder] + typstr <- typstr[neworder] + typestring <- paste(typstr, collapse="") + } } ## Put sequences of modifier letters in canonical order if (stri_detect_fixed(typestring, "MM")) { ixs <- stri_locate_all_regex(typestring, "M+")[[1]]