aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/material-parser.js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-03-06 17:02:44 -0800
committerJose Antonio Marquez2012-03-06 17:02:44 -0800
commitfca92904597895675ddd216399cd235f3c5a7cfa (patch)
tree77c30a958c0283a6aa208b93640c6008eeb943e2 /js/lib/rdge/materials/material-parser.js
parentec7cbc95de031d2be667c2a8629a9d63e91f7e1a (diff)
parenteebb7de4d19cddec9c763a073d8cf41d76fe70f7 (diff)
downloadninja-fca92904597895675ddd216399cd235f3c5a7cfa.tar.gz
Merge branch 'refs/heads/FileIO' into FileIO-Build-Candidate
Diffstat (limited to 'js/lib/rdge/materials/material-parser.js')
-rwxr-xr-xjs/lib/rdge/materials/material-parser.js73
1 files changed, 73 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/material-parser.js b/js/lib/rdge/materials/material-parser.js
new file mode 100755
index 00000000..b334c05d
--- /dev/null
+++ b/js/lib/rdge/materials/material-parser.js
@@ -0,0 +1,73 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7var MaterialParser = function MaterialParser( theStr ) {
8
9 this._strBuffer = theStr;
10
11 this.nextValue = function( prop, endKeyArg, advanceBufferArg ) {
12 if (!this._strBuffer) return;
13
14 // make the 2 & 3rd argument optional. default is to advance the string
15 var endKey = "\n", advanceBuffer = true;
16 if (endKeyArg) {
17 endKey = endKeyArg;
18 }
19
20 if (advanceBufferArg) {
21 advanceBuffer = advanceBufferArg;
22 }
23
24 var iStart = this._strBuffer.indexOf( prop );
25 if (iStart < 0) return;
26
27 var iEnd = this._strBuffer.indexOf( endKey, iStart );
28 if (iEnd < 0) throw new Error( "property " + prop + " improperly terminated: " + this._strBuffer);
29
30 iStart += prop.length;
31 var nChars = iEnd - iStart;
32 var rtnStr = this._strBuffer.substr( iStart, nChars );
33
34 if (advanceBuffer) {
35 this._strBuffer = this._strBuffer.substr( iEnd + endKey.length );
36 }
37
38 return rtnStr;
39 };
40
41 this.nextToken = function() {
42 if (!this._strBuffer) return;
43
44 // find the limits
45 var index = this._strBuffer.search( /\S/ ); // first non-whitespace character
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
48
49 var token;
50 if (index > 0) {
51 token = this._strBuffer.slice(0, index);
52 this._strBuffer = this._strBuffer.slice( index );
53 }
54
55 return token;
56 };
57
58 this.advancePastToken = function( token ) {
59 var index = this._strBuffer.indexOf( token );
60 if (index < 0) {
61 console.log( "could not find token: " + token + " in string: " + this._strBuffer );
62 } else {
63 this._strBuffer = this._strBuffer.substr( index + token.length );
64 }
65 }
66
67};
68
69if (typeof exports === "object") {
70 exports.MaterialParser = MaterialParser;
71}
72
73