Tobias Gritschacher has submitted this change and it was merged. Change subject: Removed obsolete JavaScript globe coordinate parser ......................................................................
Removed obsolete JavaScript globe coordinate parser
Change-Id: I811eabdebde6b0c24fca3e0dafc7905e9d678250
---
M .jshintignore
M DataValues/DataValues.resources.mw.php
M DataValues/DataValues.tests.qunit.php
M DataValues/resources/globeCoordinate.js/src/globeCoordinate.GlobeCoordinate.js
D DataValues/resources/globeCoordinate.js/src/globeCoordinate.parser.js
M
DataValues/resources/globeCoordinate.js/tests/globeCoordinate.GlobeCoordinate.tests.js
D DataValues/resources/globeCoordinate.js/tests/globeCoordinate.parser.tests.js
M DataValues/resources/values/GlobeCoordinateValue.js
M DataValues/tests/qunit/values/GlobeCoordinateValue.tests.js
M ValueParsers/tests/qunit/parsers/GlobeCoordinateParser.tests.js
10 files changed, 76 insertions(+), 1,002 deletions(-)
Approvals:
Tobias Gritschacher: Looks good to me, approved
diff --git a/.jshintignore b/.jshintignore
index ee04da2..ed80c95 100644
--- a/.jshintignore
+++ b/.jshintignore
@@ -1,2 +1 @@
-./DataValues/resources/globeCoordinate.js/src/globeCoordinate.parser.js
./DataValues/resources/qunit.parameterize/qunit.parameterize.js
diff --git a/DataValues/DataValues.resources.mw.php
b/DataValues/DataValues.resources.mw.php
index 9494ce8..4f46694 100644
--- a/DataValues/DataValues.resources.mw.php
+++ b/DataValues/DataValues.resources.mw.php
@@ -66,7 +66,6 @@
'globeCoordinate.js' => $moduleTemplate + array(
'scripts' => array(
'globeCoordinate.js/src/globeCoordinate.js',
-
'globeCoordinate.js/src/globeCoordinate.parser.js',
'globeCoordinate.js/src/globeCoordinate.GlobeCoordinate.js',
),
),
diff --git a/DataValues/DataValues.tests.qunit.php
b/DataValues/DataValues.tests.qunit.php
index b2e1c5e..a838723 100644
--- a/DataValues/DataValues.tests.qunit.php
+++ b/DataValues/DataValues.tests.qunit.php
@@ -84,7 +84,6 @@
'globeCoordinate.js.tests' => array(
'scripts' => array(
'resources/globeCoordinate.js/tests/globeCoordinate.tests.js',
-
'resources/globeCoordinate.js/tests/globeCoordinate.parser.tests.js',
'resources/globeCoordinate.js/tests/globeCoordinate.GlobeCoordinate.tests.js',
),
'dependencies' => array(
diff --git
a/DataValues/resources/globeCoordinate.js/src/globeCoordinate.GlobeCoordinate.js
b/DataValues/resources/globeCoordinate.js/src/globeCoordinate.GlobeCoordinate.js
index a820aca..38b6da4 100644
---
a/DataValues/resources/globeCoordinate.js/src/globeCoordinate.GlobeCoordinate.js
+++
b/DataValues/resources/globeCoordinate.js/src/globeCoordinate.GlobeCoordinate.js
@@ -10,48 +10,33 @@
* @author H. Snater < [email protected] >
*
* @dependency globeCoordinate
- * @dependency globeCoordinate.parser
*/
-globeCoordinate.GlobeCoordinate = ( function( globeCoordinate,
globeCoordinateParser ) {
+globeCoordinate.GlobeCoordinate = ( function( globeCoordinate ) {
'use strict';
/**
* Constructor for an object representing a globe coordinate with a
certain precision.
*
- * @param {string|Object} globeCoordinateDefinition
- * @param {Object} [options]
- * {number} precision: Precision which will overrule the
automatically detected
- * precision.
- *
- * @throws {Error} If input text could not be parsed.
+ * @param {Object} gcDef Needs the following attributes:
+ * - {number} latitude
+ * - {number} longitude
+ * - {number} precision
*
* @constructor
*/
- function GlobeCoordinate( globeCoordinateDefinition, options ) {
- var parsed;
-
- options = options || {};
-
- if( !globeCoordinateDefinition ) {
- throw new Error( 'No input given' );
+ function GlobeCoordinate( gcDef ) {
+ if( !gcDef || typeof gcDef !== 'object'
+ || gcDef.latitude === undefined
+ || gcDef.longitude === undefined
+ || gcDef.precision === undefined
+ ) {
+ throw new Error( 'No proper globe coordinate definition
given' );
}
- if( typeof globeCoordinateDefinition === 'string' ) {
- try {
- parsed = globeCoordinateParser.parse(
globeCoordinateDefinition );
- } catch( e ) {
- throw new Error( 'Could not parse input: ' +
e.toString() );
- }
+ this._latitude = gcDef.latitude;
+ this._longitude = gcDef.longitude;
+ this._precision = gcDef.precision;
- this._rawInput = globeCoordinateDefinition;
- this._latitude = parsed[0];
- this._longitude = parsed[1];
- this._precision = ( options.precision !== undefined ) ?
options.precision : parsed[2];
- } else {
- this._latitude = globeCoordinateDefinition.latitude;
- this._longitude = globeCoordinateDefinition.longitude;
- this._precision = globeCoordinateDefinition.precision;
- }
// TODO: Capture altitude and globe
// TODO: The following checks are earth specific. When
implementing additional globes,
@@ -121,13 +106,6 @@
getGlobe: function() {
return this._globe;
},
-
- /**
- * Returns the original (raw) input.
- *
- * @return {string}
- */
- getRawInput: function() { return this._rawInput; },
/**
* Returns the decimal latitude.
@@ -227,17 +205,19 @@
*/
iso6709: function() {
var lat = this.latitudeDegree(),
- lon = this.longitudeDegree();
+ lon = this.longitudeDegree(),
+ latISO,
+ lonISO;
/**
* Strips a number's sign and fills the number's
integer part with zeroes according to a
* given string length.
*
* @param {number} number
- * @param {number} length
+ * @param {string} length
*/
function pad( number, length ) {
- var absolute = Math.abs( number ),
+ var absolute = Math.abs( number || 0 ),
string = String( absolute ),
exploded = string.split( '.' );
@@ -251,16 +231,31 @@
+ ( ( exploded[1] ) ? '.' + exploded[1]
: '' );
}
- // There is no need to include minute in the result if
minute and second have no value.
- // If second has no value, it can be dropped anyway.
- return ''
+ latISO = ''
+ ( ( ( this.getLatitude() < 0 ) ? '-' : '+' )
+ pad( lat.degree, 2 ) )
- + ( ( lat.minute || lat.second ) ? pad(
lat.minute, 2 ) : '' )
- + ( ( lat.second ) ? pad( lat.second, 2 ) : '' )
+ + ( ( this.getPrecision() < 1 ) ? pad(
lat.minute, 2 ) : '' )
+ + ( ( this.getPrecision() < 1 / 60 ) ? pad(
lat.second, 2 ) : '' );
+
+ lonISO = ''
+ ( ( ( this.getLongitude() < 0 ) ? '-' : '+' )
+ pad( lon.degree, 3 ) )
- + ( ( lon.minute || lon.second ) ? pad(
lon.minute, 2 ) : '' )
- + ( ( lon.second ) ? pad( lon.second, 2 ) : '' )
- + '/';
+ + ( ( this.getPrecision() < 1 ) ? pad(
lon.minute, 2 ) : '' )
+ + ( ( this.getPrecision() < 1 / 60 ) ? pad(
lon.second, 2 ) : '' );
+
+ // Synchronize precision (longitude degree needs to be
1 digit longer):
+ if( lonISO.indexOf( '.' ) !== -1 && latISO.indexOf( '.'
) === -1 ) {
+ latISO += '.';
+ }
+ while( latISO.length < lonISO.length - 1 ) {
+ latISO += '0';
+ }
+ if( latISO.indexOf( '.' ) !== -1 && lonISO.indexOf( '.'
) === -1 ) {
+ lonISO += '.';
+ }
+ while( lonISO.length < latISO.length + 1 ) {
+ lonISO += '0';
+ }
+
+ return latISO + lonISO + '/';
},
/**
@@ -283,4 +278,4 @@
return GlobeCoordinate;
-}( globeCoordinate, globeCoordinate.parser ) );
+}( globeCoordinate ) );
diff --git
a/DataValues/resources/globeCoordinate.js/src/globeCoordinate.parser.js
b/DataValues/resources/globeCoordinate.js/src/globeCoordinate.parser.js
deleted file mode 100644
index 0e63e25..0000000
--- a/DataValues/resources/globeCoordinate.js/src/globeCoordinate.parser.js
+++ /dev/null
@@ -1,849 +0,0 @@
-/**
- * Globe coordinate parser
- * Original source: http://simia.net/valueparser/coordinate.js
- *
- * VERSION: 0.1
- *
- * @since 0.1
- * @file
- * @ingroup globeCoordinate.js
- * @licence GNU GPL v2+
- *
- * @author Denny Vrandečić
- *
- * @dependency globeCoordinate
- *
- * TODO: Change the return value to be an object which can be passed into the
- * GlobeCoordinate constructor.
- *
- * TODO: Make the parser a constructor which can take options, instances then
have a parse
- * function and we avoid global state for parser options.
- *
- * TODO: Make this parser more lightweight or properly use native PEG.js
rather than modifying it.
- */
-globeCoordinate.parser = ( function( globeCoordinate ){
- 'use strict';
-
- /*
- * Generated by PEG.js 0.7.0.
- *
- * http://pegjs.majda.cz/
- */
-
- /*
- * Returns a string padded on the left to a desired length with a
character.
- *
- * The code needs to be in sync with the code template in the
compilation
- * function for "action" nodes.
- */
- function padLeft(input, padding, length) {
- var result = input;
-
- var padLength = length - input.length;
- for (var i = 0; i < padLength; i++) {
- result = padding + result;
- }
-
- return result;
- }
-
- /*
- * Returns an escape sequence for given character. Uses \x for
characters <=
- * 0xFF to save space, \u for the rest.
- *
- * The code needs to be in sync with the code template in the
compilation
- * function for "action" nodes.
- */
- function escape(ch) {
- var charCode = ch.charCodeAt(0);
- var escapeChar;
- var length;
-
- if (charCode <= 0xFF) {
- escapeChar = 'x';
- length = 2;
- } else {
- escapeChar = 'u';
- length = 4;
- }
-
- return '\\' + escapeChar +
padLeft(charCode.toString(16).toUpperCase(), '0', length);
- }
-
- /*
- * Surrounds the string with quotes and escapes characters inside so
that the
- * result is a valid JavaScript string.
- *
- * The code needs to be in sync with the code template in the
compilation
- * function for "action" nodes.
- */
- function quote(s) {
- /*
- * ECMA-262, 5th ed., 7.8.4: All characters may appear
literally in a
- * string literal except for the closing quote character,
backslash,
- * carriage return, line separator, paragraph separator, and
line feed.
- * Any character may appear in the form of an escape sequence.
- *
- * For portability, we also escape escape all control and
non-ASCII
- * characters. Note that "\0" and "\v" escape sequences are not
used
- * because JSHint does not like the first and IE the second.
- */
- return '"' + s
- .replace(/\\/g, '\\\\') // backslash
- .replace(/"/g, '\\"') // closing quote character
- .replace(/\x08/g, '\\b') // backspace
- .replace(/\t/g, '\\t') // horizontal tab
- .replace(/\n/g, '\\n') // line feed
- .replace(/\f/g, '\\f') // form feed
- .replace(/\r/g, '\\r') // carriage return
- .replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape)
- + '"';
- }
-
- var result = {
- /*
- * Parses the input with a generated parser. If the parsing is
successfull,
- * returns a value explicitly or implicitly specified by the
grammar from
- * which the parser was generated (see |PEG.buildParser|). If
the parsing is
- * unsuccessful, throws |PEG.parser.SyntaxError| describing the
error.
- */
- parse: function(input, startRule) {
- var parseFunctions = {
- "start": parse_start,
- "val": parse_val,
- "postdot": parse_postdot,
- "integer": parse_integer
- };
-
- if (startRule !== undefined) {
- if (parseFunctions[startRule] === undefined) {
- throw new Error("Invalid rule name: " +
quote(startRule) + ".");
- }
- } else {
- startRule = "start";
- }
-
- var pos = 0;
- var reportFailures = 0;
- var rightmostFailuresPos = 0;
- var rightmostFailuresExpected = [];
-
- function padLeft(input, padding, length) {
- var result = input;
-
- var padLength = length - input.length;
- for (var i = 0; i < padLength; i++) {
- result = padding + result;
- }
-
- return result;
- }
-
- function escape(ch) {
- var charCode = ch.charCodeAt(0);
- var escapeChar;
- var length;
-
- if (charCode <= 0xFF) {
- escapeChar = 'x';
- length = 2;
- } else {
- escapeChar = 'u';
- length = 4;
- }
-
- return '\\' + escapeChar +
padLeft(charCode.toString(16).toUpperCase(), '0', length);
- }
-
- function matchFailed(failure) {
- if (pos < rightmostFailuresPos) {
- return;
- }
-
- if (pos > rightmostFailuresPos) {
- rightmostFailuresPos = pos;
- rightmostFailuresExpected = [];
- }
-
- rightmostFailuresExpected.push(failure);
- }
-
- function parse_start() {
- var result0, result1, result2, result3,
result4, result5, result6, result7, result8, result9, result10, result11;
- var pos0, pos1;
-
- pos0 = pos;
- pos1 = pos;
- result0 = [];
- if (input.charCodeAt(pos) === 32) {
- result1 = " ";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\" \"");
- }
- }
- while (result1 !== null) {
- result0.push(result1);
- if (input.charCodeAt(pos) === 32) {
- result1 = " ";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\" \"");
- }
- }
- }
- if (result0 !== null) {
- result1 = parse_val();
- if (result1 !== null) {
- result2 = [];
- if (input.charCodeAt(pos) ===
32) {
- result3 = " ";
- pos++;
- } else {
- result3 = null;
- if (reportFailures ===
0) {
- matchFailed("\"
\"");
- }
- }
- while (result3 !== null) {
- result2.push(result3);
- if
(input.charCodeAt(pos) === 32) {
- result3 = " ";
- pos++;
- } else {
- result3 = null;
- if
(reportFailures === 0) {
-
matchFailed("\" \"");
- }
- }
- }
- if (result2 !== null) {
- if (input.substr(pos,
1).toUpperCase() === globeCoordinate.settings.north) {
- result3 =
input.substr(pos, 1);
- pos++;
- } else {
- result3 = null;
- if
(reportFailures === 0) {
-
matchFailed("\"N\"");
- }
- }
- result3 = result3 !==
null ? result3 : "";
- if (result3 !== null) {
- if
(input.substr(pos, 1).toUpperCase() === globeCoordinate.settings.south) {
- result4
= input.substr(pos, 1);
- pos++;
- } else {
- result4
= null;
- if
(reportFailures === 0) {
-
matchFailed("\"S\"");
- }
- }
- result4 =
result4 !== null ? result4 : "";
- if (result4 !==
null) {
- result5
= [];
- if
(/^[, ]/.test(input.charAt(pos))) {
-
result6 = input.charAt(pos);
-
pos++;
- } else {
-
result6 = null;
-
if (reportFailures === 0) {
-
matchFailed("[, ]");
-
}
- }
- while
(result6 !== null) {
-
result5.push(result6);
-
if (/^[, ]/.test(input.charAt(pos))) {
-
result6 = input.charAt(pos);
-
pos++;
-
} else {
-
result6 = null;
-
if (reportFailures === 0) {
-
matchFailed("[, ]");
-
}
-
}
- }
- if
(result5 !== null) {
-
result6 = parse_val();
-
if (result6 !== null) {
-
result7 = [];
-
if (input.charCodeAt(pos) === 32) {
-
result8 = " ";
-
pos++;
-
} else {
-
result8 = null;
-
if (reportFailures === 0) {
-
matchFailed("\" \"");
-
}
-
}
-
while (result8 !== null) {
-
result7.push(result8);
-
if (input.charCodeAt(pos) === 32) {
-
result8 = " ";
-
pos++;
-
} else {
-
result8 = null;
-
if (reportFailures === 0) {
-
matchFailed("\" \"");
-
}
-
}
-
}
-
if (result7 !== null) {
-
if (input.substr(pos, 1).toUpperCase() ===
globeCoordinate.settings.east) {
-
result8 = input.substr(pos, 1);
-
pos++;
-
} else {
-
result8 = null;
-
if (reportFailures === 0) {
-
matchFailed("\"E\"");
-
}
-
}
-
result8 = result8 !== null ? result8 : "";
-
if (result8 !== null) {
-
if (input.substr(pos, 1).toUpperCase() ===
globeCoordinate.settings.west) {
-
result9 = input.substr(pos, 1);
-
pos++;
-
} else {
-
result9 = null;
-
if (reportFailures === 0) {
-
matchFailed("\"W\"");
-
}
-
}
-
result9 = result9 !== null ? result9 : "";
-
if (result9 !== null) {
-
result10 = [];
-
if (input.charCodeAt(pos) === 32) {
-
result11 = " ";
-
pos++;
-
} else {
-
result11 = null;
-
if (reportFailures === 0) {
-
matchFailed("\" \"");
-
}
-
}
-
while (result11 !== null) {
-
result10.push(result11);
-
if (input.charCodeAt(pos) === 32) {
-
result11 = " ";
-
pos++;
-
} else {
-
result11 = null;
-
if (reportFailures === 0) {
-
matchFailed("\" \"");
-
}
-
}
-
}
-
if (result10 !== null) {
-
result0 = [result0, result1, result2,
result3, result4, result5, result6, result7, result8, result9, result10];
-
} else {
-
result0 = null;
-
pos = pos1;
-
}
-
} else {
-
result0 = null;
-
pos = pos1;
-
}
-
} else {
-
result0 = null;
-
pos = pos1;
-
}
-
} else {
-
result0 = null;
-
pos = pos1;
-
}
-
} else {
-
result0 = null;
-
pos = pos1;
-
}
- } else {
-
result0 = null;
-
pos = pos1;
- }
- } else {
- result0
= null;
- pos =
pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = ( function( offset, latitude,
north, south, longitude, east, west ) {
- var lat = ( south!=='' )?
latitude[0] * -1 : latitude[0];
- var lon = ( west!=='' )?
longitude[0] * -1 : longitude[0];
- var precision = Math.min(
latitude[1], longitude[1] );
- return [lat, lon, precision];
- } )( pos0, result0[1], result0[3],
result0[4], result0[6], result0[8], result0[9] );
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
-
- function parse_val() {
- var result0, result1, result2, result3,
result4, result5, result6, result7, result8, result9, result10;
- var pos0, pos1;
-
- pos0 = pos;
- pos1 = pos;
- if (/^[+\-]/.test(input.charAt(pos))) {
- result0 = input.charAt(pos);
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("[+\\-]");
- }
- }
- result0 = result0 !== null ? result0 : "";
- if (result0 !== null) {
- result1 = parse_integer();
- if (result1 !== null) {
- if (input.charCodeAt(pos) ===
176) {
- result2 = "\xB0";
- pos++;
- } else {
- result2 = null;
- if (reportFailures ===
0) {
-
matchFailed("\"\\xB0\"");
- }
- }
- result2 = result2 !== null ?
result2 : "";
- if (result2 !== null) {
- result3 = [];
- if
(input.charCodeAt(pos) === 32) {
- result4 = " ";
- pos++;
- } else {
- result4 = null;
- if
(reportFailures === 0) {
-
matchFailed("\" \"");
- }
- }
- while (result4 !==
null) {
-
result3.push(result4);
- if
(input.charCodeAt(pos) === 32) {
- result4
= " ";
- pos++;
- } else {
- result4
= null;
- if
(reportFailures === 0) {
-
matchFailed("\" \"");
- }
- }
- }
- if (result3 !== null) {
- result4 =
parse_integer();
- if (result4 !==
null) {
- if
(input.charCodeAt(pos) === 39 || input.charCodeAt(pos) === 8242) { //' and ′
-
result5 = "'";
-
pos++;
- } else {
-
result5 = null;
-
if (reportFailures === 0) {
-
matchFailed("\"'\"");
-
}
- }
- result5
= result5 !== null ? result5 : "";
- if
(result5 !== null) {
-
result6 = [];
-
if (input.charCodeAt(pos) === 32) {
-
result7 = " ";
-
pos++;
-
} else {
-
result7 = null;
-
if (reportFailures === 0) {
-
matchFailed("\" \"");
-
}
-
}
-
while (result7 !== null) {
-
result6.push(result7);
-
if (input.charCodeAt(pos) === 32) {
-
result7 = " ";
-
pos++;
-
} else {
-
result7 = null;
-
if (reportFailures === 0) {
-
matchFailed("\" \"");
-
}
-
}
-
}
-
if (result6 !== null) {
-
result7 = parse_integer();
-
if (result7 !== null) {
-
result8 = parse_postdot();
-
if (result8 !== null) {
-
result9 = [];
-
var quoteIds = [34, 39, 8242, 8243]; //", ', ′ and ″
-
if (quoteIds.indexOf(input.charCodeAt(pos)) !== -1) {
-
result10 = input.charAt(pos);
-
pos++;
-
} else {
-
result10 = null;
-
if (reportFailures === 0) {
-
matchFailed("['\"′″]");
-
}
-
}
-
while (result10 !== null) {
-
result9.push(result10);
-
if (quoteIds.indexOf(input.charCodeAt(pos)) !==
-1) {
-
result10 = input.charAt(pos);
-
pos++;
-
} else {
-
result10 = null;
-
if (reportFailures === 0) {
-
matchFailed("['\"′″]");
-
}
-
}
-
}
-
if (result9 !== null) {
-
if (input.charCodeAt(pos) === 176) {
-
result10 = "\xB0";
-
pos++;
-
} else {
-
result10 = null;
-
if (reportFailures === 0) {
-
matchFailed("\"\\xB0\"");
-
}
-
}
-
result10 = result10 !== null ? result10 : "";
-
if (result10 !== null) {
-
result0 = [result0, result1, result2,
result3, result4, result5, result6, result7, result8, result9, result10];
-
} else {
-
result0 = null;
-
pos = pos1;
-
}
-
} else {
-
result0 = null;
-
pos = pos1;
-
}
-
} else {
-
result0 = null;
-
pos = pos1;
-
}
-
} else {
-
result0 = null;
-
pos = pos1;
-
}
-
} else {
-
result0 = null;
-
pos = pos1;
-
}
- } else {
-
result0 = null;
-
pos = pos1;
- }
- } else {
- result0
= null;
- pos =
pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = ( function( offset, sign,
full, min, dotsec, sec, postdot ) {
- var r = full + min / 60 + sec /
3600;
- var precision = 1;
- if( sec > 0 ) {
- precision = 1 / 3600;
- } else if( min > 0 ) {
- precision = 1 / 60;
- }
- if ( dotsec === '\'' ) {
- r += ( postdot[0] /
3600 );
- if( postdot[1] > 0 ) {
- precision = ( 1
/ 3600 ) / Math.pow( 10, postdot[1] );
- }
- } else {
- r += postdot[0];
- if( postdot[1] > 0 ) {
- precision = 1 /
Math.pow( 10, postdot[1] );
- }
- }
- if( sign === '-' ) {
- r *= -1;
- }
- return [r, precision];
- } )( pos0, result0[0], result0[1],
result0[4], result0[5], result0[7], result0[8] );
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
-
- function parse_postdot() {
- var result0, result1, result2;
- var pos0, pos1;
-
- pos0 = pos;
- pos1 = pos;
- if (input.charCodeAt(pos) === 46) {
- result0 = ".";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\".\"");
- }
- }
- result0 = result0 !== null ? result0 : "";
- if (result0 !== null) {
- result1 = [];
- if (/^[0-9]/.test(input.charAt(pos))) {
- result2 = input.charAt(pos);
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("[0-9]");
- }
- }
- while (result2 !== null) {
- result1.push(result2);
- if
(/^[0-9]/.test(input.charAt(pos))) {
- result2 =
input.charAt(pos);
- pos++;
- } else {
- result2 = null;
- if (reportFailures ===
0) {
-
matchFailed("[0-9]");
- }
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = ( function( offset, dot,
digits ) {
- if( dot === '' ) {
- return [0, 0];
- }
-
- var t = '.' + digits.join( ''
).toString(),
- r = parseFloat( t );
-
- if( isNaN( r ) ) {
- return [0, 0];
- }
-
- var precision = t.length - 1;
-
- return [r, precision];
- } )( pos0, result0[0], result0[1] );
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
-
- function parse_integer() {
- var result0, result1;
- var pos0;
-
- pos0 = pos;
- result0 = [];
- if (/^[0-9]/.test(input.charAt(pos))) {
- result1 = input.charAt(pos);
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("[0-9]");
- }
- }
- while (result1 !== null) {
- result0.push(result1);
- if (/^[0-9]/.test(input.charAt(pos))) {
- result1 = input.charAt(pos);
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("[0-9]");
- }
- }
- }
- if (result0 !== null) {
- result0 = (function(offset, digits) {
- var r =
parseInt(digits.join(''), 10);
- if ( isNaN( r ) ) {
- return 0;
- }
- return r;
- })(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
-
-
- function cleanupExpected(expected) {
- expected.sort();
-
- var lastExpected = null;
- var cleanExpected = [];
- for (var i = 0; i < expected.length; i++) {
- if (expected[i] !== lastExpected) {
- cleanExpected.push(expected[i]);
- lastExpected = expected[i];
- }
- }
- return cleanExpected;
- }
-
- function computeErrorPosition() {
- /*
- * The first idea was to use |String.split| to
break the input up to the
- * error position along newlines and derive the
line and column from
- * there. However IE's |split| implementation
is so broken that it was
- * enough to prevent it.
- */
-
- var line = 1;
- var column = 1;
- var seenCR = false;
-
- for (var i = 0; i < Math.max(pos,
rightmostFailuresPos); i++) {
- var ch = input.charAt(i);
- if (ch === "\n") {
- if (!seenCR) { line++; }
- column = 1;
- seenCR = false;
- } else if (ch === "\r" || ch ===
"\u2028" || ch === "\u2029") {
- line++;
- column = 1;
- seenCR = true;
- } else {
- column++;
- seenCR = false;
- }
- }
-
- return { line: line, column: column };
- }
-
-
- var result = parseFunctions[startRule]();
-
- /*
- * The parser is now in one of the following three
states:
- *
- * 1. The parser successfully parsed the whole input.
- *
- * - |result !== null|
- * - |pos === input.length|
- * - |rightmostFailuresExpected| may or may not
contain something
- *
- * 2. The parser successfully parsed only a part of the
input.
- *
- * - |result !== null|
- * - |pos < input.length|
- * - |rightmostFailuresExpected| may or may not
contain something
- *
- * 3. The parser did not successfully parse any part of
the input.
- *
- * - |result === null|
- * - |pos === 0|
- * - |rightmostFailuresExpected| contains at least
one failure
- *
- * All code following this comment (including called
functions) must
- * handle these states.
- */
- if (result === null || pos !== input.length) {
- var offset = Math.max(pos,
rightmostFailuresPos);
- var found = offset < input.length ?
input.charAt(offset) : null;
- var errorPosition = computeErrorPosition();
-
- throw new this.SyntaxError(
-
cleanupExpected(rightmostFailuresExpected),
- found,
- offset,
- errorPosition.line,
- errorPosition.column
- );
- }
-
- return result;
- },
-
- /* Returns the parser source code. */
- toSource: function() { return this._source; }
- };
-
- /* Thrown when a parser encounters a syntax error. */
-
- result.SyntaxError = function(expected, found, offset, line, column) {
- function buildMessage(expected, found) {
- var expectedHumanized, foundHumanized;
-
- switch (expected.length) {
- case 0:
- expectedHumanized = "end of input";
- break;
- case 1:
- expectedHumanized = expected[0];
- break;
- default:
- expectedHumanized = expected.slice(0,
expected.length - 1).join(", ")
- + " or "
- + expected[expected.length - 1];
- }
-
- foundHumanized = found ? quote(found) : "end of input";
-
- return "Expected " + expectedHumanized + " but " +
foundHumanized + " found.";
- }
-
- this.name = "SyntaxError";
- this.expected = expected;
- this.found = found;
- this.message = buildMessage(expected, found);
- this.offset = offset;
- this.line = line;
- this.column = column;
- };
-
- result.SyntaxError.prototype = Error.prototype;
-
- return result;
-} )( globeCoordinate );
diff --git
a/DataValues/resources/globeCoordinate.js/tests/globeCoordinate.GlobeCoordinate.tests.js
b/DataValues/resources/globeCoordinate.js/tests/globeCoordinate.GlobeCoordinate.tests.js
index 9b0a875..1fdef91 100644
---
a/DataValues/resources/globeCoordinate.js/tests/globeCoordinate.GlobeCoordinate.tests.js
+++
b/DataValues/resources/globeCoordinate.js/tests/globeCoordinate.GlobeCoordinate.tests.js
@@ -14,16 +14,16 @@
* @type {Object}
*/
var iso6709representations = {
- '0': '+00+000/',
- '-3 +2': '-03+002/',
- '1.1 2': '+0106+002/',
- '90° N 30.10°': '+90+03006/',
- '0° 5\'N, 0° 0\' 10"E': '+0005+0000010/',
- '5\'S': '-05+000/',
- '1\' 1"': '+010001+000/',
- '1\' 1.1"': '+010001.1+000/',
- '89° 59" 59\' 1.123\'': '+8959+0590001.123/',
- '5°\'N 0° 0\' 10.5"W': '+05-0000010.5/'
+ '+00+000/': { latitude: 0, longitude: 0, precision: 1 },
+ '-03+002/': { latitude: -3, longitude: 2, precision: 1 },
+ '+0106+00200/': { latitude: 1.1, longitude: 2, precision: 0.1 },
+ '+900000+0300600/': { latitude: 90, longitude: 30.1, precision:
0.01 },
+ '+000600+0000027/': { latitude: 0.1, longitude: 0.0075,
precision: 1 / 3600 },
+ '-0006+00000/': { latitude: -0.1, longitude: 0, precision: 1 /
60 },
+ '+010001+0000000/': { latitude: 1.00028, longitude: 0,
precision: 1 / 3600 },
+ '+010001.8+0000000.0/': { latitude: 1.0005, longitude: 0,
precision: 1 / 36000 },
+ '+895400.000-0000001.116/': { latitude: 89.9, longitude:
-0.00031, precision: 1 / 3600000 },
+ '+050000.0-0000010.5/': { latitude: 5, longitude: -0.00292,
precision: 1 / 36000 }
};
QUnit.module( 'globeCoordinate.GlobeCoordinate.js' );
@@ -46,15 +46,14 @@
'Trying to instantiate with an invalid value (190° 30"
1.123\') throws an error.'
);
- c = new globeCoordinate.GlobeCoordinate( '1.5 1.5' );
+ assert.throws(
+ function() { c = new globeCoordinate.GlobeCoordinate( {
latitude: 20 } ); },
+ 'Trying to instantiate with an invalid value ({
latitude: 20 }) throws an error.'
+ );
+
+ c = new globeCoordinate.GlobeCoordinate( { latitude: 1.5,
longitude: 1.5, precision: 0.1 } );
// Since most methods are just plain getters, just doing plain
verification:
-
- assert.equal(
- c.getRawInput(),
- '1.5 1.5',
- 'Verified getRawInput()'
- );
assert.equal(
c.getLatitude(),
@@ -127,13 +126,13 @@
QUnit.test( 'iso6709()', function( assert ) {
var c;
- $.each( iso6709representations, function( inputString,
iso6709string ) {
- c = new globeCoordinate.GlobeCoordinate( inputString );
+ $.each( iso6709representations, function( iso6709string, gcDef
) {
+ c = new globeCoordinate.GlobeCoordinate( gcDef );
assert.equal(
c.iso6709(),
iso6709string,
- 'Validated ISO 6709 string for \'' +
inputString + '\': \'' + iso6709string + '\'.'
+ 'Validated ISO 6709 string for \'' +
c.decimalText() + '\': \'' + iso6709string + '\'.'
);
} );
@@ -143,24 +142,24 @@
QUnit.test( 'equals()', function( assert ) {
var c1, c2;
- $.each( iso6709representations, function( inputString1,
iso6709string1 ) {
- c1 = new globeCoordinate.GlobeCoordinate( inputString1
);
+ $.each( iso6709representations, function( iso6709string1,
gcDef1 ) {
+ c1 = new globeCoordinate.GlobeCoordinate( gcDef1 );
- $.each( iso6709representations, function( inputString2,
iso6709string2 ) {
- c2 = new globeCoordinate.GlobeCoordinate(
inputString2 );
+ $.each( iso6709representations, function(
iso6709string2, gcDef ) {
+ c2 = new globeCoordinate.GlobeCoordinate( gcDef
);
- if( inputString1 === inputString2 ) {
+ if( iso6709string1 === iso6709string2 ) {
assert.ok(
c1.equals( c2 ),
- 'Validated equality for \'' +
inputString1 + '\'.'
+ 'Validated equality for \'' +
c1.decimalText() + '\'.'
);
} else {
assert.ok(
!c1.equals( c2 ),
- 'Validated inequality of \'' +
inputString1 + '\' and \'' + inputString2 + '\'.'
+ 'Validated inequality of \'' +
c1.decimalText() + '\' and \'' + c2.decimalText() + '\'.'
);
}
diff --git
a/DataValues/resources/globeCoordinate.js/tests/globeCoordinate.parser.tests.js
b/DataValues/resources/globeCoordinate.js/tests/globeCoordinate.parser.tests.js
deleted file mode 100644
index 2fc547c..0000000
---
a/DataValues/resources/globeCoordinate.js/tests/globeCoordinate.parser.tests.js
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * @since 0.1
- * @file
- * @ingroup globeCoordinate.js
- *
- * @licence GNU GPL v2+
- * @author H. Snater < [email protected] >
- */
-( function( QUnit, $, globeCoordinate ) {
- 'use strict';
-
- /**
- * Valid globe coordinate strings:
- * { <{string} input>: <{number[]} parse result> }
- * @type {Object}
- */
- var valid = {
- '0': [0, 0, 1],
- '-3 +2': [-3, 2, 1],
- '1.1 2': [1.1, 2, 0.1],
- '90° N 30.10°': [90, 30.1, 0.01],
- '0° 5\'N, 0° 0\' 10"E': [0.08333333333333333,
0.002777777777777778, 0.0002777777777777778],
- '0° 5′N, 0° 0′ 10″E': [0.08333333333333333,
0.002777777777777778, 0.0002777777777777778],
- '5\'S': [-5, 0, 1],
- '1\' 1"': [1.0002777777777778, 0, 0.0002777777777777778],
- '1\' 1.1"': [1.0003055555555556, 0, 0.00002777777777777778],
- '190° 30" 1.123\'': [190.5, 1.123, 0.001],
- '5\'N 0\' 10.5"W': [5, -0.002916666666666667,
0.00002777777777777778]
- };
-
- /**
- * Invalid globe coordinate strings.
- * @type {string[]}
- */
- var invalid = [
- 'random string'
- ];
-
- QUnit.module( 'globeCoordinate.parser.js' );
-
- QUnit.test( 'Parsing valid coordinate strings', function( assert ) {
-
- $.each( valid, function( string, expected ) {
-
- assert.deepEqual(
- globeCoordinate.parser.parse( string ),
- expected,
- 'Successfully parsed \'' + string + '\'.'
- );
-
- } );
-
- } );
-
- QUnit.test( 'Parsing invalid coordinate strings', function( assert ) {
-
- $.each( invalid, function( i, string ) {
-
- assert.throws(
- function() { globeCoordinate.parser.parse(
string ); },
- 'Unable to parse \'' + string + '\'.'
- );
-
- } );
-
- } );
-
-}( QUnit, jQuery, globeCoordinate ) );
diff --git a/DataValues/resources/values/GlobeCoordinateValue.js
b/DataValues/resources/values/GlobeCoordinateValue.js
index 0187024..92c9b72 100644
--- a/DataValues/resources/values/GlobeCoordinateValue.js
+++ b/DataValues/resources/values/GlobeCoordinateValue.js
@@ -6,7 +6,7 @@
*
* @author H. Snater < [email protected] >
*/
-( function( dv, $, GlobeCoordinate, globeCoordinateParse ) {
+( function( dv, $, GlobeCoordinate ) {
'use strict';
var PARENT = dv.DataValue,
@@ -103,4 +103,4 @@
dv.registerDataValue( SELF );
-}( dataValues, jQuery, globeCoordinate.GlobeCoordinate,
globeCoordinate.parser.parse ) );
+}( dataValues, jQuery, globeCoordinate.GlobeCoordinate ) );
diff --git a/DataValues/tests/qunit/values/GlobeCoordinateValue.tests.js
b/DataValues/tests/qunit/values/GlobeCoordinateValue.tests.js
index da3bdfe..71cdeeb 100644
--- a/DataValues/tests/qunit/values/GlobeCoordinateValue.tests.js
+++ b/DataValues/tests/qunit/values/GlobeCoordinateValue.tests.js
@@ -32,8 +32,8 @@
*/
getConstructorArguments: function() {
return [
- [ new GlobeCoordinate( '1.5 1.25' ) ],
- [ new GlobeCoordinate( '-50 -20' ) ]
+ [ new GlobeCoordinate( { latitude: 1.5,
longitude: 1.25, precision: 0.01 } ) ],
+ [ new GlobeCoordinate( { latitude: -50,
longitude: -20, precision: 1 } ) ]
];
}
diff --git a/ValueParsers/tests/qunit/parsers/GlobeCoordinateParser.tests.js
b/ValueParsers/tests/qunit/parsers/GlobeCoordinateParser.tests.js
index 17ddd80..b197370 100644
--- a/ValueParsers/tests/qunit/parsers/GlobeCoordinateParser.tests.js
+++ b/ValueParsers/tests/qunit/parsers/GlobeCoordinateParser.tests.js
@@ -35,11 +35,11 @@
return [
[
'1.5, 1.25',
- new dv.GlobeCoordinateValue( new
GlobeCoordinate( '1.5, 1.25' ) )
+ new dv.GlobeCoordinateValue( new
GlobeCoordinate( { latitude: 1.5, longitude: 1.25, precision: 0.01 } ) )
],
[
'-50, -20',
- new dv.GlobeCoordinateValue( new
GlobeCoordinate( '-50, -20' ) )
+ new dv.GlobeCoordinateValue( new
GlobeCoordinate( { latitude: -50, longitude: -20, precision: 1 } ) )
]
];
}
--
To view, visit https://gerrit.wikimedia.org/r/69112
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I811eabdebde6b0c24fca3e0dafc7905e9d678250
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
Gerrit-Reviewer: Daniel Werner <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
