Hi devs,

here are the functions,

/**
* Converts a given string to a boolean and returns it (small helper as elementVars are always strings).
* Handles this rather strict:
*    '1'     => true
*    'true'  => true
*    '0'     => false
*    'false' => false
* Nearly all other cases evaluate to 'undefined', this behaviour can be changed if the first line is altered and the variabnle bool is
* initialized with a value (e.g. var bool = false).
*
* @param {string} the var to convert
* @return {boolean} a boolean version of the passed var according to the above described rules or 'undefined'
* @author Marc Jansen <[EMAIL PROTECTED]>
*/
function elementvar_2_boolean(theVar) {
 var bool;
 if (   theVar.toLowerCase() === 'true'
     || parseInt(theVar, 10) === 1      ) {
   bool = true;
 } else {
   if (   theVar.toLowerCase() === 'false'
       || parseInt(theVar, 10) === 0       ) {
       bool = false;
   }
 }
 return bool;
}
/**
* Converts a given string to a integer and returns it (small helper as elementVars are always strings).
*
* @param {string} the var to convert
* @return {integer} a integer version of the passed var or 'NaN'
* @author Marc Jansen <[EMAIL PROTECTED]>
*/
function elementvar_2_integer(theVar) {
 return parseInt(theVar, 10);
}
/**
* Converts a given string to a float and returns it, german decimal divider ',' is recognized (small helper as elementVars are always strings).
*
* @param {string} the var to convert
* @return {integer} a float version of the passed var or 'NaN'
* @author Marc Jansen <[EMAIL PROTECTED]>
*/
function elementvar_2_float(theVar) {
 return parseFloat( theVar.replace(/,/g, '.') );
}

Shall I commit these?... would be good for my stats atr ohloh ;-)

-- Marc

Christoph Baudson (WhereGroup) schrieb:
[snip]

-----------------------
Element vars
-----------------------

We were discussing the necessity of variable types for element vars (if you don't know what element vars are, see http://www.mapbender.org/index.php/Element_var). Now, there's only one type (string), and the scripts parse it they way they want.

There were some pros and cons for the introduction of types:
- interface might become more complicated
+ type safety in scripts
+ arrays are hard to handle at the moment

Marc had written a small JS conversion function that he will send to the dev-list.
[/snip]
_______________________________________________
Mapbender_dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/mapbender_dev

Reply via email to