# HG changeset patch # User David Barts # Date 1719811732 25200 # Node ID 4391afcf6bd0c933d86900fb28a30e44bd8dacd7 # Parent 7d80cbcb67bb06bfbdb1771771a8b67f2a76fa50 Fix more bugs, correct more bad tests. diff -r 7d80cbcb67bb -r 4391afcf6bd0 src/main/kotlin/name/blackcap/passman/Shplitter.kt --- a/src/main/kotlin/name/blackcap/passman/Shplitter.kt Sun Jun 30 20:37:36 2024 -0700 +++ b/src/main/kotlin/name/blackcap/passman/Shplitter.kt Sun Jun 30 22:28:52 2024 -0700 @@ -31,13 +31,11 @@ fun split(): Iterable { if (complete) { - if (current.isNotEmpty()) { + if (state == ::nonspace) { + popState() accum.add(current.toString()) current.clear() } - if (state == ::nonspace) { - popState() - } return accum } else { throw IllegalStateException("incomplete quoted expression") @@ -57,14 +55,6 @@ private fun lastState(): State = oldStates.last() - private fun endQuote(): Unit { - if (lastState() == ::space) { - accum.add(current.toString()) - current.clear() - } - popState() - } - // States. A state is represented by a function that accepts the // character currently being processed, and returns whether it should // immediately transition to the next state without reading a new @@ -73,9 +63,9 @@ private fun space(ch: Char): Boolean = when (ch) { in WHITESPACE -> { false } - '\'' -> { pushState(::inSingle); false } - '"' -> { pushState(::inDouble); false } - '\\' -> { pushState(::backslash); false } + '\'' -> { pushState(::nonspace); pushState(::inSingle); false } + '"' -> { pushState(::nonspace); pushState(::inDouble); false } + '\\' -> { pushState(::nonspace); pushState(::backslash); false } else -> { pushState(::nonspace); true } } @@ -107,14 +97,14 @@ private fun inSingle(ch: Char): Boolean = when (ch) { - '\'' -> { endQuote(); false } + '\'' -> { popState(); false } else -> { current.append(ch); false } } private fun inDouble(ch: Char): Boolean = when (ch) { '\\' -> { pushState(::backslash); false } - '"' -> { endQuote(); false } + '"' -> { popState(); false } else -> { current.append(ch); false } } diff -r 7d80cbcb67bb -r 4391afcf6bd0 src/test/kotlin/name/blackcap/passman/ShplitterTest.kt --- a/src/test/kotlin/name/blackcap/passman/ShplitterTest.kt Sun Jun 30 20:37:36 2024 -0700 +++ b/src/test/kotlin/name/blackcap/passman/ShplitterTest.kt Sun Jun 30 22:28:52 2024 -0700 @@ -91,12 +91,12 @@ TestDatum("\"foo\\ x\\x\\\\\"", arrayOf("foo xx\\")), TestDatum("\"foo\\ x\\x\\\\\"\"foobar\"", arrayOf("foo xx\\foobar")), TestDatum("\"foo\\ x\\x\\\\\"\\'\"foobar\"", arrayOf("foo xx\\'foobar")), - TestDatum("\"foo\\ x\\x\\\\\"\\'\"fo'obar\" 'don'\\''t'", arrayOf("foo xx\\'foobar\" don\\t")), + TestDatum("\"foo\\ x\\x\\\\\"\\'\"fo'obar\" 'don'\\''t'", arrayOf("foo xx\\'fo'obar", "don't")), TestDatum("'foo\\ bar'", arrayOf("foo\\ bar")), TestDatum("'foo\\\\ bar'", arrayOf("foo\\\\ bar")), TestDatum("foo\\ bar", arrayOf("foo bar")), TestDatum("foo#bar\\nbaz", arrayOf("foo#barnbaz")), - TestDatum(":-) ;-)", arrayOf(":-)", ":-)")), + TestDatum(":-) ;-)", arrayOf(":-)", ";-)")), TestDatum("áéíóú", arrayOf("áéíóú")) )