author | Clipperz <info@clipperz.com> | 2013-01-31 13:42:04 (UTC) |
---|---|---|
committer | Clipperz <info@clipperz.com> | 2013-01-31 13:42:04 (UTC) |
commit | 07d0357beef5d9328a2dd8d07ad7b39c87ac55e4 (patch) (unidiff) | |
tree | f7a4aed8848302db153c2a211f8e58b944eb4c5b /frontend/gamma/js/Clipperz/CSVProcessor.js | |
parent | 767a3dcf48b6ac911c088af5dd7738a728eb6b99 (diff) | |
download | clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.zip clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.gz clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.bz2 |
Updated Copyright claims
- updated reference dates;
- removed reference to Community Edition;
- normalized logging using Clipperz.log[Warn|Error|Debug]
Diffstat (limited to 'frontend/gamma/js/Clipperz/CSVProcessor.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/CSVProcessor.js | 78 |
1 files changed, 38 insertions, 40 deletions
diff --git a/frontend/gamma/js/Clipperz/CSVProcessor.js b/frontend/gamma/js/Clipperz/CSVProcessor.js index 0b18731..1288ed7 100644 --- a/frontend/gamma/js/Clipperz/CSVProcessor.js +++ b/frontend/gamma/js/Clipperz/CSVProcessor.js | |||
@@ -1,346 +1,344 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
9 | 8 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 9 | * Clipperz is free software: you can redistribute it and/or modify it |
11 | it and/or modify it under the terms of the GNU Affero General Public | 10 | under the terms of the GNU Affero General Public License as published |
12 | License as published by the Free Software Foundation, either version | 11 | by the Free Software Foundation, either version 3 of the License, or |
13 | 3 of the License, or (at your option) any later version. | 12 | (at your option) any later version. |
14 | 13 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 14 | * Clipperz is distributed in the hope that it will be useful, but |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
19 | 18 | ||
20 | * You should have received a copy of the GNU Affero General Public | 19 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
22 | <http://www.gnu.org/licenses/>. | ||
23 | 21 | ||
24 | */ | 22 | */ |
25 | 23 | ||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | 25 | ||
28 | 26 | ||
29 | Clipperz.CSVProcessor = function(args) { | 27 | Clipperz.CSVProcessor = function(args) { |
30 | args = args || {}; | 28 | args = args || {}; |
31 | 29 | ||
32 | // this._status = undefined; | 30 | // this._status = undefined; |
33 | // this._error_input= undefined; | 31 | // this._error_input= undefined; |
34 | // this._string = undefined; | 32 | // this._string = undefined; |
35 | // this._fields = undefined; | 33 | // this._fields = undefined; |
36 | 34 | ||
37 | this._quoteChar = args['quoteChar'] ||"\042"; | 35 | this._quoteChar = args['quoteChar'] ||"\042"; |
38 | this._eol = args['eol'] ||""; | 36 | this._eol = args['eol'] ||""; |
39 | this._escapeChar = args['escapeChar'] ||"\042"; | 37 | this._escapeChar = args['escapeChar'] ||"\042"; |
40 | this._separatorChar = args['separatorChar'] ||","; | 38 | this._separatorChar = args['separatorChar'] ||","; |
41 | this._binary = args['binary'] ||false; | 39 | this._binary = args['binary'] ||false; |
42 | this._alwaysQuote = args['alwaysQuote'] ||false; | 40 | this._alwaysQuote = args['alwaysQuote'] ||false; |
43 | 41 | ||
44 | return this; | 42 | return this; |
45 | } | 43 | } |
46 | 44 | ||
47 | //============================================================================= | 45 | //============================================================================= |
48 | 46 | ||
49 | Clipperz.CSVProcessor.prototype = MochiKit.Base.update(null, { | 47 | Clipperz.CSVProcessor.prototype = MochiKit.Base.update(null, { |
50 | 48 | ||
51 | //------------------------------------------------------------------------- | 49 | //------------------------------------------------------------------------- |
52 | 50 | ||
53 | 'quoteChar': function() { | 51 | 'quoteChar': function() { |
54 | return this._quoteChar; | 52 | return this._quoteChar; |
55 | }, | 53 | }, |
56 | 54 | ||
57 | //------------------------------------------------------------------------- | 55 | //------------------------------------------------------------------------- |
58 | 56 | ||
59 | 'eol': function() { | 57 | 'eol': function() { |
60 | return this._eol; | 58 | return this._eol; |
61 | }, | 59 | }, |
62 | 60 | ||
63 | //------------------------------------------------------------------------- | 61 | //------------------------------------------------------------------------- |
64 | 62 | ||
65 | 'escapeChar': function() { | 63 | 'escapeChar': function() { |
66 | return this._escapeChar; | 64 | return this._escapeChar; |
67 | }, | 65 | }, |
68 | 66 | ||
69 | //------------------------------------------------------------------------- | 67 | //------------------------------------------------------------------------- |
70 | 68 | ||
71 | 'separatorChar': function() { | 69 | 'separatorChar': function() { |
72 | return this._separatorChar; | 70 | return this._separatorChar; |
73 | }, | 71 | }, |
74 | 72 | ||
75 | 'setSeparatorChar': function(aValue) { | 73 | 'setSeparatorChar': function(aValue) { |
76 | this._separatorChar = aValue; | 74 | this._separatorChar = aValue; |
77 | }, | 75 | }, |
78 | 76 | ||
79 | //------------------------------------------------------------------------- | 77 | //------------------------------------------------------------------------- |
80 | 78 | ||
81 | 'binary': function() { | 79 | 'binary': function() { |
82 | return this._binary; | 80 | return this._binary; |
83 | }, | 81 | }, |
84 | 82 | ||
85 | //------------------------------------------------------------------------- | 83 | //------------------------------------------------------------------------- |
86 | 84 | ||
87 | 'alwaysQuote': function() { | 85 | 'alwaysQuote': function() { |
88 | return this._alwaysQuote; | 86 | return this._alwaysQuote; |
89 | }, | 87 | }, |
90 | 88 | ||
91 | //------------------------------------------------------------------------- | 89 | //------------------------------------------------------------------------- |
92 | /* | 90 | /* |
93 | 'parse': function(aValue) { | 91 | 'parse': function(aValue) { |
94 | var result; | 92 | var result; |
95 | var lines; | 93 | var lines; |
96 | var parameter; | 94 | var parameter; |
97 | 95 | ||
98 | //MochiKit.Logging.logDebug(">>> CSVProcessor.parse"); | 96 | //Clipperz.logDebug(">>> CSVProcessor.parse"); |
99 | result = []; | 97 | result = []; |
100 | 98 | ||
101 | lines = aValue.replace(/\r?\n/g, "\n").replace(/^\n* /g, "").replace(/\n$/g, "");; | 99 | lines = aValue.replace(/\r?\n/g, "\n").replace(/^\n* /g, "").replace(/\n$/g, "");; |
102 | parameter = { | 100 | parameter = { |
103 | line: lines | 101 | line: lines |
104 | } | 102 | } |
105 | 103 | ||
106 | do { | 104 | do { |
107 | var fields; | 105 | var fields; |
108 | 106 | ||
109 | fields = this.parseLine(parameter); | 107 | fields = this.parseLine(parameter); |
110 | 108 | ||
111 | if (fields != null) { | 109 | if (fields != null) { |
112 | result.push(fields); | 110 | result.push(fields); |
113 | } | 111 | } |
114 | 112 | ||
115 | parameter.line = parameter.line.replace(/^\n* /g, "").replace(/\n$/g, ""); | 113 | parameter.line = parameter.line.replace(/^\n* /g, "").replace(/\n$/g, ""); |
116 | 114 | ||
117 | //MochiKit.Logging.logDebug("line: '" + parameter.line + "'"); | 115 | //Clipperz.logDebug("line: '" + parameter.line + "'"); |
118 | } while (parameter.line != ""); | 116 | } while (parameter.line != ""); |
119 | //MochiKit.Logging.logDebug("--- CSVProcessor.parse - result: " + Clipperz.Base.serializeJSON(result)); | 117 | //Clipperz.logDebug("--- CSVProcessor.parse - result: " + Clipperz.Base.serializeJSON(result)); |
120 | //MochiKit.Logging.logDebug("<<< CSVProcessor.parse"); | 118 | //Clipperz.logDebug("<<< CSVProcessor.parse"); |
121 | 119 | ||
122 | return result; | 120 | return result; |
123 | }, | 121 | }, |
124 | */ | 122 | */ |
125 | //------------------------------------------------------------------------- | 123 | //------------------------------------------------------------------------- |
126 | 124 | ||
127 | 'deferredParse_core': function(aContext) { | 125 | 'deferredParse_core': function(aContext) { |
128 | var deferredResult; | 126 | var deferredResult; |
129 | 127 | ||
130 | if (aContext.line == "") { | 128 | if (aContext.line == "") { |
131 | deferredResult = MochiKit.Async.succeed(aContext.result); | 129 | deferredResult = MochiKit.Async.succeed(aContext.result); |
132 | } else { | 130 | } else { |
133 | var fields; | 131 | var fields; |
134 | 132 | ||
135 | fields = this.parseLine(aContext); | 133 | fields = this.parseLine(aContext); |
136 | if (fields != null) { | 134 | if (fields != null) { |
137 | aContext.result.push(fields); | 135 | aContext.result.push(fields); |
138 | } | 136 | } |
139 | 137 | ||
140 | aContext.line = aContext.line.replace(/^\n*/g, "").replace(/\n$/g, ""); | 138 | aContext.line = aContext.line.replace(/^\n*/g, "").replace(/\n$/g, ""); |
141 | 139 | ||
142 | deferredResult = new Clipperz.Async.Deferred("CVSProcessor.deferredParse_core"); | 140 | deferredResult = new Clipperz.Async.Deferred("CVSProcessor.deferredParse_core"); |
143 | // deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'importProcessorProgressUpdate', {status:'processing', size:aContext.size, progress:(aContext.size - aContext.line.length)}); | 141 | // deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'importProcessorProgressUpdate', {status:'processing', size:aContext.size, progress:(aContext.size - aContext.line.length)}); |
144 | deferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'importProcessorProgressUpdate', {status:'processing', size:aContext.size, progress:(aContext.size - aContext.line.length)}); | 142 | deferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'importProcessorProgressUpdate', {status:'processing', size:aContext.size, progress:(aContext.size - aContext.line.length)}); |
145 | deferredResult.addCallback(MochiKit.Async.wait, 0.2); | 143 | deferredResult.addCallback(MochiKit.Async.wait, 0.2); |
146 | deferredResult.addMethod(this, 'deferredParse_core') | 144 | deferredResult.addMethod(this, 'deferredParse_core') |
147 | deferredResult.callback(aContext); | 145 | deferredResult.callback(aContext); |
148 | } | 146 | } |
149 | 147 | ||
150 | return deferredResult; | 148 | return deferredResult; |
151 | }, | 149 | }, |
152 | 150 | ||
153 | //......................................................................... | 151 | //......................................................................... |
154 | 152 | ||
155 | 'deferredParse': function(aValue) { | 153 | 'deferredParse': function(aValue) { |
156 | var deferredResult; | 154 | var deferredResult; |
157 | var lines; | 155 | var lines; |
158 | var context; | 156 | var context; |
159 | 157 | ||
160 | lines = aValue.replace(/\r?\n/g, "\n").replace(/^\n*/g, "").replace(/\n$/g, ""); | 158 | lines = aValue.replace(/\r?\n/g, "\n").replace(/^\n*/g, "").replace(/\n$/g, ""); |
161 | 159 | ||
162 | context = { | 160 | context = { |
163 | line: lines, | 161 | line: lines, |
164 | size: lines.length, | 162 | size: lines.length, |
165 | result: [] | 163 | result: [] |
166 | } | 164 | } |
167 | 165 | ||
168 | deferredResult = new Clipperz.Async.Deferred("CSVProcessor.deferredParse"); | 166 | deferredResult = new Clipperz.Async.Deferred("CSVProcessor.deferredParse"); |
169 | deferredResult.addMethod(this, 'deferredParse_core'); | 167 | deferredResult.addMethod(this, 'deferredParse_core'); |
170 | deferredResult.callback(context); | 168 | deferredResult.callback(context); |
171 | 169 | ||
172 | return deferredResult; | 170 | return deferredResult; |
173 | }, | 171 | }, |
174 | 172 | ||
175 | //------------------------------------------------------------------------- | 173 | //------------------------------------------------------------------------- |
176 | 174 | ||
177 | 'parseLine': function(aParameter) { | 175 | 'parseLine': function(aParameter) { |
178 | var result; | 176 | var result; |
179 | var palatable; | 177 | var palatable; |
180 | var line; | 178 | var line; |
181 | var processedField; | 179 | var processedField; |
182 | 180 | ||
183 | result = []; | 181 | result = []; |
184 | 182 | ||
185 | do { | 183 | do { |
186 | processedField = this.parseField(aParameter); | 184 | processedField = this.parseField(aParameter); |
187 | if (processedField != null) { | 185 | if (processedField != null) { |
188 | result.push(processedField) | 186 | result.push(processedField) |
189 | }; | 187 | }; |
190 | } while (processedField != null); | 188 | } while (processedField != null); |
191 | 189 | ||
192 | return result; | 190 | return result; |
193 | }, | 191 | }, |
194 | 192 | ||
195 | //------------------------------------------------------------------------- | 193 | //------------------------------------------------------------------------- |
196 | 194 | ||
197 | 'parseField': function(aParameter) { | 195 | 'parseField': function(aParameter) { |
198 | var result; | 196 | var result; |
199 | 197 | ||
200 | var inQuotes; | 198 | var inQuotes; |
201 | var validRegExp; | 199 | var validRegExp; |
202 | var singleQuoteBeginRegexp; | 200 | var singleQuoteBeginRegexp; |
203 | var escapedQuoteBeginRegexp; | 201 | var escapedQuoteBeginRegexp; |
204 | var singleQuoteCommaEndRegexp; | 202 | var singleQuoteCommaEndRegexp; |
205 | var singleQuoteNewLineEndRegexp; | 203 | var singleQuoteNewLineEndRegexp; |
206 | var commaBeginRegexp; | 204 | var commaBeginRegexp; |
207 | var newlineRegexp; | 205 | var newlineRegexp; |
208 | 206 | ||
209 | 207 | ||
210 | singleQuoteBeginRegexp = new RegExp("^" + '\\' + this.quoteChar()); | 208 | singleQuoteBeginRegexp = new RegExp("^" + '\\' + this.quoteChar()); |
211 | escapedQuoteBeginRegexp = new RegExp("^" + '\\' + this.escapeChar() + '\\' + this.quoteChar()); | 209 | escapedQuoteBeginRegexp = new RegExp("^" + '\\' + this.escapeChar() + '\\' + this.quoteChar()); |
212 | singleQuoteCommaEndRegexp= new RegExp("^" + '\\' + this.quoteChar() + '\\' + this.separatorChar()); | 210 | singleQuoteCommaEndRegexp= new RegExp("^" + '\\' + this.quoteChar() + '\\' + this.separatorChar()); |
213 | singleQuoteNewLineEndRegexp= new RegExp("^" + '\\' + this.quoteChar() + "\n"); | 211 | singleQuoteNewLineEndRegexp= new RegExp("^" + '\\' + this.quoteChar() + "\n"); |
214 | commaBeginRegexp = new RegExp("^" + '\\' + this.separatorChar()); | 212 | commaBeginRegexp = new RegExp("^" + '\\' + this.separatorChar()); |
215 | newlineRegexp = new RegExp("^\n"); | 213 | newlineRegexp = new RegExp("^\n"); |
216 | 214 | ||
217 | inQuotes = false; | 215 | inQuotes = false; |
218 | 216 | ||
219 | //MochiKit.Logging.logDebug("#################################### '" + aParameter.line + "'"); | 217 | //Clipperz.logDebug("#################################### '" + aParameter.line + "'"); |
220 | if (aParameter.line == "") { | 218 | if (aParameter.line == "") { |
221 | if (aParameter.isThereAnEmptyFinalField == true) { | 219 | if (aParameter.isThereAnEmptyFinalField == true) { |
222 | aParameter.isThereAnEmptyFinalField = false; | 220 | aParameter.isThereAnEmptyFinalField = false; |
223 | result = ""; | 221 | result = ""; |
224 | } else { | 222 | } else { |
225 | result = null; | 223 | result = null; |
226 | } | 224 | } |
227 | } else { | 225 | } else { |
228 | if (this.binary()) { | 226 | if (this.binary()) { |
229 | validRegexp = /^./; | 227 | validRegexp = /^./; |
230 | // validRegexp = /^[^\\]/; | 228 | // validRegexp = /^[^\\]/; |
231 | } else { | 229 | } else { |
232 | validRegexp = /^[\t\040-\176]/; | 230 | validRegexp = /^[\t\040-\176]/; |
233 | } | 231 | } |
234 | 232 | ||
235 | try { | 233 | try { |
236 | var done; | 234 | var done; |
237 | 235 | ||
238 | done = false; | 236 | done = false; |
239 | result = ""; | 237 | result = ""; |
240 | 238 | ||
241 | while (!done) { | 239 | while (!done) { |
242 | if (aParameter.line.length < 1) { | 240 | if (aParameter.line.length < 1) { |
243 | //MochiKit.Logging.logDebug("---> 1: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 241 | //Clipperz.logDebug("---> 1: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
244 | if (inQuotes == true) { | 242 | if (inQuotes == true) { |
245 | //MochiKit.Logging.logDebug("---> 1.1: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 243 | //Clipperz.logDebug("---> 1.1: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
246 | throw new Error("CSV Parsing error; end of string, missing closing double-quote..."); | 244 | throw new Error("CSV Parsing error; end of string, missing closing double-quote..."); |
247 | } else { | 245 | } else { |
248 | //MochiKit.Logging.logDebug("---> 1.2: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 246 | //Clipperz.logDebug("---> 1.2: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
249 | done = true; | 247 | done = true; |
250 | } | 248 | } |
251 | } else if (escapedQuoteBeginRegexp.test(aParameter.line)) { | 249 | } else if (escapedQuoteBeginRegexp.test(aParameter.line)) { |
252 | //MochiKit.Logging.logDebug("---> 2.1: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 250 | //Clipperz.logDebug("---> 2.1: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
253 | result += this.quoteChar(); | 251 | result += this.quoteChar(); |
254 | aParameter.line = aParameter.line.substr(2, aParameter.line.length - 1); | 252 | aParameter.line = aParameter.line.substr(2, aParameter.line.length - 1); |
255 | //MochiKit.Logging.logDebug("<--- 2.2: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 253 | //Clipperz.logDebug("<--- 2.2: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
256 | } else if (singleQuoteBeginRegexp.test(aParameter.line)) { | 254 | } else if (singleQuoteBeginRegexp.test(aParameter.line)) { |
257 | //MochiKit.Logging.logDebug("---> 3: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 255 | //Clipperz.logDebug("---> 3: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
258 | if (inQuotes == true) { | 256 | if (inQuotes == true) { |
259 | if (aParameter.line.length == 1) { | 257 | if (aParameter.line.length == 1) { |
260 | //MochiKit.Logging.logDebug("---> 3.1: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 258 | //Clipperz.logDebug("---> 3.1: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
261 | aParameter.line = ''; | 259 | aParameter.line = ''; |
262 | done = true; | 260 | done = true; |
263 | } else if (singleQuoteCommaEndRegexp.test(aParameter.line)) { | 261 | } else if (singleQuoteCommaEndRegexp.test(aParameter.line)) { |
264 | //MochiKit.Logging.logDebug("---> 3.3: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 262 | //Clipperz.logDebug("---> 3.3: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
265 | aParameter.line = aParameter.line.substr(2, aParameter.line.length - 1); | 263 | aParameter.line = aParameter.line.substr(2, aParameter.line.length - 1); |
266 | done = true; | 264 | done = true; |
267 | //MochiKit.Logging.logDebug("<--- 3.3: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 265 | //Clipperz.logDebug("<--- 3.3: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
268 | } else if (singleQuoteNewLineEndRegexp.test(aParameter.line)) { | 266 | } else if (singleQuoteNewLineEndRegexp.test(aParameter.line)) { |
269 | aParameter.line = aParameter.line.substr(1, aParameter.line.length - 1); | 267 | aParameter.line = aParameter.line.substr(1, aParameter.line.length - 1); |
270 | done = true; | 268 | done = true; |
271 | } else { | 269 | } else { |
272 | throw new Error("CSV Parsing error; double-quote, followed by undesirable character (bad character sequence)... " + aParameter.line); | 270 | throw new Error("CSV Parsing error; double-quote, followed by undesirable character (bad character sequence)... " + aParameter.line); |
273 | } | 271 | } |
274 | } else { | 272 | } else { |
275 | //MochiKit.Logging.logDebug("---> 4: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 273 | //Clipperz.logDebug("---> 4: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
276 | if (result == "") { | 274 | if (result == "") { |
277 | //MochiKit.Logging.logDebug("---> 4.1: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 275 | //Clipperz.logDebug("---> 4.1: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
278 | inQuotes = true; | 276 | inQuotes = true; |
279 | aParameter.line = aParameter.line.substr(1, aParameter.line.length - 1); | 277 | aParameter.line = aParameter.line.substr(1, aParameter.line.length - 1); |
280 | //MochiKit.Logging.logDebug("<--- 4.1: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 278 | //Clipperz.logDebug("<--- 4.1: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
281 | } else { | 279 | } else { |
282 | throw new Error("CSV Parsing error; double-quote, outside of double-quotes (bad character sequence)..."); | 280 | throw new Error("CSV Parsing error; double-quote, outside of double-quotes (bad character sequence)..."); |
283 | } | 281 | } |
284 | } | 282 | } |
285 | } else if (commaBeginRegexp.test(aParameter.line)) { | 283 | } else if (commaBeginRegexp.test(aParameter.line)) { |
286 | //MochiKit.Logging.logDebug("---> 5: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 284 | //Clipperz.logDebug("---> 5: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
287 | if (inQuotes) { | 285 | if (inQuotes) { |
288 | //MochiKit.Logging.logDebug("---> 5.1: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 286 | //Clipperz.logDebug("---> 5.1: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
289 | result += aParameter.line.substr(0 ,1); | 287 | result += aParameter.line.substr(0 ,1); |
290 | aParameter.line = aParameter.line.substr(1, aParameter.line.length - 1); | 288 | aParameter.line = aParameter.line.substr(1, aParameter.line.length - 1); |
291 | //MochiKit.Logging.logDebug("<--- 5.1: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 289 | //Clipperz.logDebug("<--- 5.1: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
292 | } else { | 290 | } else { |
293 | //MochiKit.Logging.logDebug("---> 5.2: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 291 | //Clipperz.logDebug("---> 5.2: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
294 | aParameter.line = aParameter.line.substr(1, aParameter.line.length - 1); | 292 | aParameter.line = aParameter.line.substr(1, aParameter.line.length - 1); |
295 | if (newlineRegexp.test(aParameter.line) || aParameter.line == "") { | 293 | if (newlineRegexp.test(aParameter.line) || aParameter.line == "") { |
296 | //MochiKit.Logging.logDebug("######"); | 294 | //Clipperz.logDebug("######"); |
297 | aParameter.isThereAnEmptyFinalField = true; | 295 | aParameter.isThereAnEmptyFinalField = true; |
298 | }; | 296 | }; |
299 | done = true; | 297 | done = true; |
300 | //MochiKit.Logging.logDebug("<--- 5.2: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 298 | //Clipperz.logDebug("<--- 5.2: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
301 | } | 299 | } |
302 | } else if (validRegexp.test(aParameter.line)) { | 300 | } else if (validRegexp.test(aParameter.line)) { |
303 | //MochiKit.Logging.logDebug("---> 6: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 301 | //Clipperz.logDebug("---> 6: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
304 | result += aParameter.line.substr(0, 1); | 302 | result += aParameter.line.substr(0, 1); |
305 | aParameter.line = aParameter.line.substr(1, aParameter.line.length - 1); | 303 | aParameter.line = aParameter.line.substr(1, aParameter.line.length - 1); |
306 | //MochiKit.Logging.logDebug("<--- 6: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); | 304 | //Clipperz.logDebug("<--- 6: '" + aParameter.line.replace(/\n/g, "\\n") + "'"); |
307 | } else if (newlineRegexp.test(aParameter.line)) { | 305 | } else if (newlineRegexp.test(aParameter.line)) { |
308 | if (inQuotes == true) { | 306 | if (inQuotes == true) { |
309 | result += aParameter.line.substr(0 ,1); | 307 | result += aParameter.line.substr(0 ,1); |
310 | aParameter.line = aParameter.line.substr(1, aParameter.line.length - 1); | 308 | aParameter.line = aParameter.line.substr(1, aParameter.line.length - 1); |
311 | } else { | 309 | } else { |
312 | if (result == "") { | 310 | if (result == "") { |
313 | if (aParameter.isThereAnEmptyFinalField == true) { | 311 | if (aParameter.isThereAnEmptyFinalField == true) { |
314 | aParameter.isThereAnEmptyFinalField = false; | 312 | aParameter.isThereAnEmptyFinalField = false; |
315 | } else { | 313 | } else { |
316 | result = null; | 314 | result = null; |
317 | } | 315 | } |
318 | } | 316 | } |
319 | 317 | ||
320 | done = true; | 318 | done = true; |
321 | } | 319 | } |
322 | } else { | 320 | } else { |
323 | throw new Error("CSV Parsing error; an undesirable character... '" + aParameter.line.substr(0,1) + "'"); | 321 | throw new Error("CSV Parsing error; an undesirable character... '" + aParameter.line.substr(0,1) + "'"); |
324 | } | 322 | } |
325 | } | 323 | } |
326 | } catch(exception) { | 324 | } catch(exception) { |
327 | MochiKit.Logging.logError(exception.message); | 325 | Clipperz.logError(exception.message); |
328 | // result = null; | 326 | // result = null; |
329 | throw exception; | 327 | throw exception; |
330 | } | 328 | } |
331 | } | 329 | } |
332 | 330 | ||
333 | //if (result != null) { | 331 | //if (result != null) { |
334 | //MochiKit.Logging.logDebug("<=== result: '" + result.replace(/\n/g, "\\n") + "'"); | 332 | //Clipperz.logDebug("<=== result: '" + result.replace(/\n/g, "\\n") + "'"); |
335 | //} else { | 333 | //} else { |
336 | //MochiKit.Logging.logDebug("<=== result: NULL"); | 334 | //Clipperz.logDebug("<=== result: NULL"); |
337 | //} | 335 | //} |
338 | 336 | ||
339 | return result; | 337 | return result; |
340 | }, | 338 | }, |
341 | 339 | ||
342 | //------------------------------------------------------------------------- | 340 | //------------------------------------------------------------------------- |
343 | __syntaxFix__: "syntax fix" | 341 | __syntaxFix__: "syntax fix" |
344 | }); | 342 | }); |
345 | 343 | ||
346 | 344 | ||