Changeset 44
- Timestamp:
- 03/02/06 17:49:37 (3 years ago)
- Files:
-
- trunk/jsolait/jsolait.js (modified) (4 diffs)
- trunk/jsolait/lib/codecs.js (modified) (2 diffs)
- trunk/jsolait/lib/jsonrpc.js (modified) (6 diffs)
- trunk/jsolait/lib/net/sockets.js (modified) (1 diff)
- trunk/jsolait/lib/operators.js (modified) (1 diff)
- trunk/jsolait/lib/strings.js (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/jsolait/jsolait.js
r43 r44 21 21 /** 22 22 The main jsolait script. 23 It provides the core functionalities for creating classes, modules and for importing modules.23 It provides the core functionalities for creating classes, modules and for importing modules. 24 24 25 25 @author Jan-Klaas Kollhof … … 227 227 /** 228 228 Returns a string representation of an object. 229 The difference to230 229 @param obj The object to return a string repr. of. 231 230 @return A string repr. the object. 232 231 **/ 233 str = function(obj){ 234 return "" + obj; 232 str = String; 233 234 /** 235 Return a String containing a printable representation of an object which can be used with eval() to create an equal object. 236 Objects can cosutumize the the value being returned by repr(obj) by providing a obj.__repr__() method which is called by repr(obj). 237 @param obj The object to create a repr. String from. 238 @return A representation of the object. 239 **/ 240 repr = function(obj){ 241 if(obj == null){ 242 return null; 243 }else if(obj.__repr__){ 244 return obj.__repr__(); 245 }else{ 246 switch(typeof obj){ 247 case "string": 248 obj = obj.replace(/\\/g,"\\\\").replace(/\"/g,"\\\"").replace(/\n/g, "\\n").replace(/\r/g,"\\r"); 249 return '"' + obj + '"'; 250 case "boolean":case"number": 251 return "" + obj; 252 case "object": 253 var out = []; 254 if(obj == null){ 255 return "null"; 256 }else if(obj instanceof Array){ 257 for(var i=0;i<obj.length;i++){ 258 out.push(repr(obj[i])); 259 } 260 return "[" + out.join(",") + "]"; 261 }else if(obj instanceof Object){ 262 for(var key in obj){ 263 out.push(repr(key) + ":" + repr(obj[key])); 264 } 265 return "{" + out.join(",") + "}"; 266 } 267 } 268 } 235 269 }; 236 270 … … 546 580 */ 547 581 mod.loadURI=function(uri, headers) { 548 //if callback is defined then the operation is done async549 582 headers = (headers !== undefined) ? headers : []; 550 //setup the request551 583 try{ 552 var xmlhttp = getHTTP();584 var xmlhttp = getHTTP(); 553 585 xmlhttp.open("GET", uri, false); 554 586 for(var i=0;i< headers.length;i++){ … … 961 993 return a.join(this); 962 994 }; 963 964 995 }); 965 996 trunk/jsolait/lib/codecs.js
r29 r44 29 29 */ 30 30 Module("codecs", "$Revision$", function(mod){ 31 31 32 /** 32 33 Returns all all available encoders. … … 170 171 }; 171 172 172 mod.__main__=function(){ 173 }; 173 174 String.prototype.encode_lzw=function(){ 175 var dict = {}; 176 var data = (this + "").split(""); 177 var out=[]; 178 var currChar; 179 var phrase = data[0]; 180 var code = 256; 181 182 for(var i=1;i<data.length;i++){ 183 currChar = data[i]; 184 if(dict[phrase + currChar] != null){ 185 phrase += currChar; 186 }else{ 187 out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0)); 188 dict[phrase + currChar] = code; 189 code++; 190 phrase=currChar; 191 } 192 } 193 out.push( phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0)); 194 for(var i=0;i<out.length;i++){ 195 196 out[i] = String.fromCharCode(out[i]); 197 } 198 return out.join(""); 199 }; 200 201 String.prototype.decode_lzw=function(){ 202 var dict={}; 203 var data = (this + "").split(""); 204 var currChar = data[0]; 205 var oldPhrase = currChar; 206 var out = [currChar]; 207 var code = 256; 208 var phrase; 209 for(var i=1;i<data.length;i++){ 210 var currCode = data[i].charCodeAt(0); 211 if(currCode < 256){ 212 phrase = data[i]; 213 }else{ 214 phrase = dict[currCode] ? dict[currCode] : (oldPhrase + currChar); 215 } 216 out.push(phrase); 217 currChar = phrase.charAt(0); 218 dict[code] = oldPhrase + currChar; 219 code ++; 220 oldPhrase = phrase; 221 } 222 return out.join(""); 223 }; 224 174 225 }); trunk/jsolait/lib/jsonrpc.js
r41 r44 1 1 /* 2 Copyright (c) 2005 Jan-Klaas Kollhof2 Copyright (c) 2005-2006 Jan-Klaas Kollhof 3 3 4 4 This file is part of the JavaScript o lait library(jsolait). … … 25 25 @lastchangedby $LastChangedBy$ 26 26 @lastchangeddate $Date$ 27 * /27 **/ 28 28 Module("jsonrpc","$Revision$", function(mod){ 29 29 var urllib = imprt("urllib"); … … 75 75 }); 76 76 77 77 78 78 /** 79 79 Marshalls an object to JSON.(Converts an object into JSON conforming source.) … … 413 413 }); 414 414 415 416 415 mod.RPCMethod=Class(function(publ,supr){ 417 416 publ.__init__=function(name,proxy){ … … 442 441 this._pendingRequests={}; 443 442 }; 444 445 443 446 444 /** … … 554 552 }); 555 553 556 557 554 558 555 /** 559 556 Converts a String to JSON. trunk/jsolait/lib/net/sockets.js
r42 r44 115 115 }; 116 116 117 mod.isReady = function(){ 118 return flashSocketProvider != null; 119 }; 117 120 }); trunk/jsolait/lib/operators.js
r29 r44 19 19 */ 20 20 21 /** 22 Module providing functions implementing operators. 23 24 @creator Jan-Klaas Kollhof 25 @created 2005-12-30 26 @lastchangedby $LastChangedBy: Jan-Klaas Kollhof $ 27 @lastchangeddate $Date: 2006-01-30 20:52:35 +0000 (Mon, 30 Jan 2006) $ 28 **/ 21 29 Module("operators", "$Revision: 20 $", function(mod){ 22 30
