Hi all,

I've found a helper function that does this:
utilities.parsers.settings_to_hash('ape=1, note=2, mice=3')
-->
{
  ["ape"] = 1,
  ["note"] = 2,
  ["mice"] = 3
}

This makes me very happy. This function and its friends are stored
under utilities.parsers, and defined in util-prs.lua; I've listed them
below. Perhaps they'll be useful to somebody else, too.

I should probably add this info to
http://wiki.contextgarden.net/Commands_with_KeyVal_arguments,
but dinner first.

Cheers,
Sietse

First some examples of what the most important functions:

utilities.parsers.settings_to_hash('ape=1, note=2, mice=3')
-->
{ ["ape"] = 1, ["note"] = 2,  ["mice"] = 3 }
--  settings_to_hash takes an option 'strict',
-- I assume that has to do with space-trimming.

utilities.parsers.settings_to_array('ape, note=2, mice, ape')
--> { "ape", "note=2", "mice", "ape" }

utilities.parsers.settings_to_array('ape, note=2, mice, ape')
--> { ["ape"]=true, ["note=2"]=true, ["mice"]=true,}


Complete list of functions (and one table) in utilities.parsers:
T.add_settings_to_array
T.arguments_to_table
T.array_to_string
T.getparameters
T.hash_to_string
T.listitem
T.make_settings_to_hash_pattern
T.patterns                    : table: 0x9a67680
T.patterns.settings_to_array  : userdata: 0x9a6c904
T.patterns.settings_to_hash_a : userdata: 0x9a6a694
T.patterns.settings_to_hash_b : userdata: 0x9a6ad6c
T.patterns.settings_to_hash_c : userdata: 0x9a6b424
T.settings_to_array
T.settings_to_hash
T.settings_to_hash_strict
T.settings_to_hash_tolerant
T.settings_to_set
T.simple_hash_to_string
T.splitthousands
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to