Open-source multiplayer game server compatible with the RuneScape client
https://www.openrs2.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.2 KiB
49 lines
1.2 KiB
4 years ago
|
package org.openrs2.asm.filter
|
||
4 years ago
|
|
||
4 years ago
|
public object Glob {
|
||
|
public fun compile(pattern: String): Regex {
|
||
4 years ago
|
return compile(pattern, className = false)
|
||
|
}
|
||
|
|
||
4 years ago
|
public fun compileClass(pattern: String): Regex {
|
||
4 years ago
|
return compile(pattern, className = true)
|
||
|
}
|
||
|
|
||
|
private fun compile(pattern: String, className: Boolean): Regex {
|
||
|
val regex = StringBuilder()
|
||
|
var star = false
|
||
|
|
||
|
for (ch in pattern) {
|
||
|
if (star) {
|
||
|
star = false
|
||
|
|
||
|
if (ch == '*') {
|
||
|
regex.append(".*")
|
||
|
continue
|
||
|
}
|
||
|
|
||
4 years ago
|
/*
|
||
|
* The deobfuscator uses ! in class names to separate the
|
||
|
* library name from the rest of the package/class name.
|
||
|
*/
|
||
|
regex.append("[^/!]*")
|
||
4 years ago
|
}
|
||
|
|
||
|
when (ch) {
|
||
|
'*' -> if (className) {
|
||
|
star = true
|
||
|
} else {
|
||
|
regex.append(".*")
|
||
|
}
|
||
|
else -> regex.append(Regex.escape(ch.toString()))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (star) {
|
||
|
regex.append(".*")
|
||
|
}
|
||
|
|
||
|
return Regex(regex.toString())
|
||
|
}
|
||
|
}
|