Skip to content

Instantly share code, notes, and snippets.

@treytomes
Created January 5, 2024 14:31
Show Gist options
  • Save treytomes/905936947b0863879d6637735f6f7ef3 to your computer and use it in GitHub Desktop.
Save treytomes/905936947b0863879d6637735f6f7ef3 to your computer and use it in GitHub Desktop.
Split a quoted string around a delimiter.
import "qa"
// Split a quoted string on a delimiter.
string.splitQuote = function(delim)
a = self.split("""")
b = []
for n in a.indexes
if n % 2 == 0 then
b += a[n].trim.split(delim)
else
b.push """" + a[n] + """"
end if
end for
return b
end function
runUnitTests = function
delim = " "
text = """But what if I spoke before thinking?"" he thought to himself."
qa.assertEqual text.splitQuote(delim), [
"""But what if I spoke before thinking?""",
"he",
"thought",
"to",
"himself.",
]
text = "He said, ""But what did you think?"", but no one was listening."
qa.assertEqual text.splitQuote(delim), [
"He",
"said,",
"""But what did you think?""",
",",
"but",
"no",
"one",
"was",
"listening.",
]
end function
runUnitTests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment