aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/material-parser.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-03-12 16:25:28 -0700
committerNivesh Rajbhandari2012-03-12 16:25:28 -0700
commit5fb358d9e80a364d5f300d60b7a9fe0f773741e7 (patch)
tree2c4d5292b19c91697dffb542f369ec9dcb340f77 /js/lib/rdge/materials/material-parser.js
parent5f9b67be3b8bdb391d021103c6bcee6be2f6cdf4 (diff)
parent69d90467865a1384725b2301901be2180c5a841f (diff)
downloadninja-5fb358d9e80a364d5f300d60b7a9fe0f773741e7.tar.gz
Merge branch 'refs/heads/ninja-internal' into ToolFixes
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