blob: b38721e56a97bb3a1060ca25406859b07d058f34 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
package xyz.driver.pdsuicommon.utils
import xyz.driver.pdsuicommon.utils.Implicits.toCharOps
final class StringOps(val self: String) extends AnyVal {
def safeTrim: String = {
def shouldKeep(c: Char): Boolean = !c.isSafeControl && !c.isSafeWhitespace
if (self.isEmpty) {
""
} else {
val start = self.indexWhere(shouldKeep)
val end = self.lastIndexWhere(shouldKeep)
if (start >= 0 && end >= 0) {
self.substring(start, end + 1)
} else {
""
}
}
}
}
|