| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
String.ANUMPATTERN = /[^a-zA-Z0-9]/; |
|---|
| 19 |
String.APATTERN = /[^a-zA-Z]/; |
|---|
| 20 |
String.NUMPATTERN = /[^0-9]/; |
|---|
| 21 |
String.FILEPATTERN = /[^a-zA-Z0-9-_\. ]/; |
|---|
| 22 |
String.HEXPATTERN = /[^a-fA-F0-9]/; |
|---|
| 23 |
String.EMAILPATTERN = /^.+@.+\.[a-zA-Z]+$/; |
|---|
| 24 |
String.URLPATTERN = /^([^:]*):\/\/+(?:([^\/]*):)?(?:([^\/]*)@)?([\w\-_.]*[^.])(\/[^?]*)?(?:\?(.*))?$/; |
|---|
| 25 |
String.LEFT = -1 |
|---|
| 26 |
String.BALANCE = 0 |
|---|
| 27 |
String.RIGHT = 1 |
|---|
| 28 |
String.ISOFORMAT = "yyyy-MM-dd'T'HH:mm:ssZ"; |
|---|
| 29 |
String.SPACE = " "; |
|---|
| 30 |
String.EMPTY = ""; |
|---|
| 31 |
String.NULL = String.EMPTY; |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
String.prototype.isDateFormat = function() { |
|---|
| 45 |
try { |
|---|
| 46 |
new java.text.SimpleDateFormat(this); |
|---|
| 47 |
return true; |
|---|
| 48 |
} catch (err) { |
|---|
| 49 |
return false; |
|---|
| 50 |
} |
|---|
| 51 |
}; |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
String.prototype.toDate = function(format, timezone) { |
|---|
| 62 |
var sdf = res.data._dateformat; |
|---|
| 63 |
if (!sdf) { |
|---|
| 64 |
sdf = new java.text.SimpleDateFormat(format); |
|---|
| 65 |
res.data._dateformat = sdf; |
|---|
| 66 |
} else if (format != sdf.toPattern()) |
|---|
| 67 |
sdf.applyPattern(format); |
|---|
| 68 |
if (timezone && timezone != sdf.getTimeZone()) |
|---|
| 69 |
sdf.setTimeZone(timezone); |
|---|
| 70 |
try { |
|---|
| 71 |
return new Date(sdf.parse(this).getTime()); |
|---|
| 72 |
} catch (err) { |
|---|
| 73 |
return null; |
|---|
| 74 |
} |
|---|
| 75 |
}; |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
String.prototype.isUrl = function() { |
|---|
| 86 |
if (String.URLPATTERN.test(this)) |
|---|
| 87 |
return true; |
|---|
| 88 |
try { |
|---|
| 89 |
return new java.net.URL(this); |
|---|
| 90 |
} catch (err) { |
|---|
| 91 |
return false; |
|---|
| 92 |
} |
|---|
| 93 |
return true; |
|---|
| 94 |
}; |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
String.prototype.isFileName = function() { |
|---|
| 103 |
return !String.FILEPATTERN.test(this); |
|---|
| 104 |
}; |
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
String.prototype.toFileName = function() { |
|---|
| 113 |
return this.replace(new RegExp(String.FILEPATTERN.source, "g"), String.NULL); |
|---|
| 114 |
}; |
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
String.prototype.isHexColor = function() { |
|---|
| 124 |
var str = this; |
|---|
| 125 |
if (this.indexOf("#") == 0) |
|---|
| 126 |
str = this.substring(1); |
|---|
| 127 |
if (str.length != 6) |
|---|
| 128 |
return false; |
|---|
| 129 |
return !String.HEXPATTERN.test(str); |
|---|
| 130 |
}; |
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
String.prototype.toHexColor = function() { |
|---|
| 140 |
if (this.startsWith("rgb")) { |
|---|
| 141 |
res.push(); |
|---|
| 142 |
var col = this.replace(/[^0-9,]/g, String.NULL); |
|---|
| 143 |
var parts = col.split(","); |
|---|
| 144 |
for (var i in parts) { |
|---|
| 145 |
var num = parseInt(parts[i], 10); |
|---|
| 146 |
var hex = num.toString(16); |
|---|
| 147 |
res.write(hex.pad("0", 2, String.LEFT)); |
|---|
| 148 |
} |
|---|
| 149 |
return res.pop(); |
|---|
| 150 |
} |
|---|
| 151 |
var col = this.replace(new RegExp(String.HEXPATTERN.source), String.NULL); |
|---|
| 152 |
return col.toLowerCase().pad("0", 6, String.LEFT); |
|---|
| 153 |
}; |
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
String.prototype.isAlphanumeric = function() { |
|---|
| 162 |
if (!this.length) |
|---|
| 163 |
return false; |
|---|
| 164 |
return !String.ANUMPATTERN.test(this); |
|---|
| 165 |
}; |
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
String.prototype.toAlphanumeric = function() { |
|---|
| 174 |
return this.replace(new RegExp(String.ANUMPATTERN.source, "g"), String.NULL); |
|---|
| 175 |
}; |
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
String.prototype.isAlpha = function() { |
|---|
| 184 |
if (!this.length) |
|---|
| 185 |
return false; |
|---|
| 186 |
return !String.APATTERN.test(this); |
|---|
| 187 |
}; |
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
String.prototype.isNumeric = function() { |
|---|
| 196 |
if (!this.length) |
|---|
| 197 |
return false; |
|---|
| 198 |
return !String.NUMPATTERN.test(this); |
|---|
| 199 |
}; |
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
String.prototype.capitalize = function(limit) { |
|---|
| 208 |
if (limit == null) |
|---|
| 209 |
limit = 1; |
|---|
| 210 |
var head = this.substring(0, limit); |
|---|
| 211 |
var tail = this.substring(limit, this.length); |
|---|
| 212 |
return head.toUpperCase() + tail.toLowerCase(); |
|---|
| 213 |
}; |
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
String.prototype.titleize = function() { |
|---|
| 222 |
var parts = this.split(" "); |
|---|
| 223 |
res.push(); |
|---|
| 224 |
for (var i in parts) { |
|---|
| 225 |
res.write(parts[i].capitalize()); |
|---|
| 226 |
if (i < parts.length-1) |
|---|
| 227 |
res.write(" "); |
|---|
| 228 |
} |
|---|
| 229 |
return res.pop(); |
|---|
| 230 |
}; |
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
String.prototype.entitize = function() { |
|---|
| 238 |
res.push(); |
|---|
| 239 |
for (var i=0; i<this.length; i++) { |
|---|
| 240 |
res.write("&#"); |
|---|
| 241 |
res.write(this.charCodeAt(i).toString()); |
|---|
| 242 |
res.write(";"); |
|---|
| 243 |
} |
|---|
| 244 |
return res.pop(); |
|---|
| 245 |
}; |
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
String.prototype.embody = function(limit, clipping, delimiter) { |
|---|
| 258 |
if (typeof limit == "string") |
|---|
| 259 |
limit = parseInt(limit, 10); |
|---|
| 260 |
var result = {head: this, tail: String.NULL}; |
|---|
| 261 |
if (!limit || limit < 1) |
|---|
| 262 |
return result; |
|---|
| 263 |
if (!delimiter || delimiter == String.NULL) |
|---|
| 264 |
result.head= this.substring(0, limit); |
|---|
| 265 |
else { |
|---|
| 266 |
var re = new RegExp ("(" + delimiter + "+)"); |
|---|
| 267 |
result.head = this.split(re, 2*limit - 1).join(String.NULL); |
|---|
| 268 |
} |
|---|
| 269 |
if (result.head != this) { |
|---|
| 270 |
result.tail = this.substring(result.head.length).trim(); |
|---|
| 271 |
if (result.tail) { |
|---|
| 272 |
if (clipping == null) |
|---|
| 273 |
clipping = "..."; |
|---|
| 274 |
result.head = result.head.trim() + clipping; |
|---|
| 275 |
result.tail = clipping + result.tail; |
|---|
| 276 |
} |
|---|
| 277 |
} |
|---|
| 278 |
return result; |
|---|
| 279 |
}; |
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
String.prototype.head = function(limit, clipping, delimiter) { |
|---|
| 287 |
return this.embody(limit, clipping, delimiter).head; |
|---|
| 288 |
}; |
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
|
|---|
| 294 |
|
|---|
| 295 |
String.prototype.tail = function(limit, clipping, delimiter) { |
|---|
| 296 |
return this.embody(limit, clipping, delimiter).tail; |
|---|
| 297 |
}; |
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
String.prototype.clip = String.prototype.head; |
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 |
String.prototype.group = function(interval, str, ignoreWhiteSpace) { |
|---|
| 316 |
if (!interval || interval < 1) |
|---|
| 317 |
interval = 20; |
|---|
| 318 |
if (!str || this.length < interval) |
|---|
| 319 |
return this; |
|---|
| 320 |
res.push(); |
|---|
| 321 |
for (var i=0; i<this.length; i=i+interval) { |
|---|
| 322 |
var strPart = this.substring(i, i+interval); |
|---|
| 323 |
res.write(strPart); |
|---|
| 324 |
if (ignoreWhiteSpace == true || |
|---|
| 325 |
(strPart.length == interval && !/\s/g.test(strPart))) { |
|---|
| 326 |
res.write(str); |
|---|
| 327 |
} |
|---|
| 328 |
} |
|---|
| 329 |
return res.pop(); |
|---|
| 330 |
}; |
|---|
| 331 |
|
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
|
|---|
| 335 |
|
|---|
| 336 |
|
|---|
| 337 |
|
|---|
| 338 |
|
|---|
| 339 |
String.prototype.unwrap = function(removeTags, replacement) { |
|---|
| 340 |
if (replacement == null) |
|---|
| 341 |
replacement = String.NULL; |
|---|
| 342 |
var str = this.replace(/[\n|\r]/g, replacement); |
|---|
| 343 |
if (removeTags) |
|---|
| 344 |
str = str.replace(/<[w]?br *\/?>/g, replacement); |
|---|
| 345 |
return str; |
|---|
| 346 |
}; |
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
String.prototype.md5 = function() { |
|---|
| 354 |
return Packages.helma.util.MD5Encoder.encode(this); |
|---|
| 355 |
}; |
|---|
| 356 |
|
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 |
String.prototype.repeat = function(multiplier) { |
|---|
| 364 |
res.push(); |
|---|
| 365 |
for (var i=0; i<multiplier; i++) |
|---|
| 366 |
res.write(this); |
|---|
| 367 |
return res.pop(); |
|---|
| 368 |
}; |
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 |
|
|---|
| 375 |
|
|---|
| 376 |
|
|---|
| 377 |
|
|---|
| 378 |
String.prototype.startsWith = function(str, offset) { |
|---|
| 379 |
var javaObj = new java.lang.String(this); |
|---|
| 380 |
if (offset != null) |
|---|
| 381 |
return javaObj.startsWith(str, offset); |
|---|
| 382 |
return javaObj.startsWith(str); |
|---|
| 383 |
}; |
|---|
| 384 |
|
|---|
| 385 |
|
|---|
| 386 |
|
|---|
| 387 |
|
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 |
|
|---|
| 392 |
|
|---|
| 393 |
String.prototype.endsWith = function(str) { |
|---|
| 394 |
var javaObj = new java.lang.String(this); |
|---|
| 395 |
return javaObj.endsWith(str); |
|---|
| 396 |
}; |
|---|
| 397 |
|
|---|
| 398 |
|
|---|
| 399 |
|
|---|
| 400 |
|
|---|
| 401 |
|
|---|
| 402 |
|
|---|
| 403 |
|
|---|
| 404 |
|
|---|
| 405 |
|
|---|
| 406 |
|
|---|
| 407 |
|
|---|
| 408 |
|
|---|
| 409 |
String.prototype.pad = function(str, len, mode) { |
|---|
| 410 |
if (str == null || len == null) |
|---|
| 411 |
return this; |
|---|
| 412 |
var diff = len - this.length; |
|---|
| 413 |
if (diff == 0) |
|---|
| 414 |
return this; |
|---|
| 415 |
var left, right = 0; |
|---|
| 416 |
if (mode == null || mode == String.RIGHT) |
|---|
| 417 |
right = diff; |
|---|
| 418 |
else if (mode == String.LEFT) |
|---|
| 419 |
left = diff; |
|---|
| 420 |
else if (mode == String.BALANCE) { |
|---|
| 421 |
right = Math.round(diff / 2); |
|---|
| 422 |
left = diff - right; |
|---|
| 423 |
} |
|---|
| 424 |
res.push(); |
|---|
| 425 |
for (var i=0; i<left; i++) |
|---|
| 426 |
res.write(str); |
|---|
| 427 |
res.write(this); |
|---|
| 428 |
for (var i=0; i<right; i++) |
|---|
| 429 |
res.write(str); |
|---|
| 430 |
return res.pop(); |
|---|
| 431 |
}; |
|---|
| 432 |
|
|---|
| 433 |
|
|---|
| 434 |
|
|---|
| 435 |
|
|---|
| 436 |
|
|---|
| 437 |
|
|---|
| 438 |
|
|---|
| 439 |
|
|---|
| 440 |
|
|---|
| 441 |
String.prototype.contains = function(str, fromIndex) { |
|---|
| 442 |
if (this.indexOf(str, fromIndex ? fromIndex : 0) > -1) |
|---|
| 443 |
return true; |
|---|
| 444 |
return false; |
|---|
| 445 |
}; |
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 |
|
|---|
| 454 |
|
|---|
| 455 |
|
|---|
| 456 |
|
|---|
| 457 |
|
|---|
| 458 |
|
|---|
| 459 |
|
|---|
| 460 |
|
|---|
| 461 |
String.prototype.diff = function(mod, separator) { |
|---|
| 462 |
|
|---|
| 463 |
var regexp = (typeof(separator) == "undefined") ? |
|---|
| 464 |
new RegExp("\r\n|\r|\n") : |
|---|
| 465 |
new RegExp(separator); |
|---|
| 466 |
|
|---|
| 467 |
var orig = this.split(regexp); |
|---|
| 468 |
var mod = mod.split(regexp); |
|---|
| 469 |
|
|---|
| 470 |
var diff = new Packages.helma.util.Diff(orig, mod); |
|---|
| 471 |
|
|---|
| 472 |
var d = diff.diff(); |
|---|
| 473 |
if (!d) |
|---|
| 474 |
return null; |
|---|
| 475 |
|
|---|
| 476 |
var max = Math.max(orig.length, mod.length); |
|---|
| 477 |
var result = new Array(); |
|---|
| 478 |
for (var i=0;i<max;i++) { |
|---|
| 479 |
var line = result[i]; |
|---|
| 480 |
if (!line) { |
|---|
| 481 |
line = new Object(); |
|---|
| 482 |
line.num = (i+1); |
|---|
| 483 |
result[i] = line; |
|---|
| 484 |
} |
|---|
| 485 |
if (d && i == d.line1) { |
|---|
| 486 |
if (d.deleted) { |
|---|
| 487 |
var del = new Array(); |
|---|
| 488 |
for (var j=d.line0; j<d.line0+d.deleted; j++) |
|---|
| 489 |
del[del.length] = orig[j]; |
|---|
| 490 |
line.deleted = del; |
|---|
| 491 |
} |
|---|
| 492 |
if (d.inserted) { |
|---|
| 493 |
var ins = new Array(); |
|---|
| 494 |
for (var j=d.line1; j<d.line1+d.inserted; j++) |
|---|
| 495 |
ins[ins.length] = mod[j]; |
|---|
| 496 |
line.inserted = ins; |
|---|
| 497 |
} |
|---|
| 498 |
i = d.line1 + d.inserted -1; |
|---|
| 499 |
d = d.link; |
|---|
| 500 |
} else { |
|---|
| 501 |
line.value = mod[i]; |
|---|
| 502 |
} |
|---|
| 503 |
} |
|---|
| 504 |
return result; |
|---|
| 505 |
}; |
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
String.prototype.trim = function () { |
|---|
| 512 |
var s = new java.lang.String(this); |
|---|
| 513 |
return String(s.trim()); |
|---|
| 514 |
}; |
|---|
| 515 |
|
|---|
| 516 |
|
|---|
| 517 |
|
|---|
| 518 |
|
|---|
| 519 |
|
|---|
| 520 |
String.prototype.isEmail = function() { |
|---|
| 521 |
return String.EMAILPATTERN.test(this); |
|---|
| 522 |
}; |
|---|
| 523 |
|
|---|
| 524 |
|
|---|
| 525 |
|
|---|
| 526 |
|
|---|
| 527 |
|
|---|
| 528 |
String.prototype.count = function(str) { |
|---|
| 529 |
var count = 0; |
|---|
| 530 |
var offset = 0; |
|---|
| 531 |
while ((offset = this.indexOf(str, offset)) > -1) { |
|---|
| 532 |
count += 1; |
|---|
| 533 |
offset += 1; |
|---|
| 534 |
} |
|---|
| 535 |
return count; |
|---|
| 536 |
}; |
|---|
| 537 |
|
|---|
| 538 |
|
|---|
| 539 |
|
|---|
| 540 |
|
|---|
| 541 |
|
|---|
| 542 |
String.prototype.enbase64 = function() { |
|---|
| 543 |
var bytes = new java.lang.String(this) . getBytes(); |
|---|
| 544 |
return new Packages.sun.misc.BASE64Encoder().encode(bytes); |
|---|
| 545 |
}; |
|---|
| 546 |
|
|---|
| 547 |
|
|---|
| 548 |
|
|---|
| 549 |
|
|---|
| 550 |
|
|---|
| 551 |
String.prototype.debase64 = function() { |
|---|
| 552 |
var bytes = new Packages.sun.misc.BASE64Decoder().decodeBuffer(this); |
|---|
| 553 |
return String(new java.lang.String(bytes)); |
|---|
| 554 |
}; |
|---|
| 555 |
|
|---|
| 556 |
|
|---|
| 557 |
|
|---|
| 558 |
|
|---|
| 559 |
|
|---|
| 560 |
String.prototype.encode = function() { |
|---|
| 561 |
return encode(this); |
|---|
| 562 |
}; |
|---|
| 563 |
|
|---|
| 564 |
String.prototype.encodeXml = function() { |
|---|
| 565 |
return encodeXml(this); |
|---|
| 566 |
}; |
|---|
| 567 |
|
|---|
| 568 |
String.prototype.encodeForm = function() { |
|---|
| 569 |
return encodeForm(this); |
|---|
| 570 |
}; |
|---|
| 571 |
|
|---|
| 572 |
String.prototype.format = function() { |
|---|
| 573 |
return format(this); |
|---|
| 574 |
}; |
|---|
| 575 |
|
|---|
| 576 |
String.prototype.stripTags = function() { |
|---|
| 577 |
return stripTags(this); |
|---|
| 578 |
}; |
|---|
| 579 |
|
|---|
| 580 |
|
|---|
| 581 |
|
|---|
| 582 |
|
|---|
| 583 |
|
|---|
| 584 |
|
|---|
| 585 |
|
|---|
| 586 |
String.Sorter = function(field, order) { |
|---|
| 587 |
if (!order) |
|---|
| 588 |
order = 1; |
|---|
| 589 |
var key = field + ":" + order; |
|---|
| 590 |
if (!String.Sorter.cache[key]) { |
|---|
| 591 |
String.Sorter.cache[key] = function(a, b) { |
|---|
| 592 |
var str1 = String(a[field] || String.NULL).toLowerCase(); |
|---|
| 593 |
var str2 = String(b[field] || String.NULL).toLowerCase(); |
|---|
| 594 |
if (str1 > str2) |
|---|
| 595 |
return order * 1; |
|---|
| 596 |
if (str1 < str2) |
|---|
| 597 |
return order * -1; |
|---|
| 598 |
return 0; |
|---|
| 599 |
}; |
|---|
| 600 |
} |
|---|
| 601 |
return String.Sorter.cache[key]; |
|---|
| 602 |
}; |
|---|
| 603 |
|
|---|
| 604 |
String.Sorter.ASC = 1; |
|---|
| 605 |
String.Sorter.DESC = -1; |
|---|
| 606 |
String.Sorter.cache = {}; |
|---|
| 607 |
|
|---|
| 608 |
|
|---|
| 609 |
|
|---|
| 610 |
|
|---|
| 611 |
|
|---|
| 612 |
|
|---|
| 613 |
|
|---|
| 614 |
String.compose = function() { |
|---|
| 615 |
res.push(); |
|---|
| 616 |
for (var i=0; i<arguments.length; i++) |
|---|
| 617 |
res.write(arguments[i]); |
|---|
| 618 |
return res.pop(); |
|---|
| 619 |
}; |
|---|
| 620 |
|
|---|
| 621 |
|
|---|
| 622 |
|
|---|
| 623 |
|
|---|
| 624 |
|
|---|
| 625 |
|
|---|
| 626 |
|
|---|
| 627 |
|
|---|
| 628 |
|
|---|
| 629 |
|
|---|
| 630 |
String.random = function(len, mode) { |
|---|
| 631 |
if (mode == 2) { |
|---|
| 632 |
var x = Math.random() * Math.pow(10,len); |
|---|
| 633 |
return Math.floor(x); |
|---|
| 634 |
} |
|---|
| 635 |
var keystr = String.NULL; |
|---|
| 636 |
for (var i=0; i<len; i++) { |
|---|
| 637 |
var x = Math.floor((Math.random() * 36)); |
|---|
| 638 |
if (mode == 1) { |
|---|
| 639 |
|
|---|
| 640 |
x = (x<2) ? x + 2 : x; |
|---|
| 641 |
|
|---|
| 642 |
x = (x==21) ? 22 : x; |
|---|
| 643 |
x = (x==24) ? 25 : x; |
|---|
| 644 |
} |
|---|
| 645 |
if (x<10) { |
|---|
| 646 |
keystr += String(x); |
|---|
| 647 |
} else { |
|---|
| 648 |
keystr += String.fromCharCode(x+87); |
|---|
| 649 |
} |
|---|
| 650 |
} |
|---|
| 651 |
return keystr; |
|---|
| 652 |
}; |
|---|
| 653 |
|
|---|
| 654 |
|
|---|
| 655 |
|
|---|
| 656 |
|
|---|
| 657 |
|
|---|
| 658 |
|
|---|
| 659 |
|
|---|
| 660 |
|
|---|
| 661 |
|
|---|
| 662 |
|
|---|
| 663 |
String.join = function(str1, str2, glue) { |
|---|
| 664 |
if (glue == null) |
|---|
| 665 |
glue = String.NULL; |
|---|
| 666 |
if (str1 && str2) |
|---|
| 667 |
return str1 + glue + str2; |
|---|
| 668 |
else if (str2) |
|---|
| 669 |
return str2; |
|---|
| 670 |
return str1; |
|---|
| 671 |
}; |
|---|
| 672 |
|
|---|
| 673 |
|
|---|
| 674 |
|
|---|
| 675 |
for (var i in String) |
|---|
| 676 |
String.dontEnum(i); |
|---|
| 677 |
for (var i in String.prototype) |
|---|
| 678 |
String.prototype.dontEnum(i); |
|---|