| 
									
										
										
										
											2014-04-03 22:51:54 +00:00
										 |  |  | var attregexg=/([\w:]+)=((?:")([^"]*)(?:")|(?:')([^']*)(?:'))/g; | 
					
						
							|  |  |  | var attregex=/([\w:]+)=((?:")(?:[^"]*)(?:")|(?:')(?:[^']*)(?:'))/; | 
					
						
							| 
									
										
										
										
											2013-05-02 16:59:27 +00:00
										 |  |  | function parsexmltag(tag) { | 
					
						
							|  |  |  | 	var words = tag.split(/\s+/); | 
					
						
							|  |  |  | 	var z = {'0': words[0]}; | 
					
						
							|  |  |  | 	if(words.length === 1) return z; | 
					
						
							| 
									
										
										
										
											2014-04-03 22:51:54 +00:00
										 |  |  | 	(tag.match(attregexg) || []).map(function(x){ | 
					
						
							|  |  |  | 		var y=x.match(attregex); | 
					
						
							|  |  |  | 		y[1] = y[1].replace(/xmlns:/,"xmlns"); | 
					
						
							|  |  |  | 		z[y[1].replace(/^[a-zA-Z]*:/,"")] = y[2].substr(1,y[2].length-2); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2013-05-02 16:59:27 +00:00
										 |  |  | 	return z; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-29 06:00:09 +00:00
										 |  |  | function evert(obj) { | 
					
						
							| 
									
										
										
										
											2014-01-28 16:38:02 +00:00
										 |  |  | 	var o = {}; | 
					
						
							|  |  |  | 	Object.keys(obj).forEach(function(k) { if(obj.hasOwnProperty(k)) o[obj[k]] = k; }); | 
					
						
							|  |  |  | 	return o; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 16:59:27 +00:00
										 |  |  | var encodings = { | 
					
						
							|  |  |  | 	'"': '"', | 
					
						
							|  |  |  | 	''': "'", | 
					
						
							|  |  |  | 	'>': '>', | 
					
						
							|  |  |  | 	'<': '<', | 
					
						
							|  |  |  | 	'&': '&' | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2014-01-29 06:00:09 +00:00
										 |  |  | var rencoding = evert(encodings); | 
					
						
							| 
									
										
										
										
											2014-01-28 16:38:02 +00:00
										 |  |  | var rencstr = "&<>'\"".split(""); | 
					
						
							| 
									
										
										
										
											2014-01-29 06:00:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 16:59:27 +00:00
										 |  |  | // TODO: CP remap (need to read file version to determine OS)
 | 
					
						
							|  |  |  | function unescapexml(text){ | 
					
						
							|  |  |  | 	var s = text + ''; | 
					
						
							|  |  |  | 	for(var y in encodings) s = s.replace(new RegExp(y,'g'), encodings[y]); | 
					
						
							|  |  |  | 	return s.replace(/_x([0-9a-fA-F]*)_/g,function(m,c) {return _chr(parseInt(c,16));}); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-28 16:38:02 +00:00
										 |  |  | function escapexml(text){ | 
					
						
							|  |  |  | 	var s = text + ''; | 
					
						
							|  |  |  | 	rencstr.forEach(function(y){s=s.replace(new RegExp(y,'g'), rencoding[y]);}); | 
					
						
							|  |  |  | 	return s; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 16:59:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | function parsexmlbool(value, tag) { | 
					
						
							|  |  |  | 	switch(value) { | 
					
						
							|  |  |  | 		case '0': case 0: case 'false': case 'FALSE': return false; | 
					
						
							|  |  |  | 		case '1': case 1: case 'true': case 'TRUE': return true; | 
					
						
							|  |  |  | 		default: throw "bad boolean value " + value + " in "+(tag||"?"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var utf8read = function(orig) { | 
					
						
							| 
									
										
										
										
											2014-02-22 21:36:28 +00:00
										 |  |  | 	var out = [], i = 0, c = 0, c1 = 0, c2 = 0, c3 = 0; | 
					
						
							| 
									
										
										
										
											2013-05-02 16:59:27 +00:00
										 |  |  | 	while (i < orig.length) { | 
					
						
							|  |  |  | 		c = orig.charCodeAt(i++); | 
					
						
							| 
									
										
										
										
											2014-02-22 21:36:28 +00:00
										 |  |  | 		if (c < 128) out.push(_chr(c)); | 
					
						
							| 
									
										
										
										
											2013-05-02 16:59:27 +00:00
										 |  |  | 		else { | 
					
						
							|  |  |  | 			c2 = orig.charCodeAt(i++); | 
					
						
							| 
									
										
										
										
											2014-02-22 21:36:28 +00:00
										 |  |  | 			if (c>191 && c<224) out.push(_chr((c & 31) << 6 | c2 & 63)); | 
					
						
							| 
									
										
										
										
											2013-05-02 16:59:27 +00:00
										 |  |  | 			else { | 
					
						
							|  |  |  | 				c3 = orig.charCodeAt(i++); | 
					
						
							| 
									
										
										
										
											2014-02-22 21:36:28 +00:00
										 |  |  | 				out.push(_chr((c & 15) << 12 | (c2 & 63) << 6 | c3 & 63)); | 
					
						
							| 
									
										
										
										
											2013-05-02 16:59:27 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-22 21:36:28 +00:00
										 |  |  | 	return out.join(""); | 
					
						
							| 
									
										
										
										
											2013-05-02 16:59:27 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // matches <foo>...</foo> extracts content
 | 
					
						
							| 
									
										
										
										
											2014-04-15 09:04:03 +00:00
										 |  |  | function matchtag(f,g) {return new RegExp('<(?:\\w+:)?'+f+'(?: xml:space="preserve")?(?:[^>]*)>([^\u2603]*)</(?:\\w+:)?'+f+'>',(g||"")+"m");} | 
					
						
							| 
									
										
										
										
											2013-05-02 16:59:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | function parseVector(data) { | 
					
						
							|  |  |  | 	var h = parsexmltag(data); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-06 06:05:32 +00:00
										 |  |  | 	var matches = data.match(new RegExp("<vt:" + h.baseType + ">(.*?)</vt:" + h.baseType + ">", 'g'))||[]; | 
					
						
							| 
									
										
										
										
											2013-05-02 16:59:27 +00:00
										 |  |  | 	if(matches.length != h.size) throw "unexpected vector length " + matches.length + " != " + h.size; | 
					
						
							|  |  |  | 	var res = []; | 
					
						
							|  |  |  | 	matches.forEach(function(x) { | 
					
						
							|  |  |  | 		var v = x.replace(/<[/]?vt:variant>/g,"").match(/<vt:([^>]*)>(.*)</); | 
					
						
							|  |  |  | 		res.push({v:v[2], t:v[1]}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function isval(x) { return typeof x !== "undefined" && x !== null; } |