|
@@ -187,13 +187,26 @@ fun String.hide(hs: Char = '*', pre_len: Int = 2, suf_len: Int = 2, hs_max: Int?
|
|
|
val j_slen = this.length
|
|
|
if (j_slen <= pre_len + suf_len) return this
|
|
|
val j_midlen = j_slen - pre_len - suf_len
|
|
|
- val j_shide = CharArray(j_slen)
|
|
|
- for (j_i in 0 until pre_len) j_shide[j_i] = this[j_i]
|
|
|
+ val j_shide = CharArray(if (hs_max == null || j_midlen < hs_max) j_slen else (j_slen - j_midlen + hs_max))
|
|
|
+ var j_si = 0
|
|
|
+ while (j_si < pre_len) {
|
|
|
+ j_shide[j_si] = this[j_si]
|
|
|
+ j_si++
|
|
|
+ }
|
|
|
if (hs_max == null || j_midlen < hs_max) {
|
|
|
- for (j_i in pre_len until pre_len + j_midlen) j_shide[j_i] = hs
|
|
|
+ for (j_i in 0..<j_midlen) {
|
|
|
+ j_shide[j_si] = hs
|
|
|
+ j_si++
|
|
|
+ }
|
|
|
} else {
|
|
|
- for (j_i in pre_len until pre_len + hs_max) j_shide[j_i] = hs
|
|
|
+ for (j_i in 0..<hs_max) {
|
|
|
+ j_shide[j_si] = hs
|
|
|
+ j_si++
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (j_i in j_slen - suf_len until j_slen) {
|
|
|
+ j_shide[j_si] = this[j_i]
|
|
|
+ j_si++
|
|
|
}
|
|
|
- for (j_i in j_slen - suf_len until j_slen) j_shide[j_i] = this[j_i]
|
|
|
return String(j_shide)
|
|
|
}
|