@@ -198,12 +198,14 @@ class MergeSpringMetadataAction(
198198 logicalLines.add(current.toString())
199199 }
200200
201- return logicalLines.mapNotNull { line ->
202- val separatorIndex = line.indexOfFirst { it == ' = ' || it == ' : ' }
203- if (separatorIndex <= 0 ) {
204- null
201+ return logicalLines.map { line ->
202+ val separatorIndex = findSeparatorIndex( line)
203+ if (separatorIndex < 0 ) {
204+ line to " "
205205 } else {
206- line.substring(0 , separatorIndex).trim() to line.substring(separatorIndex + 1 ).trim()
206+ val keyEnd = trimTrailingWhitespace(line, separatorIndex)
207+ val valueStart = findValueStart(line, separatorIndex)
208+ line.substring(0 , keyEnd) to line.substring(valueStart).trim()
207209 }
208210 }
209211 }
@@ -221,4 +223,50 @@ class MergeSpringMetadataAction(
221223
222224 return backslashCount % 2 == 1
223225 }
226+
227+ private fun findSeparatorIndex (line : String ): Int {
228+ var backslashCount = 0
229+
230+ line.forEachIndexed { index, char ->
231+ if (char == ' \\ ' ) {
232+ backslashCount++
233+ } else {
234+ val isEscaped = backslashCount % 2 == 1
235+ if (! isEscaped && (char == ' =' || char == ' :' || char.isWhitespace())) {
236+ return index
237+ }
238+ backslashCount = 0
239+ }
240+ }
241+
242+ return - 1
243+ }
244+
245+ private fun trimTrailingWhitespace (line : String , endExclusive : Int ): Int {
246+ var end = endExclusive
247+
248+ while (end > 0 && line[end - 1 ].isWhitespace()) {
249+ end--
250+ }
251+
252+ return end
253+ }
254+
255+ private fun findValueStart (line : String , separatorIndex : Int ): Int {
256+ var valueStart = separatorIndex
257+
258+ while (valueStart < line.length && line[valueStart].isWhitespace()) {
259+ valueStart++
260+ }
261+
262+ if (valueStart < line.length && (line[valueStart] == ' =' || line[valueStart] == ' :' )) {
263+ valueStart++
264+ }
265+
266+ while (valueStart < line.length && line[valueStart].isWhitespace()) {
267+ valueStart++
268+ }
269+
270+ return valueStart
271+ }
224272}
0 commit comments