aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/material-parser.js
diff options
context:
space:
mode:
authorJonathan Duran2012-04-05 08:09:18 -0700
committerJonathan Duran2012-04-05 08:09:18 -0700
commite186c49247689b5c2df6125037e2473636701d17 (patch)
treee626b006027949f87b5aa1e76eb0ed719adb99bb /js/lib/rdge/materials/material-parser.js
parent135c5257e2a4d5f1b25f62758c6783fd2ebe5e19 (diff)
parent17ca01f54591187f5c0812c0fd2cb7260afa9639 (diff)
downloadninja-e186c49247689b5c2df6125037e2473636701d17.tar.gz
Merge branch 'refs/heads/NINJAmaster' into TimelineUber
Diffstat (limited to 'js/lib/rdge/materials/material-parser.js')
-rwxr-xr-xjs/lib/rdge/materials/material-parser.js81
1 files changed, 40 insertions, 41 deletions
diff --git a/js/lib/rdge/materials/material-parser.js b/js/lib/rdge/materials/material-parser.js
index b334c05d..c078c3af 100755
--- a/js/lib/rdge/materials/material-parser.js
+++ b/js/lib/rdge/materials/material-parser.js
@@ -4,66 +4,65 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */ 5</copyright> */
6 6
7var MaterialParser = function MaterialParser( theStr ) { 7var MaterialParser = function MaterialParser(theStr) {
8 8
9 this._strBuffer = theStr; 9 this._strBuffer = theStr;
10 10
11 this.nextValue = function( prop, endKeyArg, advanceBufferArg ) { 11 this.nextValue = function (prop, endKeyArg, advanceBufferArg) {
12 if (!this._strBuffer) return; 12 if (!this._strBuffer) return;
13 13
14 // make the 2 & 3rd argument optional. default is to advance the string 14 // make the 2 & 3rd argument optional. default is to advance the string
15 var endKey = "\n", advanceBuffer = true; 15 var endKey = "\n", advanceBuffer = true;
16 if (endKeyArg) { 16 if (endKeyArg) {
17 endKey = endKeyArg; 17 endKey = endKeyArg;
18 } 18 }
19 19
20 if (advanceBufferArg) { 20 if (advanceBufferArg) {
21 advanceBuffer = advanceBufferArg; 21 advanceBuffer = advanceBufferArg;
22 } 22 }
23 23
24 var iStart = this._strBuffer.indexOf( prop ); 24 var iStart = this._strBuffer.indexOf(prop);
25 if (iStart < 0) return; 25 if (iStart < 0) return;
26 26
27 var iEnd = this._strBuffer.indexOf( endKey, iStart ); 27 var iEnd = this._strBuffer.indexOf(endKey, iStart);
28 if (iEnd < 0) throw new Error( "property " + prop + " improperly terminated: " + this._strBuffer); 28 if (iEnd < 0) throw new Error("property " + prop + " improperly terminated: " + this._strBuffer);
29 29
30 iStart += prop.length; 30 iStart += prop.length;
31 var nChars = iEnd - iStart; 31 var nChars = iEnd - iStart;
32 var rtnStr = this._strBuffer.substr( iStart, nChars ); 32 var rtnStr = this._strBuffer.substr(iStart, nChars);
33 33
34 if (advanceBuffer) { 34 if (advanceBuffer) {
35 this._strBuffer = this._strBuffer.substr( iEnd + endKey.length ); 35 this._strBuffer = this._strBuffer.substr(iEnd + endKey.length);
36 } 36 }
37 37
38 return rtnStr; 38 return rtnStr;
39 }; 39 };
40 40
41 this.nextToken = function() { 41 this.nextToken = function () {
42 if (!this._strBuffer) return; 42 if (!this._strBuffer) return;
43 43
44 // find the limits 44 // find the limits
45 var index = this._strBuffer.search( /\S/ ); // first non-whitespace character 45 var index = this._strBuffer.search(/\S/); // first non-whitespace character
46 if (index > 0) this._strBuffer = this._strBuffer.slice(index); 46 if (index > 0) this._strBuffer = this._strBuffer.slice(index);
47 index = this._strBuffer.search( /\s/ ); // first whitespace character marking the end of the token 47 index = this._strBuffer.search(/\s/); // first whitespace character marking the end of the token
48 48
49 var token; 49 var token;
50 if (index > 0) { 50 if (index > 0) {
51 token = this._strBuffer.slice(0, index); 51 token = this._strBuffer.slice(0, index);
52 this._strBuffer = this._strBuffer.slice( index ); 52 this._strBuffer = this._strBuffer.slice(index);
53 } 53 }
54 54
55 return token; 55 return token;
56 }; 56 };
57 57
58 this.advancePastToken = function( token ) { 58 this.advancePastToken = function (token) {
59 var index = this._strBuffer.indexOf( token ); 59 var index = this._strBuffer.indexOf(token);
60 if (index < 0) { 60 if (index < 0) {
61 console.log( "could not find token: " + token + " in string: " + this._strBuffer ); 61 console.log("could not find token: " + token + " in string: " + this._strBuffer);
62 } else { 62 } else {
63 this._strBuffer = this._strBuffer.substr( index + token.length ); 63 this._strBuffer = this._strBuffer.substr(index + token.length);
64 } 64 }
65 } 65 };
66
67}; 66};
68 67
69if (typeof exports === "object") { 68if (typeof exports === "object") {