File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments