aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/backup-delete/ParseUtils.js
diff options
context:
space:
mode:
authorJonathan Duran2012-03-06 17:08:55 -0800
committerJonathan Duran2012-03-06 17:08:55 -0800
commitbb6a1d82b2884b410f5859cc0c2cafd380acbe6a (patch)
tree6ec3e960a0c38ce8fd88c9bc17f5227d072ebe76 /js/helper-classes/backup-delete/ParseUtils.js
parent2815adfd7c19b3dff89dc3e1bda9af8d30dca8d6 (diff)
parent2e3943a8f751ec572066f168b58464c24b9f29e5 (diff)
downloadninja-bb6a1d82b2884b410f5859cc0c2cafd380acbe6a.tar.gz
Merge branch 'refs/heads/NINJAmaster' into TimelineUber
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