class-case.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. // BEGIN PRELUDE
  6. function echo(o) {
  7. try {
  8. document.write(o + "<br/>");
  9. echo = function(o) { document.write(o + "<br/>"); };
  10. } catch (ex) {
  11. try {
  12. WScript.Echo("" + o);
  13. echo = function(o) { WScript.Echo("" + o); };
  14. } catch (ex2) {
  15. print("" + o);
  16. echo = function(o) { print("" + o); };
  17. }
  18. }
  19. }
  20. var suppressLastIndex = false;
  21. var suppressRegExp = false;
  22. var suppressIndex = false;
  23. function safeCall(f) {
  24. var args = [];
  25. for (var a = 1; a < arguments.length; ++a)
  26. args.push(arguments[a]);
  27. try {
  28. return f.apply(this, args);
  29. } catch (ex) {
  30. echo("EXCEPTION");
  31. }
  32. }
  33. hex = "0123456789abcdef";
  34. function dump(o) {
  35. var sb = [];
  36. if (o === null)
  37. sb.push("null");
  38. else if (o === undefined)
  39. sb.push("undefined");
  40. else if (o === true)
  41. sb.push("true");
  42. else if (o === false)
  43. sb.push("false");
  44. else if (typeof o === "number")
  45. sb.push(o.toString());
  46. else if (typeof o == "string") {
  47. if (o.length > 8192)
  48. sb.push("<long string>");
  49. else {
  50. sb.push("\"");
  51. var start = -1;
  52. for (var i = 0; i < o.length; i++) {
  53. var c = o.charCodeAt(i);
  54. if (c < 32 || c > 127 || c == '"'.charCodeAt(0) || c == '\\'.charCodeAt(0)) {
  55. if (start >= 0)
  56. sb.push(o.substring(start, i));
  57. start = -1;
  58. sb.push("\\u");
  59. sb.push(String.fromCharCode(hex.charCodeAt((c >> 12) & 0xf)));
  60. sb.push(String.fromCharCode(hex.charCodeAt((c >> 8) & 0xf)));
  61. sb.push(String.fromCharCode(hex.charCodeAt((c >> 4) & 0xf)));
  62. sb.push(String.fromCharCode(hex.charCodeAt((c >> 0) & 0xf)));
  63. }
  64. else {
  65. if (start < 0)
  66. start = i;
  67. }
  68. }
  69. if (start >= 0)
  70. sb.push(o.substring(start, o.length));
  71. sb.push("\"");
  72. }
  73. }
  74. else if (o instanceof RegExp) {
  75. var body = o.source;
  76. sb.push("/");
  77. var start = -1;
  78. for (var i = 0; i < body.length; i++) {
  79. var c = body.charCodeAt(i);
  80. if (c < 32 || c > 127) {
  81. if (start >= 0)
  82. sb.push(body.substring(start, i));
  83. start = -1;
  84. sb.push("\\u");
  85. sb.push(String.fromCharCode(hex.charCodeAt((c >> 12) & 0xf)));
  86. sb.push(String.fromCharCode(hex.charCodeAt((c >> 8) & 0xf)));
  87. sb.push(String.fromCharCode(hex.charCodeAt((c >> 4) & 0xf)));
  88. sb.push(String.fromCharCode(hex.charCodeAt((c >> 0) & 0xf)));
  89. }
  90. else {
  91. if (start < 0)
  92. start = i;
  93. }
  94. }
  95. if (start >= 0)
  96. sb.push(body.substring(start, body.length));
  97. sb.push("/");
  98. if (o.global)
  99. sb.push("g");
  100. if (o.ignoreCase)
  101. sb.push("i");
  102. if (o.multiline)
  103. sb.push("m");
  104. if (!suppressLastIndex && o.lastIndex !== undefined) {
  105. sb.push(" /*lastIndex=");
  106. sb.push(o.lastIndex);
  107. sb.push("*/ ");
  108. }
  109. }
  110. else if (o.length !== undefined) {
  111. sb.push("[");
  112. for (var i = 0; i < o.length; i++) {
  113. if (i > 0)
  114. sb.push(",");
  115. sb.push(dump(o[i]));
  116. }
  117. sb.push("]");
  118. if (!suppressIndex && (o.input !== undefined || o.index !== undefined))
  119. {
  120. sb.push(" /*input=");
  121. sb.push(dump(o.input));
  122. sb.push(", index=");
  123. sb.push(dump(o.index));
  124. // IE only
  125. // sb.push(", lastIndex=");
  126. // sb.push(dump(o.lastIndex));
  127. sb.push("*/ ");
  128. }
  129. }
  130. else if (o.toString !== undefined) {
  131. sb.push("<object with toString>");
  132. }
  133. else
  134. sb.push(o.toString());
  135. return sb.join("");
  136. }
  137. function pre(w, origargs, n) {
  138. var sb = [w];
  139. sb.push("(");
  140. for (var i = 0; i < n; i++) {
  141. if (i > 0) sb.push(", ");
  142. sb.push(dump(origargs[i]));
  143. }
  144. if (origargs.length > n) {
  145. sb.push(", ");
  146. sb.push(dump(origargs[n]));
  147. origargs[0].lastIndex = origargs[n];
  148. }
  149. sb.push(");");
  150. echo(sb.join(""));
  151. }
  152. function post(r) {
  153. if (!suppressLastIndex) {
  154. echo("r.lastIndex=" + dump(r.lastIndex));
  155. }
  156. if (!suppressRegExp) {
  157. // IE only
  158. // echo("RegExp.index=" + dump(RegExp.index));
  159. // echo("RegExp.lastIndex=" + dump(RegExp.lastIndex));
  160. var sb = [];
  161. sb.push("RegExp.${_,1,...,9}=[");
  162. sb.push(dump(RegExp.$_));
  163. for (var i = 1; i <= 9; i++) {
  164. sb.push(",");
  165. sb.push(dump(RegExp["$" + i]));
  166. }
  167. sb.push("]");
  168. echo(sb.join(""));
  169. }
  170. }
  171. function exec(r, s) {
  172. pre("exec", arguments, 2);
  173. echo(dump(r.exec(s)));
  174. post(r);
  175. }
  176. function test(r, s) {
  177. pre("test", arguments, 2);
  178. echo(dump(r.test(s)));
  179. post(r);
  180. }
  181. function replace(r, s, o) {
  182. pre("replace", arguments, 3);
  183. echo(dump(s.replace(r, o)));
  184. post(r);
  185. }
  186. function split(r, s) {
  187. pre("split", arguments, 2);
  188. echo(dump(s.split(r)));
  189. post(r);
  190. }
  191. function match(r, s) {
  192. pre("match", arguments, 2);
  193. echo(dump(s.match(r)));
  194. post(r);
  195. }
  196. function search(r, s) {
  197. pre("search", arguments, 2);
  198. echo(dump(s.search(r)));
  199. post(r);
  200. }
  201. function bogus(r, o) {
  202. echo("bogus(" + dump(r) + ", " + dump(o) + ");");
  203. try { new RegExp(r, o); echo("FAILED"); } catch (e) { echo("PASSED"); }
  204. }
  205. // END PRELUDE
  206. suppressLastIndex = true;
  207. var a = "#$%&";
  208. a+="0123456789";
  209. a+="<=>?@"
  210. a+="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  211. a+="[\]^_`";
  212. a+="abcdefghijklmnopqrstuvwXYZ";
  213. a+="{|}~";
  214. var regexNoCase =
  215. [ /[K-Z]+/gi,
  216. /[C-\{]+/gi,
  217. /[L-e]+/gi,
  218. /[F-e]+/gi,
  219. /[K-_]+/gi,
  220. /[e-p]+/gi,
  221. /[r-\~]+/gi,
  222. /[9-Z]+/gi,
  223. /[9-k]+/gi,
  224. /[\]-k]+/gi,
  225. /[\{-\}]+/gi,
  226. /[0-z]+/gi,
  227. /[0-K]+/gi,
  228. /[5-\}]+/gi,
  229. /[a-zA-Z]+/gi,
  230. /[afkl]+/gi,
  231. /[a-z0-9_]+/gi,
  232. /[abc]+/gi,
  233. /[E-f]+/gi,
  234. /[abc]+/gi,
  235. /[E-fk-o]+/gi,
  236. /[a-dk-lx-z]+/gi,
  237. /[\[\]]+/gi,
  238. /[\[\}]+/gi,
  239. /[0-\}]+/gi,
  240. /[A-z]+/gi,
  241. /[@-k]+/gi,
  242. /[0-_]+/gi,
  243. /[Z-z]+/gi,
  244. /[A-a]+/gi,
  245. /[X-kK-b]+/gi
  246. ];
  247. var regexCase =
  248. [ /[K-Z]+/g,
  249. /[C-\{]+/g,
  250. /[L-e]+/g,
  251. /[F-e]+/g,
  252. /[K-_]+/g,
  253. /[e-p]+/g,
  254. /[r-\~]+/g,
  255. /[9-Z]+/g,
  256. /[9-k]+/g,
  257. /[\]-k]+/g,
  258. /[\{-\}]+/g,
  259. /[0-z]+/g,
  260. /[0-K]+/g,
  261. /[5-\}]+/g,
  262. /[a-zA-Z]+/g,
  263. /[afkl]+/g,
  264. /[a-z0-9_]+/g,
  265. /[abc]+/g,
  266. /[E-f]+/g,
  267. /[abc]+/g,
  268. /[E-fk-o]+/g,
  269. /[a-dk-lx-z]+/g,
  270. /[\[\]]+/g,
  271. /[\[\}]+/g,
  272. /[0-\}]+/g,
  273. /[A-z]+/g,
  274. /[@-k]+/g,
  275. /[0-_]+/g,
  276. /[Z-z]+/g,
  277. /[A-a]+/g,
  278. /[X-kK-b]+/g
  279. ];
  280. for (var i in regexNoCase)
  281. {
  282. exec(regexNoCase[i], a);
  283. match(regexNoCase[i], a);
  284. }
  285. for (var j in regexCase)
  286. {
  287. exec(regexCase[j], a);
  288. match(regexCase[j], a);
  289. }