diff options
author | Jonathan Duran | 2012-03-06 17:08:55 -0800 |
---|---|---|
committer | Jonathan Duran | 2012-03-06 17:08:55 -0800 |
commit | bb6a1d82b2884b410f5859cc0c2cafd380acbe6a (patch) | |
tree | 6ec3e960a0c38ce8fd88c9bc17f5227d072ebe76 /js/lib/rdge/materials/material-parser.js | |
parent | 2815adfd7c19b3dff89dc3e1bda9af8d30dca8d6 (diff) | |
parent | 2e3943a8f751ec572066f168b58464c24b9f29e5 (diff) | |
download | ninja-bb6a1d82b2884b410f5859cc0c2cafd380acbe6a.tar.gz |
Merge branch 'refs/heads/NINJAmaster' into TimelineUber
Diffstat (limited to 'js/lib/rdge/materials/material-parser.js')
-rwxr-xr-x | js/lib/rdge/materials/material-parser.js | 73 |
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> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No 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 | |||
7 | var 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 | |||
69 | if (typeof exports === "object") { | ||
70 | exports.MaterialParser = MaterialParser; | ||
71 | } | ||
72 | |||
73 | |||