aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/backup-delete/ParseUtils.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-03-06 14:09:44 -0800
committerNivesh Rajbhandari2012-03-06 14:09:44 -0800
commit792793cd3991032b4840ade67f98ae8eae2d30a0 (patch)
tree69d3df003d2bb58fa1ab562fbd1058ff91851f01 /js/helper-classes/backup-delete/ParseUtils.js
parent2346d8ab9db06573d8672c64988c46b6c672e015 (diff)
parent1cd89d4d06e3a8f2c221628b19cf26a2c69f5d3f (diff)
downloadninja-792793cd3991032b4840ade67f98ae8eae2d30a0.tar.gz
Merge branch 'refs/heads/ninja-internal' into WebGLFixes
Diffstat (limited to 'js/helper-classes/backup-delete/ParseUtils.js')
-rwxr-xr-xjs/helper-classes/backup-delete/ParseUtils.js84
1 files changed, 84 insertions, 0 deletions
diff --git a/js/helper-classes/backup-delete/ParseUtils.js b/js/helper-classes/backup-delete/ParseUtils.js
new file mode 100755
index 00000000..556253e9
--- /dev/null
+++ b/js/helper-classes/backup-delete/ParseUtils.js
@@ -0,0 +1,84 @@
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
7///////////////////////////////////////////////////////////////////////
8// Class Utils
9// Vector Utility functions
10///////////////////////////////////////////////////////////////////////
11function ParseUtils( theStr )
12{
13 ///////////////////////////////////////////////////////////////////////
14 // Instance variables
15 ///////////////////////////////////////////////////////////////////////
16 this._strBuffer = theStr;
17
18 ///////////////////////////////////////////////////////////////////////
19 // Property accessors
20 ///////////////////////////////////////////////////////////////////////
21 this.getBuffer = function() { return this._strBuffer; }
22 this.setBuffer = function(b) { this._strBuffer = b; }
23
24 ///////////////////////////////////////////////////////////////////////
25 // Methods
26 ///////////////////////////////////////////////////////////////////////
27 this.nextValue = function( prop, endKeyArg, advanceBufferArg )
28 {
29 if (!this._strBuffer) return;
30
31 // make the 2 & 3rd argument optional. default is to advance the string
32 var endKey = "\n", advanceBuffer = true;
33 if (endKeyArg)
34 endKey = endKeyArg;
35 if (advanceBufferArg)
36 advanceBuffer = advanceBufferArg;
37
38 var iStart = this._strBuffer.indexOf( prop );
39 if (iStart < 0) return;
40
41 var iEnd = this._strBuffer.indexOf( endKey, iStart );
42 if (iEnd < 0) throw new Error( "property " + prop + " improperly terminated: " + this._strBuffer);
43
44 iStart += prop.length;
45 var nChars = iEnd - iStart;
46 var rtnStr = this._strBuffer.substr( iStart, nChars );
47
48 if (advanceBuffer)
49 this._strBuffer = this._strBuffer.substr( iEnd + endKey.length );
50
51 return rtnStr;
52 }
53
54 this.nextToken = function()
55 {
56 if (!this._strBuffer) return;
57
58 // find the limits
59 var index = this._strBuffer.search( /\S/ ); // first non-whitespace character
60 if (index > 0) this._strBuffer = this._strBuffer.slice(index);
61 index = this._strBuffer.search( /\s/ ); // first whitespace character marking the end of the token
62
63 var token;
64 if (index > 0)
65 {
66 token = this._strBuffer.slice(0, index);
67 this._strBuffer = this._strBuffer.slice( index );
68 }
69
70 return token;
71 }
72
73 this.advancePastToken = function( token )
74 {
75 var index = this._strBuffer.indexOf( token );
76 if (index < 0)
77 console.log( "could not find token: " + token + " in string: " + this._strBuffer );
78 else
79 this._strBuffer = this._strBuffer.substr( index + token.length );
80 }
81
82}
83
84