webmcp
annotate framework/env/parse/boolean.lua @ 2:72860d232f32
Version 1.0.2
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
author | jbe/bsw |
---|---|
date | Thu Dec 10 12:00:00 2009 +0100 (2009-12-10) |
parents | 9fdfb27f8e67 |
children |
rev | line source |
---|---|
jbe/bsw@0 | 1 function parse.boolean(str, dest_type, options) |
jbe/bsw@0 | 2 if dest_type ~= atom.boolean then |
jbe/bsw@0 | 3 error("parse.boolean(...) can only return booleans, but a different destination type than atom.boolean was given.") |
jbe/bsw@0 | 4 end |
jbe/bsw@0 | 5 local options = options or {} |
jbe/bsw@0 | 6 local trimmed_str = string.match(str or "", "^%s*(.-)%s*$") |
jbe/bsw@0 | 7 if options.true_as or options.false_as or options.nil_as then |
jbe/bsw@0 | 8 if trimmed_str == options.true_as then |
jbe/bsw@0 | 9 return true |
jbe/bsw@0 | 10 elseif trimmed_str == options.false_as then |
jbe/bsw@0 | 11 return false |
jbe/bsw@0 | 12 elseif trimmed_str == options.nil_as or trimmed_str == "" then |
jbe/bsw@0 | 13 return nil |
jbe/bsw@0 | 14 else |
jbe/bsw@0 | 15 error("Boolean value not recognized.") |
jbe/bsw@0 | 16 end |
jbe/bsw@0 | 17 else |
jbe/bsw@0 | 18 local char = string.upper(string.sub(trimmed_str, 1, 1)) |
jbe/bsw@0 | 19 if char == "1" or char == "T" or char == "Y" then |
jbe/bsw@0 | 20 return true |
jbe/bsw@0 | 21 elseif char == "0" or char == "F" or char == "N" then |
jbe/bsw@0 | 22 return false |
jbe/bsw@0 | 23 elseif char == "" then |
jbe/bsw@0 | 24 return nil |
jbe/bsw@0 | 25 else |
jbe/bsw@0 | 26 error("Boolean value not recognized.") |
jbe/bsw@0 | 27 end |
jbe/bsw@0 | 28 end |
jbe/bsw@0 | 29 end |