diff src/main/kotlin/name/blackcap/passman/See.kt @ 4:02b101422726

See bugs.
author David Barts <n5jrn@me.com>
date Sun, 11 Sep 2022 20:44:59 -0700
parents eafa3779aef8
children ad997df1f560
line wrap: on
line diff
--- a/src/main/kotlin/name/blackcap/passman/See.kt	Sun Sep 11 20:36:06 2022 -0700
+++ b/src/main/kotlin/name/blackcap/passman/See.kt	Sun Sep 11 20:44:59 2022 -0700
@@ -7,14 +7,15 @@
 import java.util.Formatter
 
 private const val DELIM = '"'
+private const val SHY = '\u00ad'
 
 private val STD_ESC_MAP = mapOf<Char, Char>('\t' to 't', '\b' to 'b', '\n' to 'n',
-    '\r' to 'r', '\u000c' to 'f', '\"' to '"', '\\' to '\\')
+    '\r' to 'r', '\u000c' to 'f', '"' to '"', '\\' to '\\')
+private val BANNED = setOf<Char>(DELIM, SHY, '\\')
 private const val MIN_ASCII = ' '
 private const val MAX_ASCII = '~'
 private const val MIN_8859 = '\u00a1'
 private const val MAX_8859 = '\u00ff'
-private const val SHY = '\u00ad'
 
 fun see(input: String, simple: Boolean = false): String =
     if (simple) seeSimple(input) else seeAggressive(input)
@@ -30,7 +31,7 @@
     val accum = Formatter()
     accum.format("%c", DELIM)
     for (ch in input) {
-        if ((ch in MIN_ASCII..MAX_ASCII) || ((ch != SHY) && (ch in MIN_8859 .. MAX_8859))) {
+        if ((ch !in BANNED) && ((ch in MIN_ASCII..MAX_ASCII) || (ch in MIN_8859 .. MAX_8859))) {
             accum.format("%c", ch)
             continue
         }