查看: 2452|回复: 0

[搬运汉化] 可用于RMMV的JavaScript的Native函数

[复制链接]
梦石
0
星屑
50
在线时间
119 小时
注册时间
2015-1-5
回帖
118
发表于 2015-10-25 02:10:29 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 MonsterJohnCN 于 2015-10-25 02:37 编辑

这些函数没有被列在F1文档中(或者我没找到),在JS教程中通常会存在。

不过我所找到的是直接使用F8调试查询到的可确保用于RMMV的函数。

因此提供这些方便的函数,也许你会需要。

暂时没有翻译,因为我暂时还没用到这些功能。

  1. function StringConstructor(a) {
  2.         if ( % _ArgumentsLength() == 0) a = '';
  3.         if ( % _IsConstructCall()) { % _SetValueOf(this, ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a)));
  4.         } else {
  5.                 return (typeof(a) === 'symbol') ?
  6.                         % _CallFunction(a, SymbolToString) : ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a));
  7.         }
  8. }

  9. function StringToString() {
  10.         if (!(typeof(this) === 'string') && !( % _ClassOf(this) === 'String')) {
  11.                 throw new $TypeError('String.prototype.toString is not generic');
  12.         }
  13.         return %_ValueOf(this);
  14. }

  15. function StringValueOf() {
  16.         if (!(typeof(this) === 'string') && !( % _ClassOf(this) === 'String')) {
  17.                 throw new $TypeError('String.prototype.valueOf is not generic');
  18.         }
  19.         return %_ValueOf(this);
  20. }

  21. function StringCharAt(a) {
  22.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.charAt"]);
  23.         var b = % _StringCharAt(this, a);
  24.         if ( % _IsSmi(b)) {
  25.                 b = % _StringCharAt(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), ( % _IsSmi( % IS_VAR(a)) ? a : % NumberToInteger(ToNumber(a))));
  26.         }
  27.         return b;
  28. }

  29. function StringCharCodeAt(a) {
  30.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.charCodeAt"]);
  31.         var b = % _StringCharCodeAt(this, a);
  32.         if (! % _IsSmi(b)) {
  33.                 b = % _StringCharCodeAt(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), ( % _IsSmi( % IS_VAR(a)) ? a : % NumberToInteger(ToNumber(a))));
  34.         }
  35.         return b;
  36. }

  37. function StringConcat(a) {
  38.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.concat"]);
  39.         var b = % _ArgumentsLength();
  40.         var c = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
  41.         if (b === 1) {
  42.                 return c + a;
  43.         }
  44.         var d = new InternalArray(b + 1);
  45.         d[0] = c;
  46.         for (var g = 0; g < b; g++) {
  47.                 var h = % _Arguments(g);
  48.                 d[g + 1] = ((typeof( % IS_VAR(h)) === 'string') ? h : NonStringToString(h));
  49.         }
  50.         return %StringBuilderConcat(d, b + 1, "");
  51. }

  52. function StringIndexOfJS(a) {
  53.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.indexOf"]);
  54.         var b = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
  55.         a = ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a));
  56.         var c = 0;
  57.         if ( % _ArgumentsLength() > 1) {
  58.                 c = % _Arguments(1);
  59.                 c = ( % _IsSmi( % IS_VAR(c)) ? c : % NumberToInteger(ToNumber(c)));
  60.                 if (c < 0) c = 0;
  61.                 if (c > b.length) c = b.length;
  62.         }
  63.         return %StringIndexOf(b, a, c);
  64. }

  65. function StringLastIndexOfJS(a) {
  66.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.lastIndexOf"]);
  67.         var b = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
  68.         var c = b.length;
  69.         var a = ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a));
  70.         var d = a.length;
  71.         var g = c - d;
  72.         if ( % _ArgumentsLength() > 1) {
  73.                 var h = ToNumber( % _Arguments(1));
  74.                 if (!(! % _IsSmi( % IS_VAR(h)) && !(h == h))) {
  75.                         h = ( % _IsSmi( % IS_VAR(h)) ? h : % NumberToInteger(ToNumber(h)));
  76.                         if (h < 0) {
  77.                                 h = 0;
  78.                         }
  79.                         if (h + d < c) {
  80.                                 g = h;
  81.                         }
  82.                 }
  83.         }
  84.         if (g < 0) {
  85.                 return -1;
  86.         }
  87.         return %StringLastIndexOf(b, a, g);
  88. }

  89. function StringLocaleCompareJS(a) {
  90.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.localeCompare"]);
  91.         return %StringLocaleCompare(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a)));
  92. }

  93. function StringMatchJS(a) {
  94.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.match"]);
  95.         var b = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
  96.         if (( % _IsRegExp(a))) {
  97.                 var c = a.lastIndex;
  98.                 ( % _IsSmi( % IS_VAR(c)) ? c : ToNumber(c));
  99.                 if (!a.global) return RegExpExecNoTests(a, b, 0);
  100.                 var d = % StringMatch(b, a, lastMatchInfo);
  101.                 if (d !== null) lastMatchInfoOverride = null;
  102.                 a.lastIndex = 0;
  103.                 return d;
  104.         }
  105.         a = new $RegExp(a);
  106.         return RegExpExecNoTests(a, b, 0);
  107. }
  108. var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD'];

  109. function StringNormalizeJS(a) {
  110.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.normalize"]);
  111.         var a = a ? ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a)) : 'NFC';
  112.         var b = NORMALIZATION_FORMS.indexOf(a);
  113.         if (b === -1) {
  114.                 throw new $RangeError('The normalization form should be one of ' + NORMALIZATION_FORMS.join(', ') + '.');
  115.         }
  116.         return %_ValueOf(this);
  117. }
  118. var reusableMatchInfo = [2, "", "", -1, -1];

  119. function StringReplace(a, b) {
  120.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.replace"]);
  121.         var c = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
  122.         if (( % _IsRegExp(a))) {
  123.                 var d = a.lastIndex;
  124.                 ( % _IsSmi( % IS_VAR(d)) ? d : ToNumber(d));
  125.                 if (!( % _ClassOf(b) === 'Function')) {
  126.                         b = ((typeof( % IS_VAR(b)) === 'string') ? b : NonStringToString(b));
  127.                         if (!a.global) {
  128.                                 var g = DoRegExpExec(a, c, 0);
  129.                                 if (g == null) {
  130.                                         a.lastIndex = 0
  131.                                         return c;
  132.                                 }
  133.                                 if (b.length == 0) {
  134.                                         return %_SubString(c, 0, g[3]) +
  135.                                                 % _SubString(c, g[4], c.length)
  136.                                 }
  137.                                 return ExpandReplacement(b, c, lastMatchInfo, % _SubString(c, 0, g[3])) +
  138.                                         % _SubString(c, g[4], c.length);
  139.                         }
  140.                         a.lastIndex = 0;
  141.                         if (lastMatchInfoOverride == null) {
  142.                                 return %StringReplaceGlobalRegExpWithString(
  143.                                         c, a, b, lastMatchInfo);
  144.                         } else {
  145.                                 var h = lastMatchInfo[1];
  146.                                 lastMatchInfo[1] = 0;
  147.                                 var i = % StringReplaceGlobalRegExpWithString(
  148.                                         c, a, b, lastMatchInfo);
  149.                                 if ( % _IsSmi(lastMatchInfo[1])) {
  150.                                         lastMatchInfo[1] = h;
  151.                                 } else {
  152.                                         lastMatchInfoOverride = null;
  153.                                 }
  154.                                 return i;
  155.                         }
  156.                 }
  157.                 if (a.global) {
  158.                         return StringReplaceGlobalRegExpWithFunction(c, a, b);
  159.                 }
  160.                 return StringReplaceNonGlobalRegExpWithFunction(c, a, b);
  161.         }
  162.         a = ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a));
  163.         if (a.length == 1 &&
  164.                 c.length > 0xFF &&
  165.                 (typeof(b) === 'string') &&
  166.                 % StringIndexOf(b, '$', 0) < 0) {
  167.                 return %StringReplaceOneCharWithString(c, a, b);
  168.         }
  169.         var j = % StringIndexOf(c, a, 0);
  170.         if (j < 0) return c;
  171.         var k = j + a.length;
  172.         var l = % _SubString(c, 0, j);
  173.         if (( % _ClassOf(b) === 'Function')) {
  174.                 var m = % GetDefaultReceiver(b);
  175.                 l += % _CallFunction(m, a, j, c, b);
  176.         } else {
  177.                 reusableMatchInfo[3] = j;
  178.                 reusableMatchInfo[4] = k;
  179.                 l = ExpandReplacement(((typeof( % IS_VAR(b)) === 'string') ? b : NonStringToString(b)),
  180.                         c,
  181.                         reusableMatchInfo,
  182.                         l);
  183.         }
  184.         return l + % _SubString(c, k, c.length);
  185. }

  186. function ExpandReplacement(a, b, c, d) {
  187.         var g = a.length;
  188.         var h = % StringIndexOf(a, '$', 0);
  189.         if (h < 0) {
  190.                 if (g > 0) d += a;
  191.                 return d;
  192.         }
  193.         if (h > 0) d += % _SubString(a, 0, h);
  194.         while (true) {
  195.                 var i = '$';
  196.                 var j = h + 1;
  197.                 if (j < g) {
  198.                         var k = % _StringCharCodeAt(a, j);
  199.                         if (k == 36) {
  200.                                 ++j;
  201.                                 d += '$';
  202.                         } else if (k == 38) {
  203.                                 ++j;
  204.                                 d +=
  205.                                         % _SubString(b, c[3], c[4]);
  206.                         } else if (k == 96) {
  207.                                 ++j;
  208.                                 d += % _SubString(b, 0, c[3]);
  209.                         } else if (k == 39) {
  210.                                 ++j;
  211.                                 d += % _SubString(b, c[4], b.length);
  212.                         } else if (k >= 48 && k <= 57) {
  213.                                 var l = (k - 48) << 1;
  214.                                 var m = 1;
  215.                                 var o = ((c)[0]);
  216.                                 if (j + 1 < a.length) {
  217.                                         var h = % _StringCharCodeAt(a, j + 1);
  218.                                         if (h >= 48 && h <= 57) {
  219.                                                 var q = l * 10 + ((h - 48) << 1);
  220.                                                 if (q < o) {
  221.                                                         l = q;
  222.                                                         m = 2;
  223.                                                 }
  224.                                         }
  225.                                 }
  226.                                 if (l != 0 && l < o) {
  227.                                         var r = c[(3 + (l))];
  228.                                         if (r >= 0) {
  229.                                                 d +=
  230.                                                         % _SubString(b, r, c[(3 + (l + 1))]);
  231.                                         }
  232.                                         j += m;
  233.                                 } else {
  234.                                         d += '$';
  235.                                 }
  236.                         } else {
  237.                                 d += '$';
  238.                         }
  239.                 } else {
  240.                         d += '$';
  241.                 }
  242.                 h = % StringIndexOf(a, '$', j);
  243.                 if (h < 0) {
  244.                         if (j < g) {
  245.                                 d += % _SubString(a, j, g);
  246.                         }
  247.                         return d;
  248.                 }
  249.                 if (h > j) {
  250.                         d += % _SubString(a, j, h);
  251.                 }
  252.         }
  253.         return d;
  254. }

  255. function CaptureString(a, b, c) {
  256.         var d = c << 1;
  257.         var g = b[(3 + (d))];
  258.         if (g < 0) return;
  259.         var h = b[(3 + (d + 1))];
  260.         return %_SubString(a, g, h);
  261. }
  262. var reusableReplaceArray = new InternalArray(16);

  263. function StringReplaceGlobalRegExpWithFunction(a, b, c) {
  264.         var d = reusableReplaceArray;
  265.         if (d) {
  266.                 reusableReplaceArray = null;
  267.         } else {
  268.                 d = new InternalArray(16);
  269.         }
  270.         var g = % RegExpExecMultiple(b,
  271.                 a,
  272.                 lastMatchInfo,
  273.                 d);
  274.         b.lastIndex = 0;
  275.         if ((g === null)) {
  276.                 reusableReplaceArray = d;
  277.                 return a;
  278.         }
  279.         var h = g.length;
  280.         if (((lastMatchInfo)[0]) == 2) {
  281.                 var i = 0;
  282.                 var j = new InternalPackedArray(null, 0, a);
  283.                 var k = % GetDefaultReceiver(c);
  284.                 for (var l = 0; l < h; l++) {
  285.                         var m = g[l];
  286.                         if ( % _IsSmi(m)) {
  287.                                 if (m > 0) {
  288.                                         i = (m >> 11) + (m & 0x7ff);
  289.                                 } else {
  290.                                         i = g[++l] - m;
  291.                                 }
  292.                         } else {
  293.                                 j[0] = m;
  294.                                 j[1] = i;
  295.                                 lastMatchInfoOverride = j;
  296.                                 var o = % _CallFunction(k, m, i, a, c);
  297.                                 g[l] = ((typeof( % IS_VAR(o)) === 'string') ? o : NonStringToString(o));
  298.                                 i += m.length;
  299.                         }
  300.                 }
  301.         } else {
  302.                 var k = % GetDefaultReceiver(c);
  303.                 for (var l = 0; l < h; l++) {
  304.                         var m = g[l];
  305.                         if (! % _IsSmi(m)) {
  306.                                 lastMatchInfoOverride = m;
  307.                                 var o = % Apply(c, k, m, 0, m.length);
  308.                                 g[l] = ((typeof( % IS_VAR(o)) === 'string') ? o : NonStringToString(o));
  309.                         }
  310.                 }
  311.         }
  312.         var q = % StringBuilderConcat(g, g.length, a);
  313.         d.length = 0;
  314.         reusableReplaceArray = d;
  315.         return q;
  316. }

  317. function StringReplaceNonGlobalRegExpWithFunction(a, b, c) {
  318.         var d = DoRegExpExec(b, a, 0);
  319.         if ((d === null)) {
  320.                 b.lastIndex = 0;
  321.                 return a;
  322.         }
  323.         var g = d[3];
  324.         var h = % _SubString(a, 0, g);
  325.         var i = d[4];
  326.         var j = ((d)[0]) >> 1;
  327.         var k;
  328.         var l = % GetDefaultReceiver(c);
  329.         if (j == 1) {
  330.                 var m = % _SubString(a, g, i);
  331.                 k = % _CallFunction(l, m, g, a, c);
  332.         } else {
  333.                 var o = new InternalArray(j + 2);
  334.                 for (var q = 0; q < j; q++) {
  335.                         o[q] = CaptureString(a, d, q);
  336.                 }
  337.                 o[q] = g;
  338.                 o[q + 1] = a;
  339.                 k = % Apply(c, l, o, 0, q + 2);
  340.         }
  341.         h += k;
  342.         return h + % _SubString(a, i, a.length);
  343. }

  344. function StringSearch(a) {
  345.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.search"]);
  346.         var b;
  347.         if ((typeof(a) === 'string')) {
  348.                 b = % _GetFromCache(0, a);
  349.         } else if (( % _IsRegExp(a))) {
  350.                 b = a;
  351.         } else {
  352.                 b = new $RegExp(a);
  353.         }
  354.         var c = DoRegExpExec(b, ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), 0);
  355.         if (c) {
  356.                 return c[3];
  357.         }
  358.         return -1;
  359. }

  360. function StringSlice(a, b) {
  361.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.slice"]);
  362.         var c = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
  363.         var d = c.length;
  364.         var g = ( % _IsSmi( % IS_VAR(a)) ? a : % NumberToInteger(ToNumber(a)));
  365.         var h = d;
  366.         if (!(b === (void 0))) {
  367.                 h = ( % _IsSmi( % IS_VAR(b)) ? b : % NumberToInteger(ToNumber(b)));
  368.         }
  369.         if (g < 0) {
  370.                 g += d;
  371.                 if (g < 0) {
  372.                         g = 0;
  373.                 }
  374.         } else {
  375.                 if (g > d) {
  376.                         return '';
  377.                 }
  378.         }
  379.         if (h < 0) {
  380.                 h += d;
  381.                 if (h < 0) {
  382.                         return '';
  383.                 }
  384.         } else {
  385.                 if (h > d) {
  386.                         h = d;
  387.                 }
  388.         }
  389.         if (h <= g) {
  390.                 return '';
  391.         }
  392.         return %_SubString(c, g, h);
  393. }

  394. function StringSplitJS(a, b) {
  395.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.split"]);
  396.         var c = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
  397.         b = ((b === (void 0))) ? 0xffffffff : (b >>> 0);
  398.         var d = c.length;
  399.         if (!( % _IsRegExp(a))) {
  400.                 var g = ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a));
  401.                 if (b === 0) return [];
  402.                 if ((a === (void 0))) return [c];
  403.                 var h = g.length;
  404.                 if (h === 0) return %StringToArray(c, b);
  405.                 var i = % StringSplit(c, g, b);
  406.                 return i;
  407.         }
  408.         if (b === 0) return [];
  409.         return StringSplitOnRegExp(c, a, b, d);
  410. }

  411. function StringSplitOnRegExp(a, b, c, d) {
  412.         if (d === 0) {
  413.                 if (DoRegExpExec(b, a, 0, 0) != null) {
  414.                         return [];
  415.                 }
  416.                 return [a];
  417.         }
  418.         var g = 0;
  419.         var h = 0;
  420.         var i = 0;
  421.         var j = new InternalArray();
  422.         outer_loop:
  423.                 while (true) {
  424.                         if (h === d) {
  425.                                 j[j.length] = % _SubString(a, g, d);
  426.                                 break;
  427.                         }
  428.                         var k = DoRegExpExec(b, a, h);
  429.                         if (k == null || d === (i = k[3])) {
  430.                                 j[j.length] = % _SubString(a, g, d);
  431.                                 break;
  432.                         }
  433.                         var l = k[4];
  434.                         if (h === l && l === g) {
  435.                                 h++;
  436.                                 continue;
  437.                         }
  438.                         j[j.length] = % _SubString(a, g, i);
  439.                         if (j.length === c) break;
  440.                         var m = ((k)[0]) + 3;
  441.                         for (var o = 3 + 2; o < m;) {
  442.                                 var q = k[o++];
  443.                                 var r = k[o++];
  444.                                 if (r != -1) {
  445.                                         j[j.length] = % _SubString(a, q, r);
  446.                                 } else {
  447.                                         j[j.length] = (void 0);
  448.                                 }
  449.                                 if (j.length === c) break outer_loop;
  450.                         }
  451.                         h = g = l;
  452.                 }
  453.         var t = []; % MoveArrayContents(j, t);
  454.         return t;
  455. }

  456. function StringSubstring(a, b) {
  457.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.subString"]);
  458.         var c = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
  459.         var d = c.length;
  460.         var g = ( % _IsSmi( % IS_VAR(a)) ? a : % NumberToInteger(ToNumber(a)));
  461.         if (g < 0) {
  462.                 g = 0;
  463.         } else if (g > d) {
  464.                 g = d;
  465.         }
  466.         var h = d;
  467.         if (!(b === (void 0))) {
  468.                 h = ( % _IsSmi( % IS_VAR(b)) ? b : % NumberToInteger(ToNumber(b)));
  469.                 if (h > d) {
  470.                         h = d;
  471.                 } else {
  472.                         if (h < 0) h = 0;
  473.                         if (g > h) {
  474.                                 var i = h;
  475.                                 h = g;
  476.                                 g = i;
  477.                         }
  478.                 }
  479.         }
  480.         return %_SubString(c, g, h);
  481. }

  482. function StringSubstr(a, b) {
  483.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.substr"]);
  484.         var c = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
  485.         var d;
  486.         if ((b === (void 0))) {
  487.                 d = c.length;
  488.         } else {
  489.                 d = ( % _IsSmi( % IS_VAR(b)) ? b : % NumberToInteger(ToNumber(b)));
  490.                 if (d <= 0) return '';
  491.         }
  492.         if ((a === (void 0))) {
  493.                 a = 0;
  494.         } else {
  495.                 a = ( % _IsSmi( % IS_VAR(a)) ? a : % NumberToInteger(ToNumber(a)));
  496.                 if (a >= c.length) return '';
  497.                 if (a < 0) {
  498.                         a += c.length;
  499.                         if (a < 0) a = 0;
  500.                 }
  501.         }
  502.         var g = a + d;
  503.         if (g > c.length) g = c.length;
  504.         return %_SubString(c, a, g);
  505. }

  506. function StringToLowerCaseJS() {
  507.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.toLowerCase"]);
  508.         return %StringToLowerCase(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)));
  509. }

  510. function StringToLocaleLowerCase() {
  511.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.toLocaleLowerCase"]);
  512.         return %StringToLowerCase(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)));
  513. }

  514. function StringToUpperCaseJS() {
  515.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.toUpperCase"]);
  516.         return %StringToUpperCase(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)));
  517. }

  518. function StringToLocaleUpperCase() {
  519.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.toLocaleUpperCase"]);
  520.         return %StringToUpperCase(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)));
  521. }

  522. function StringTrimJS() {
  523.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.trim"]);
  524.         return %StringTrim(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), true, true);
  525. }

  526. function StringTrimLeft() {
  527.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.trimLeft"]);
  528.         return %StringTrim(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), true, false);
  529. }

  530. function StringTrimRight() {
  531.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.trimRight"]);
  532.         return %StringTrim(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), false, true);
  533. }

  534. function StringFromCharCode(a) {
  535.         var b = % _ArgumentsLength();
  536.         if (b == 1) {
  537.                 if (! % _IsSmi(a)) a = ToNumber(a);
  538.                 return %_StringCharFromCode(a & 0xffff);
  539.         }
  540.         var c = % NewString(b, true);
  541.         var d;
  542.         for (d = 0; d < b; d++) {
  543.                 var a = % _Arguments(d);
  544.                 if (! % _IsSmi(a)) a = ToNumber(a) & 0xffff;
  545.                 if (a < 0) a = a & 0xffff;
  546.                 if (a > 0xff) break; % _OneByteSeqStringSetChar(d, a, c);
  547.         }
  548.         if (d == b) return c;
  549.         c = % TruncateString(c, d);
  550.         var g = % NewString(b - d, false);
  551.         for (var h = 0; d < b; d++, h++) {
  552.                 var a = % _Arguments(d);
  553.                 if (! % _IsSmi(a)) a = ToNumber(a) & 0xffff; % _TwoByteSeqStringSetChar(h, a, g);
  554.         }
  555.         return c + g;
  556. }

  557. function HtmlEscape(a) {
  558.         return ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a)).replace(/"/g, "&quot;");
  559. }

  560. function StringAnchor(a) {
  561.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.anchor"]);
  562.         return "<a name="" + HtmlEscape(a) + "">" + this + "</a>";
  563. }

  564. function StringBig() {
  565.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.big"]);
  566.         return "<big>" + this + "</big>";
  567. }

  568. function StringBlink() {
  569.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.blink"]);
  570.         return "<blink>" + this + "</blink>";
  571. }

  572. function StringBold() {
  573.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.bold"]);
  574.         return "<b>" + this + "</b>";
  575. }

  576. function StringFixed() {
  577.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.fixed"]);
  578.         return "<tt>" + this + "</tt>";
  579. }

  580. function StringFontcolor(a) {
  581.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.fontcolor"]);
  582.         return "<font color="" + HtmlEscape(a) + "">" + this + "</font>";
  583. }

  584. function StringFontsize(a) {
  585.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.fontsize"]);
  586.         return "<font size="" + HtmlEscape(a) + "">" + this + "</font>";
  587. }

  588. function StringItalics() {
  589.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.italics"]);
  590.         return "<i>" + this + "</i>";
  591. }

  592. function StringLink(a) {
  593.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.link"]);
  594.         return "<a href="" + HtmlEscape(a) + "">" + this + "</a>";
  595. }

  596. function StringSmall() {
  597.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.small"]);
  598.         return "<small>" + this + "</small>";
  599. }

  600. function StringStrike() {
  601.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.strike"]);
  602.         return "<strike>" + this + "</strike>";
  603. }

  604. function StringSub() {
  605.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.sub"]);
  606.         return "<sub>" + this + "</sub>";
  607. }

  608. function StringSup() {
  609.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.sup"]);
  610.         return "<sup>" + this + "</sup>";
  611. }

  612. function SetUpString() { % CheckIsBootstrapping(); % SetCode($String, StringConstructor); % FunctionSetPrototype($String, new $String()); % AddNamedProperty($String.prototype, "constructor", $String, 2);
  613.         InstallFunctions($String, 2, $Array(
  614.                 "fromCharCode", StringFromCharCode
  615.         ));
  616.         InstallFunctions($String.prototype, 2, $Array(
  617.                 "valueOf", StringValueOf,
  618.                 "toString", StringToString,
  619.                 "charAt", StringCharAt,
  620.                 "charCodeAt", StringCharCodeAt,
  621.                 "concat", StringConcat,
  622.                 "indexOf", StringIndexOfJS,
  623.                 "lastIndexOf", StringLastIndexOfJS,
  624.                 "localeCompare", StringLocaleCompareJS,
  625.                 "match", StringMatchJS,
  626.                 "normalize", StringNormalizeJS,
  627.                 "replace", StringReplace,
  628.                 "search", StringSearch,
  629.                 "slice", StringSlice,
  630.                 "split", StringSplitJS,
  631.                 "substring", StringSubstring,
  632.                 "substr", StringSubstr,
  633.                 "toLowerCase", StringToLowerCaseJS,
  634.                 "toLocaleLowerCase", StringToLocaleLowerCase,
  635.                 "toUpperCase", StringToUpperCaseJS,
  636.                 "toLocaleUpperCase", StringToLocaleUpperCase,
  637.                 "trim", StringTrimJS,
  638.                 "trimLeft", StringTrimLeft,
  639.                 "trimRight", StringTrimRight,
  640.                 "link", StringLink,
  641.                 "anchor", StringAnchor,
  642.                 "fontcolor", StringFontcolor,
  643.                 "fontsize", StringFontsize,
  644.                 "big", StringBig,
  645.                 "blink", StringBlink,
  646.                 "bold", StringBold,
  647.                 "fixed", StringFixed,
  648.                 "italics", StringItalics,
  649.                 "small", StringSmall,
  650.                 "strike", StringStrike,
  651.                 "sub", StringSub,
  652.                 "sup", StringSup
  653.         ));
  654. }
  655. SetUpString();
复制代码

评分

参与人数 1星屑 +400 收起 理由
余烬之中 + 400 搬运

查看全部评分

实力跳票,根本停不下来…… | bgpCore.js | 《下一站》2号DEMO | 插件开发无限延期中……正在研制适用性更强的普适模板,不再输出单体插件……
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部