@@ -14,26 +14,34 @@ object FixInvalidDayOffsetPreprocessor : StreamPreprocessor() {
1414 // Examples:
1515 // TRIGGER:-P2DT
1616 // TRIGGER:-PT2D
17- // REFRESH-INTERVAL;VALUE=DURATION:PT1D
18- " (?:^|(^( DURATION|REFRESH-INTERVAL|RELATED-TO|TRIGGER)) ;VALUE=)(DURATION|TRIGGER):-?P((T-?\\ d+D)|(-?\\ d+DT))\ $" ,
17+ // REFRESH-INTERVAL;VALUE=DURATION:- PT1D
18+ " (?:^|^(?: DURATION|REFRESH-INTERVAL|RELATED-TO|TRIGGER);VALUE=)(?: DURATION|TRIGGER):( -?P((T-?\\ d+D)|(-?\\ d+DT))) $" ,
1919 setOf (RegexOption .MULTILINE , RegexOption .IGNORE_CASE )
2020 )
2121
2222 override fun fixString (original : String ): String {
23- var s : String = original
23+ var iCal : String = original
2424
2525 // Find all instances matching the defined expression
26- val found = regexpForProblem().findAll(s )
26+ val found = regexpForProblem().findAll(iCal )
2727
2828 // ..and repair them
2929 for (match in found) {
30- val matchStr = match.value
31- val fixed = matchStr
30+ // Fix the duration string
31+ val faultyDuration = match.groupValues[1 ] // IE: "-PT1D" (faulty)
32+ val fixedDuration = faultyDuration // IE: "-P1D" (fixed)
3233 .replace(" PT" , " P" )
3334 .replace(" DT" , " D" )
34- s = s.replace(matchStr, fixed)
35+
36+ // Replace the faulty duration with the fixed one in the captured line
37+ val faultyCapture = match.value // IE: "REFRESH-INTERVAL;VALUE=DURATION:-PT1D" (faulty)
38+ val fixedCapture = faultyCapture // IE: "REFRESH-INTERVAL;VALUE=DURATION:-P1D" (fixed)
39+ .replace(faultyDuration, fixedDuration)
40+
41+ // Replace complete faulty line in the iCal string with the fixed one
42+ iCal = iCal.replace(faultyCapture, fixedCapture)
3543 }
36- return s
44+ return iCal
3745 }
3846
3947}
0 commit comments