@@ -51,18 +51,46 @@ inline infix fun <T, R> T.with(function: T.() -> R) =
51
51
inline infix fun <T , R , K > T.withPair (function : T .() -> Pair <R , K >) =
52
52
function(this ).let { Triple (this , it.first, it.second) }
53
53
54
- internal val sanitizationRegex1 = Regex (" (<span )?style=.*>(\\ d*%)<.*;( |\\ .)" )
55
- internal val sanitizationRegex2 = Regex (" (<span )?style=.*>(\\ d{1,2}%) \\ ((\\ d{1,3}%)\\ ).*" )
56
- internal val sanitizationRegex3 = Regex (" \\ [\\ [.*\\ |(.*)\\ ]\\ ]" )
57
- internal val sanitizationRegex4 = Regex (" \\ [\\ [(.*)\\ ]\\ ]" )
58
- internal val sanitizationRegex5 = Regex (" "(.*)\\ ."" )
59
-
60
- fun String.sanitize () =
61
- replace(" '''" , " " )
62
- .replace(sanitizationRegex1, " $2 " )
63
- .replace(sanitizationRegex2, " $2 ($3)" )
64
- .replace(sanitizationRegex3, " $1" )
65
- .replace(sanitizationRegex4, " $1" )
66
- .replace(" <br>" , " " )
67
- .replace(" \n " , " " )
68
- .replace(sanitizationRegex5, " $1" )
54
+ internal val sanitizationRegexes = listOf (
55
+ Regex (" \\ [\\ [.*\\ |(.*)\\ ]\\ ]" ) to " $1" ,
56
+ Regex (" \\ [\\ [(.*)\\ ]\\ ]" ) to " $1" ,
57
+ Regex (" color:#(.{6});" ) to " " ,
58
+ Regex (" br([A-Z])" ) to " $1" ,
59
+ Regex (" \\ .(\\ w)" ) to " . $1" ,
60
+ Regex (" (\\ d)\\ . (\\ d)" ) to " $1.$2"
61
+ )
62
+
63
+ internal val sanitizationRemoves = listOf (
64
+ " <span " , " "" , " >" , " <" , " /span" , " brbr" ,
65
+ " style=" , " <br>" , " \n " , " ]]" , " [[" , " '''" , " font-weight:bold;"
66
+ )
67
+
68
+ internal val sanitizationSubstitutions = listOf (
69
+ " " to " " , " br/" to " . "
70
+ )
71
+
72
+ @JvmName(" replaceRegex" )
73
+ fun String.replace (values : Pair <Regex , String >) =
74
+ replace(values.first, values.second)
75
+
76
+ @JvmName(" replaceString" )
77
+ fun String.replace (values : Pair <String , String >) =
78
+ replace(values.first, values.second)
79
+
80
+ fun String.remove (chars : String ) =
81
+ replace(chars, " " )
82
+
83
+ fun String.sanitize (): String {
84
+ var me = this
85
+ sanitizationRegexes.forEach {
86
+ me = me.replace(it)
87
+ }
88
+ sanitizationRemoves.forEach {
89
+ me = me.remove(it)
90
+ }
91
+ sanitizationSubstitutions.forEach {
92
+ me = me.replace(it)
93
+ }
94
+ return me.replace(Regex (" br([A-Z])" ), " $1" )
95
+
96
+ }
0 commit comments