Folks,
For another piece of work I have come across problem I believe someone with better regex skills than my self may be able to solve.
- It seems to me a larger problem of parsing key/value pairs can be solved if the smaller problem of identifying how to spit a string into separate pairs is found.
First example
number="1",streetaddress="my street",city="my town",postcode=2222,"key name"="key value"
In this example the existence of the comma, It is possible to split this string to extract five separate key value pairs and then handle them.
- However we can not use comma â,â inside the key or values?
- what if the input does not include commas?
Second example
number="1" streetaddress="my street" city="my town" postcode=2222 "key name"="key value"
- In this example we are using key value pairs that we understand as a list but how can we parse this into separate key value pairs?
Third example;
number='1' streetaddress="my street there is a 'object' waiting" city="my town" postcode=2222 "key name"="key value" keyname=""" This includes "double quote" in the value""" mykey=45
- This introduces examples of the different quote rules as documented, again without the commas. How can we split this into key/value pairs?
Note, Tiddlywiki can already parse a range of key/value pairs passed into a widget and macros and the new set multiple variables widget can make use of a list of keys plus a list of values to convert key value pairs into variables.
The problem is the initial spiting of a list of key/value pairs into separate pairs to give the various alternative ways to âquote a valueâ, or for that matter quotes for a key name.
- It is also a little difficult to then make use of the results of a successful list of key/value pairs.
I would appreciate any ideas and especially if a split operator such as splitregexp<myexp>
could be used to do this for all cases in general.
- or at least based only on double quotes of the values.
- or perhaps a tool to programmatically insert the appropriate commas.
There may even be a hack that uses the similar behaviour already in tiddlywiki to achieve the full outcome.
- For example most widgets accept and validly process such key/value pairs often referred to as a âHashmap of variablesâ.