Skip to content

Commit e4bb23f

Browse files
committed
preserve order of inline tags in RUL2
1 parent 9624bdd commit e4bb23f

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/main/scala/module/Rul2Checker.scala

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,22 @@ object Rul2Checker {
104104
class Result(val numFailures: Int, val removed: Int, val added: Int)
105105

106106
def replaceTags(line: String, add: Option[String], remove: Seq[String]): String = {
107-
val line0 =
108-
remove.foldLeft(line.stripLineEnd) { (line, rem) =>
109-
line.replaceFirst(s" ?\\b$rem\\b", "").replaceFirst(";\\s*$", "")
107+
var line0: String = line.stripLineEnd
108+
var start = -1
109+
for (rem <- remove) {
110+
val p = java.util.regex.Pattern.compile(s"; ?\\b$rem\\b;?")
111+
val m = p.matcher(line0)
112+
if (m.find()) {
113+
start = m.start
114+
line0 = m.replaceFirst(";")
110115
}
111-
if (add.isDefined) s"$line0; ${add.get}" else line0
116+
}
117+
if (start != -1) {
118+
line0 = line0.replaceFirst(";\\s*$", "")
119+
}
120+
121+
if (!add.isDefined) line0
122+
else if (start == -1 || start >= line0.length) s"$line0; ${add.get}"
123+
else s"${line0.substring(0, start)}; ${add.get}${line0.substring(start)}"
112124
}
113125
}

0 commit comments

Comments
 (0)