Merge pull request #1677 from fredj/xsd-from-string

Add ol.format.XSD.read*String functions
This commit is contained in:
Frédéric Junod
2014-02-10 16:34:46 +01:00

View File

@@ -17,7 +17,16 @@ ol.format.XSD.NAMESPACE_URI = 'http://www.w3.org/2001/XMLSchema';
*/
ol.format.XSD.readBoolean = function(node) {
var s = ol.xml.getAllTextContent(node, false);
var m = /^\s*(true|1)|(false|0)\s*$/.exec(s);
return ol.format.XSD.readBooleanString(s);
};
/**
* @param {string} string String.
* @return {boolean|undefined} Boolean.
*/
ol.format.XSD.readBooleanString = function(string) {
var m = /^\s*(true|1)|(false|0)\s*$/.exec(string);
if (m) {
return goog.isDef(m[1]) || false;
} else {
@@ -62,9 +71,18 @@ ol.format.XSD.readDateTime = function(node) {
* @return {number|undefined} Decimal.
*/
ol.format.XSD.readDecimal = function(node) {
// FIXME check spec
var s = ol.xml.getAllTextContent(node, false);
var m = /^\s*([+\-]?\d*\.?\d+(?:e[+\-]?\d+)?)\s*$/i.exec(s);
return ol.format.XSD.readDecimalString(s);
};
/**
* @param {string} string String.
* @return {number|undefined} Decimal.
*/
ol.format.XSD.readDecimalString = function(string) {
// FIXME check spec
var m = /^\s*([+\-]?\d*\.?\d+(?:e[+\-]?\d+)?)\s*$/i.exec(string);
if (m) {
return parseFloat(m[1]);
} else {
@@ -79,7 +97,16 @@ ol.format.XSD.readDecimal = function(node) {
*/
ol.format.XSD.readNonNegativeInteger = function(node) {
var s = ol.xml.getAllTextContent(node, false);
var m = /^\s*(\d+)\s*$/.exec(s);
return ol.format.XSD.readNonNegativeIntegerString(s);
};
/**
* @param {string} string String.
* @return {number|undefined} Non negative integer.
*/
ol.format.XSD.readNonNegativeIntegerString = function(string) {
var m = /^\s*(\d+)\s*$/.exec(string);
if (m) {
return parseInt(m[1], 10);
} else {