Changeset 6776
- Timestamp:
- 12/02/06 11:32:46 (2 years ago)
- Files:
-
- 1 modified
-
branches/0.4.1_working/src/cal/textDirectory.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.4.1_working/src/cal/textDirectory.js
r6228 r6776 2 2 dojo.require("dojo.string"); 3 3 4 /* 5 * This class parses a single line from a text/directory file 6 * and returns an object with four named values; name, group, params 7 * and value. name, group and value are strings containing the original 8 * tokens unaltered and values is an array containing name/value pairs 9 * or a single name token packed into arrays. 10 */ 11 dojo.cal.textDirectory.Property = function (line) { 4 dojo.cal.textDirectory.Property = function(/*String*/line){ 5 // summary: parses a single line from an iCalendar text/directory file 6 // and creates an object with four named values; name, group, params 7 // and value. name, group and value are strings containing the original 8 // tokens unaltered and values is an array containing name/value pairs 9 // or a single name token packed into arrays. 10 12 11 // split into name/value pair 13 12 var left = dojo.string.trim(line.substring(0, line.indexOf(':'))); 14 13 var right = dojo.string.trim(line.substr(line.indexOf(':') + 1)); 15 14 16 // sep erate name and paramters15 // separate name and paramters 17 16 var parameters = dojo.string.splitEscaped(left,';'); 18 this.name = parameters[0] 17 this.name = parameters[0]; 19 18 parameters.splice(0, 1); 20 19 21 20 // parse paramters 22 21 this.params = []; 23 for (var i = 0; i < parameters.length; i++) { 24 var arr = parameters[i].split("="); 22 var arr; 23 for(var i = 0; i < parameters.length; i++){ 24 arr = parameters[i].split("="); 25 25 var key = dojo.string.trim(arr[0].toUpperCase()); 26 27 if (arr.length == 1){ this.params.push([key]); continue; }28 26 27 if(arr.length == 1){ this.params.push([key]); continue; } 28 29 29 var values = dojo.string.splitEscaped(arr[1],','); 30 for (var j = 0; j < values.length; j++){31 if (dojo.string.trim(values[j]) != ''){30 for(var j = 0; j < values.length; j++){ 31 if(dojo.string.trim(values[j]) != ''){ 32 32 this.params.push([key, dojo.string.trim(values[j])]); 33 33 } … … 35 35 } 36 36 37 // sep erate group38 if (this.name.indexOf('.') > 0){39 vararr = this.name.split('.');37 // separate group 38 if(this.name.indexOf('.') > 0){ 39 arr = this.name.split('.'); 40 40 this.group = arr[0]; 41 41 this.name = arr[1]; 42 42 } 43 43 44 44 // don't do any parsing, leave to implementation 45 45 this.value = right; … … 47 47 48 48 49 // tokeniser, parses into an array of properties. 50 dojo.cal.textDirectory.tokenise = function (text) { 51 // normlize to one propterty per line and parse 52 var nText = dojo.string.normalizeNewlines(text,"\n"); 53 nText = nText.replace(/\n[ \t]/g, ''); 54 nText = nText.replace(/\x00/g, ''); 55 49 dojo.cal.textDirectory.tokenise = function(/*String*/text){ 50 // summary: parses text into an array of properties. 51 52 // normlize to one property per line and parse 53 var nText = dojo.string.normalizeNewlines(text,"\n"). 54 replace(/\n[ \t]/g, ''). 55 replace(/\x00/g, ''); 56 56 57 var lines = nText.split("\n"); 57 var properties = [] 58 var properties = []; 58 59 59 for (var i = 0; i < lines.length; i++){60 if (dojo.string.trim(lines[i]) == ''){ continue; }60 for(var i = 0; i < lines.length; i++){ 61 if(dojo.string.trim(lines[i]) == ''){ continue; } 61 62 var prop = new dojo.cal.textDirectory.Property(lines[i]); 62 63 properties.push(prop); 63 64 } 64 return properties; 65 return properties; // Array 65 66 }