Changes

Jump to navigation Jump to search
2,699 bytes added ,  08:56, 28 September 2012
Document utilities.parsers
rest after that regardless of any further occurrences of <tt>separator</tt>.
= util-prs.lua =
 
== utilities.parsers.settings_to_hash(str) ==
 
<pre>
str = 'a=1, b=2, c=3'
utilities.parsers.settings_to_hash(str)
--> { a = 1, b = 2, c = 3 }
</pre>
 
{{code|utilities.parsers.settings_to_array}} takes a string of comma-separated key=value statements, and returns an associative array of {{code|1=["key"] = value}} entries. Very useful for parsing and accessing macro arguments at the Lua end.
 
== utilities.parsers.settings_to_array(str) ==
 
<pre>
str = 'top, inmargin=2, top, {here,now}'
utilities.parsers.settings_to_array(str)
--> { "top", "inmargin=2", "top", "here,now" }
</pre>
 
{{code|utilities.parsers.settings_to_array}} takes a string of comma-separated keywords, and returns a array of those keywords in the order in which they appear. Duplicates are not filtered. <tt>Key=value</tt> strings are taken as a single keyword. Surrounding braces are removed
 
== utilities.parsers.settings_to_set(str) ==
 
<pre>
str = 'top, inmargin=2, top, {here,now}'
utilities.parsers.settings_to_set(str)
--> { "top", "inmargin=2", "here,now" }
</pre>
 
{{code|utilities.parsers.settings_to_array}} takes a string of comma-separated keywords, and returns a array of those keywords in the order in which they appear, with duplicates removed.
<tt>Key=value</tt> strings are taken as a single keyword. Surrounding braces are removed
 
== Other function in utilities.parsers ==
{| class="wikitable"
|-
| utilities.parsers.add_settings_to_array
| parse and write directly into table
|-
| utilities.parsers.arguments_to_table
| parse arguments, return table
|-
| utilities.parsers.array_to_string(a,sep)
| concatenates a with custom sep or comma
|-
| utilities.parsers.getparameters
| write settings_to_hash to an array with a metatable. A metatable is a sort of parent: when a table is accessed, undefined values will be looked up in the metatable.
|-
| utilities.parsers.hash_to_string
| turn a hash into a string, with optional strictness settings
|-
| utilities.parsers.simple_hash_to_string
| concatenate the values of a hash
|-
| utilities.parsers.make_settings_to_hash_pattern
| returns parser pattern for strict, tolerant, or normal arg-parsing
|-
| utilities.parsers.settings_to_hash_strict
| like settings_to_hash with strict parsing
|-
| utilities.parsers.settings_to_hash_tolerant
| like settings_to_hash with tolerant parsing
|-
| utilities.parsers.splitthousands
| turns 12345678.44 into 12,345,678.44
|-
|}
=LuaTeX=
turned out to be almost twice as fast as an LPEG iterator.
=RecipiesRecipes=
General: [http://lua-users.org/wiki/StringRecipes string section of the Lua wiki].
[[Category:Lua]]
[[Category:Programming]]
/tt> with surrounding quotes removed iff they are
of the same kind (ascii single/double quote only).
 
==string.quote(string)==
 
Equivalent to /tt> strings are taken as a single keyword. Surrounding braces are removed
 
== utilities.parsers.settings_to_set(str) ==

Navigation menu