/
Reports.kt
54 lines (43 loc) · 1.5 KB
/
Reports.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.kover.engines.commons
import kotlinx.kover.api.*
import java.io.File
import java.math.BigDecimal
internal class ReportVerificationRule(
val id: Int,
val name: String?,
val target: VerificationTarget,
val filters: KoverClassFilter?,
val bounds: List<ReportVerificationBound>
)
internal class ReportVerificationBound(
val id: Int,
val minValue: BigDecimal?,
val maxValue: BigDecimal?,
val metric: CounterType,
val valueType: VerificationValueType
)
private val regexMetacharactersSet = "<([{\\^-=$!|]})+.>".toSet()
internal fun String.wildcardsToClassFileRegex(): String {
val filenameWithWildcards = "*" + File.separatorChar + this.replace('.', File.separatorChar) + ".class"
return filenameWithWildcards.wildcardsToRegex()
}
/**
* Replaces characters `*` or `.` to `.*` and `.` regexp characters.
*/
internal fun String.wildcardsToRegex(): String {
// in most cases, the characters `*` or `.` will be present therefore, we increase the capacity in advance
val builder = StringBuilder(length * 2)
forEach { char ->
when (char) {
in regexMetacharactersSet -> builder.append('\\').append(char)
'*' -> builder.append('.').append("*")
'?' -> builder.append('.')
else -> builder.append(char)
}
}
return builder.toString()
}
internal val ONE_HUNDRED = 100.toBigDecimal()