设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1683|回复: 0
打印 上一主题 下一主题

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

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
119 小时
注册时间
2015-1-5
帖子
139
跳转到指定楼层
1
发表于 2015-10-25 02:10:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

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

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

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

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

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

JAVASCRIPT 代码复制
  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.  
  10. function StringToString() {
  11.         if (!(typeof(this) === 'string') && !( % _ClassOf(this) === 'String')) {
  12.                 throw new $TypeError('String.prototype.toString is not generic');
  13.         }
  14.         return %_ValueOf(this);
  15. }
  16.  
  17. function StringValueOf() {
  18.         if (!(typeof(this) === 'string') && !( % _ClassOf(this) === 'String')) {
  19.                 throw new $TypeError('String.prototype.valueOf is not generic');
  20.         }
  21.         return %_ValueOf(this);
  22. }
  23.  
  24. function StringCharAt(a) {
  25.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.charAt"]);
  26.         var b = % _StringCharAt(this, a);
  27.         if ( % _IsSmi(b)) {
  28.                 b = % _StringCharAt(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), ( % _IsSmi( % IS_VAR(a)) ? a : % NumberToInteger(ToNumber(a))));
  29.         }
  30.         return b;
  31. }
  32.  
  33. function StringCharCodeAt(a) {
  34.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.charCodeAt"]);
  35.         var b = % _StringCharCodeAt(this, a);
  36.         if (! % _IsSmi(b)) {
  37.                 b = % _StringCharCodeAt(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), ( % _IsSmi( % IS_VAR(a)) ? a : % NumberToInteger(ToNumber(a))));
  38.         }
  39.         return b;
  40. }
  41.  
  42. function StringConcat(a) {
  43.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.concat"]);
  44.         var b = % _ArgumentsLength();
  45.         var c = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
  46.         if (b === 1) {
  47.                 return c + a;
  48.         }
  49.         var d = new InternalArray(b + 1);
  50.         d[0] = c;
  51.         for (var g = 0; g < b; g++) {
  52.                 var h = % _Arguments(g);
  53.                 d[g + 1] = ((typeof( % IS_VAR(h)) === 'string') ? h : NonStringToString(h));
  54.         }
  55.         return %StringBuilderConcat(d, b + 1, "");
  56. }
  57.  
  58. function StringIndexOfJS(a) {
  59.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.indexOf"]);
  60.         var b = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
  61.         a = ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a));
  62.         var c = 0;
  63.         if ( % _ArgumentsLength() > 1) {
  64.                 c = % _Arguments(1);
  65.                 c = ( % _IsSmi( % IS_VAR(c)) ? c : % NumberToInteger(ToNumber(c)));
  66.                 if (c < 0) c = 0;
  67.                 if (c > b.length) c = b.length;
  68.         }
  69.         return %StringIndexOf(b, a, c);
  70. }
  71.  
  72. function StringLastIndexOfJS(a) {
  73.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.lastIndexOf"]);
  74.         var b = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
  75.         var c = b.length;
  76.         var a = ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a));
  77.         var d = a.length;
  78.         var g = c - d;
  79.         if ( % _ArgumentsLength() > 1) {
  80.                 var h = ToNumber( % _Arguments(1));
  81.                 if (!(! % _IsSmi( % IS_VAR(h)) && !(h == h))) {
  82.                         h = ( % _IsSmi( % IS_VAR(h)) ? h : % NumberToInteger(ToNumber(h)));
  83.                         if (h < 0) {
  84.                                 h = 0;
  85.                         }
  86.                         if (h + d < c) {
  87.                                 g = h;
  88.                         }
  89.                 }
  90.         }
  91.         if (g < 0) {
  92.                 return -1;
  93.         }
  94.         return %StringLastIndexOf(b, a, g);
  95. }
  96.  
  97. function StringLocaleCompareJS(a) {
  98.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.localeCompare"]);
  99.         return %StringLocaleCompare(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a)));
  100. }
  101.  
  102. function StringMatchJS(a) {
  103.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.match"]);
  104.         var b = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
  105.         if (( % _IsRegExp(a))) {
  106.                 var c = a.lastIndex;
  107.                 ( % _IsSmi( % IS_VAR(c)) ? c : ToNumber(c));
  108.                 if (!a.global) return RegExpExecNoTests(a, b, 0);
  109.                 var d = % StringMatch(b, a, lastMatchInfo);
  110.                 if (d !== null) lastMatchInfoOverride = null;
  111.                 a.lastIndex = 0;
  112.                 return d;
  113.         }
  114.         a = new $RegExp(a);
  115.         return RegExpExecNoTests(a, b, 0);
  116. }
  117. var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD'];
  118.  
  119. function StringNormalizeJS(a) {
  120.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.normalize"]);
  121.         var a = a ? ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a)) : 'NFC';
  122.         var b = NORMALIZATION_FORMS.indexOf(a);
  123.         if (b === -1) {
  124.                 throw new $RangeError('The normalization form should be one of ' + NORMALIZATION_FORMS.join(', ') + '.');
  125.         }
  126.         return %_ValueOf(this);
  127. }
  128. var reusableMatchInfo = [2, "", "", -1, -1];
  129.  
  130. function StringReplace(a, b) {
  131.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.replace"]);
  132.         var c = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
  133.         if (( % _IsRegExp(a))) {
  134.                 var d = a.lastIndex;
  135.                 ( % _IsSmi( % IS_VAR(d)) ? d : ToNumber(d));
  136.                 if (!( % _ClassOf(b) === 'Function')) {
  137.                         b = ((typeof( % IS_VAR(b)) === 'string') ? b : NonStringToString(b));
  138.                         if (!a.global) {
  139.                                 var g = DoRegExpExec(a, c, 0);
  140.                                 if (g == null) {
  141.                                         a.lastIndex = 0
  142.                                         return c;
  143.                                 }
  144.                                 if (b.length == 0) {
  145.                                         return %_SubString(c, 0, g[3]) +
  146.                                                 % _SubString(c, g[4], c.length)
  147.                                 }
  148.                                 return ExpandReplacement(b, c, lastMatchInfo, % _SubString(c, 0, g[3])) +
  149.                                         % _SubString(c, g[4], c.length);
  150.                         }
  151.                         a.lastIndex = 0;
  152.                         if (lastMatchInfoOverride == null) {
  153.                                 return %StringReplaceGlobalRegExpWithString(
  154.                                         c, a, b, lastMatchInfo);
  155.                         } else {
  156.                                 var h = lastMatchInfo[1];
  157.                                 lastMatchInfo[1] = 0;
  158.                                 var i = % StringReplaceGlobalRegExpWithString(
  159.                                         c, a, b, lastMatchInfo);
  160.                                 if ( % _IsSmi(lastMatchInfo[1])) {
  161.                                         lastMatchInfo[1] = h;
  162.                                 } else {
  163.                                         lastMatchInfoOverride = null;
  164.                                 }
  165.                                 return i;
  166.                         }
  167.                 }
  168.                 if (a.global) {
  169.                         return StringReplaceGlobalRegExpWithFunction(c, a, b);
  170.                 }
  171.                 return StringReplaceNonGlobalRegExpWithFunction(c, a, b);
  172.         }
  173.         a = ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a));
  174.         if (a.length == 1 &&
  175.                 c.length > 0xFF &&
  176.                 (typeof(b) === 'string') &&
  177.                 % StringIndexOf(b, '$', 0) < 0) {
  178.                 return %StringReplaceOneCharWithString(c, a, b);
  179.         }
  180.         var j = % StringIndexOf(c, a, 0);
  181.         if (j < 0) return c;
  182.         var k = j + a.length;
  183.         var l = % _SubString(c, 0, j);
  184.         if (( % _ClassOf(b) === 'Function')) {
  185.                 var m = % GetDefaultReceiver(b);
  186.                 l += % _CallFunction(m, a, j, c, b);
  187.         } else {
  188.                 reusableMatchInfo[3] = j;
  189.                 reusableMatchInfo[4] = k;
  190.                 l = ExpandReplacement(((typeof( % IS_VAR(b)) === 'string') ? b : NonStringToString(b)),
  191.                         c,
  192.                         reusableMatchInfo,
  193.                         l);
  194.         }
  195.         return l + % _SubString(c, k, c.length);
  196. }
  197.  
  198. function ExpandReplacement(a, b, c, d) {
  199.         var g = a.length;
  200.         var h = % StringIndexOf(a, '$', 0);
  201.         if (h < 0) {
  202.                 if (g > 0) d += a;
  203.                 return d;
  204.         }
  205.         if (h > 0) d += % _SubString(a, 0, h);
  206.         while (true) {
  207.                 var i = '$';
  208.                 var j = h + 1;
  209.                 if (j < g) {
  210.                         var k = % _StringCharCodeAt(a, j);
  211.                         if (k == 36) {
  212.                                 ++j;
  213.                                 d += '$';
  214.                         } else if (k == 38) {
  215.                                 ++j;
  216.                                 d +=
  217.                                         % _SubString(b, c[3], c[4]);
  218.                         } else if (k == 96) {
  219.                                 ++j;
  220.                                 d += % _SubString(b, 0, c[3]);
  221.                         } else if (k == 39) {
  222.                                 ++j;
  223.                                 d += % _SubString(b, c[4], b.length);
  224.                         } else if (k >= 48 && k <= 57) {
  225.                                 var l = (k - 48) << 1;
  226.                                 var m = 1;
  227.                                 var o = ((c)[0]);
  228.                                 if (j + 1 < a.length) {
  229.                                         var h = % _StringCharCodeAt(a, j + 1);
  230.                                         if (h >= 48 && h <= 57) {
  231.                                                 var q = l * 10 + ((h - 48) << 1);
  232.                                                 if (q < o) {
  233.                                                         l = q;
  234.                                                         m = 2;
  235.                                                 }
  236.                                         }
  237.                                 }
  238.                                 if (l != 0 && l < o) {
  239.                                         var r = c[(3 + (l))];
  240.                                         if (r >= 0) {
  241.                                                 d +=
  242.                                                         % _SubString(b, r, c[(3 + (l + 1))]);
  243.                                         }
  244.                                         j += m;
  245.                                 } else {
  246.                                         d += '$';
  247.                                 }
  248.                         } else {
  249.                                 d += '$';
  250.                         }
  251.                 } else {
  252.                         d += '$';
  253.                 }
  254.                 h = % StringIndexOf(a, '$', j);
  255.                 if (h < 0) {
  256.                         if (j < g) {
  257.                                 d += % _SubString(a, j, g);
  258.                         }
  259.                         return d;
  260.                 }
  261.                 if (h > j) {
  262.                         d += % _SubString(a, j, h);
  263.                 }
  264.         }
  265.         return d;
  266. }
  267.  
  268. function CaptureString(a, b, c) {
  269.         var d = c << 1;
  270.         var g = b[(3 + (d))];
  271.         if (g < 0) return;
  272.         var h = b[(3 + (d + 1))];
  273.         return %_SubString(a, g, h);
  274. }
  275. var reusableReplaceArray = new InternalArray(16);
  276.  
  277. function StringReplaceGlobalRegExpWithFunction(a, b, c) {
  278.         var d = reusableReplaceArray;
  279.         if (d) {
  280.                 reusableReplaceArray = null;
  281.         } else {
  282.                 d = new InternalArray(16);
  283.         }
  284.         var g = % RegExpExecMultiple(b,
  285.                 a,
  286.                 lastMatchInfo,
  287.                 d);
  288.         b.lastIndex = 0;
  289.         if ((g === null)) {
  290.                 reusableReplaceArray = d;
  291.                 return a;
  292.         }
  293.         var h = g.length;
  294.         if (((lastMatchInfo)[0]) == 2) {
  295.                 var i = 0;
  296.                 var j = new InternalPackedArray(null, 0, a);
  297.                 var k = % GetDefaultReceiver(c);
  298.                 for (var l = 0; l < h; l++) {
  299.                         var m = g[l];
  300.                         if ( % _IsSmi(m)) {
  301.                                 if (m > 0) {
  302.                                         i = (m >> 11) + (m & 0x7ff);
  303.                                 } else {
  304.                                         i = g[++l] - m;
  305.                                 }
  306.                         } else {
  307.                                 j[0] = m;
  308.                                 j[1] = i;
  309.                                 lastMatchInfoOverride = j;
  310.                                 var o = % _CallFunction(k, m, i, a, c);
  311.                                 g[l] = ((typeof( % IS_VAR(o)) === 'string') ? o : NonStringToString(o));
  312.                                 i += m.length;
  313.                         }
  314.                 }
  315.         } else {
  316.                 var k = % GetDefaultReceiver(c);
  317.                 for (var l = 0; l < h; l++) {
  318.                         var m = g[l];
  319.                         if (! % _IsSmi(m)) {
  320.                                 lastMatchInfoOverride = m;
  321.                                 var o = % Apply(c, k, m, 0, m.length);
  322.                                 g[l] = ((typeof( % IS_VAR(o)) === 'string') ? o : NonStringToString(o));
  323.                         }
  324.                 }
  325.         }
  326.         var q = % StringBuilderConcat(g, g.length, a);
  327.         d.length = 0;
  328.         reusableReplaceArray = d;
  329.         return q;
  330. }
  331.  
  332. function StringReplaceNonGlobalRegExpWithFunction(a, b, c) {
  333.         var d = DoRegExpExec(b, a, 0);
  334.         if ((d === null)) {
  335.                 b.lastIndex = 0;
  336.                 return a;
  337.         }
  338.         var g = d[3];
  339.         var h = % _SubString(a, 0, g);
  340.         var i = d[4];
  341.         var j = ((d)[0]) >> 1;
  342.         var k;
  343.         var l = % GetDefaultReceiver(c);
  344.         if (j == 1) {
  345.                 var m = % _SubString(a, g, i);
  346.                 k = % _CallFunction(l, m, g, a, c);
  347.         } else {
  348.                 var o = new InternalArray(j + 2);
  349.                 for (var q = 0; q < j; q++) {
  350.                         o[q] = CaptureString(a, d, q);
  351.                 }
  352.                 o[q] = g;
  353.                 o[q + 1] = a;
  354.                 k = % Apply(c, l, o, 0, q + 2);
  355.         }
  356.         h += k;
  357.         return h + % _SubString(a, i, a.length);
  358. }
  359.  
  360. function StringSearch(a) {
  361.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.search"]);
  362.         var b;
  363.         if ((typeof(a) === 'string')) {
  364.                 b = % _GetFromCache(0, a);
  365.         } else if (( % _IsRegExp(a))) {
  366.                 b = a;
  367.         } else {
  368.                 b = new $RegExp(a);
  369.         }
  370.         var c = DoRegExpExec(b, ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), 0);
  371.         if (c) {
  372.                 return c[3];
  373.         }
  374.         return -1;
  375. }
  376.  
  377. function StringSlice(a, b) {
  378.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.slice"]);
  379.         var c = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
  380.         var d = c.length;
  381.         var g = ( % _IsSmi( % IS_VAR(a)) ? a : % NumberToInteger(ToNumber(a)));
  382.         var h = d;
  383.         if (!(b === (void 0))) {
  384.                 h = ( % _IsSmi( % IS_VAR(b)) ? b : % NumberToInteger(ToNumber(b)));
  385.         }
  386.         if (g < 0) {
  387.                 g += d;
  388.                 if (g < 0) {
  389.                         g = 0;
  390.                 }
  391.         } else {
  392.                 if (g > d) {
  393.                         return '';
  394.                 }
  395.         }
  396.         if (h < 0) {
  397.                 h += d;
  398.                 if (h < 0) {
  399.                         return '';
  400.                 }
  401.         } else {
  402.                 if (h > d) {
  403.                         h = d;
  404.                 }
  405.         }
  406.         if (h <= g) {
  407.                 return '';
  408.         }
  409.         return %_SubString(c, g, h);
  410. }
  411.  
  412. function StringSplitJS(a, b) {
  413.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.split"]);
  414.         var c = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
  415.         b = ((b === (void 0))) ? 0xffffffff : (b >>> 0);
  416.         var d = c.length;
  417.         if (!( % _IsRegExp(a))) {
  418.                 var g = ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a));
  419.                 if (b === 0) return [];
  420.                 if ((a === (void 0))) return [c];
  421.                 var h = g.length;
  422.                 if (h === 0) return %StringToArray(c, b);
  423.                 var i = % StringSplit(c, g, b);
  424.                 return i;
  425.         }
  426.         if (b === 0) return [];
  427.         return StringSplitOnRegExp(c, a, b, d);
  428. }
  429.  
  430. function StringSplitOnRegExp(a, b, c, d) {
  431.         if (d === 0) {
  432.                 if (DoRegExpExec(b, a, 0, 0) != null) {
  433.                         return [];
  434.                 }
  435.                 return [a];
  436.         }
  437.         var g = 0;
  438.         var h = 0;
  439.         var i = 0;
  440.         var j = new InternalArray();
  441.         outer_loop:
  442.                 while (true) {
  443.                         if (h === d) {
  444.                                 j[j.length] = % _SubString(a, g, d);
  445.                                 break;
  446.                         }
  447.                         var k = DoRegExpExec(b, a, h);
  448.                         if (k == null || d === (i = k[3])) {
  449.                                 j[j.length] = % _SubString(a, g, d);
  450.                                 break;
  451.                         }
  452.                         var l = k[4];
  453.                         if (h === l && l === g) {
  454.                                 h++;
  455.                                 continue;
  456.                         }
  457.                         j[j.length] = % _SubString(a, g, i);
  458.                         if (j.length === c) break;
  459.                         var m = ((k)[0]) + 3;
  460.                         for (var o = 3 + 2; o < m;) {
  461.                                 var q = k[o++];
  462.                                 var r = k[o++];
  463.                                 if (r != -1) {
  464.                                         j[j.length] = % _SubString(a, q, r);
  465.                                 } else {
  466.                                         j[j.length] = (void 0);
  467.                                 }
  468.                                 if (j.length === c) break outer_loop;
  469.                         }
  470.                         h = g = l;
  471.                 }
  472.         var t = []; % MoveArrayContents(j, t);
  473.         return t;
  474. }
  475.  
  476. function StringSubstring(a, b) {
  477.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.subString"]);
  478.         var c = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
  479.         var d = c.length;
  480.         var g = ( % _IsSmi( % IS_VAR(a)) ? a : % NumberToInteger(ToNumber(a)));
  481.         if (g < 0) {
  482.                 g = 0;
  483.         } else if (g > d) {
  484.                 g = d;
  485.         }
  486.         var h = d;
  487.         if (!(b === (void 0))) {
  488.                 h = ( % _IsSmi( % IS_VAR(b)) ? b : % NumberToInteger(ToNumber(b)));
  489.                 if (h > d) {
  490.                         h = d;
  491.                 } else {
  492.                         if (h < 0) h = 0;
  493.                         if (g > h) {
  494.                                 var i = h;
  495.                                 h = g;
  496.                                 g = i;
  497.                         }
  498.                 }
  499.         }
  500.         return %_SubString(c, g, h);
  501. }
  502.  
  503. function StringSubstr(a, b) {
  504.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.substr"]);
  505.         var c = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
  506.         var d;
  507.         if ((b === (void 0))) {
  508.                 d = c.length;
  509.         } else {
  510.                 d = ( % _IsSmi( % IS_VAR(b)) ? b : % NumberToInteger(ToNumber(b)));
  511.                 if (d <= 0) return '';
  512.         }
  513.         if ((a === (void 0))) {
  514.                 a = 0;
  515.         } else {
  516.                 a = ( % _IsSmi( % IS_VAR(a)) ? a : % NumberToInteger(ToNumber(a)));
  517.                 if (a >= c.length) return '';
  518.                 if (a < 0) {
  519.                         a += c.length;
  520.                         if (a < 0) a = 0;
  521.                 }
  522.         }
  523.         var g = a + d;
  524.         if (g > c.length) g = c.length;
  525.         return %_SubString(c, a, g);
  526. }
  527.  
  528. function StringToLowerCaseJS() {
  529.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.toLowerCase"]);
  530.         return %StringToLowerCase(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)));
  531. }
  532.  
  533. function StringToLocaleLowerCase() {
  534.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.toLocaleLowerCase"]);
  535.         return %StringToLowerCase(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)));
  536. }
  537.  
  538. function StringToUpperCaseJS() {
  539.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.toUpperCase"]);
  540.         return %StringToUpperCase(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)));
  541. }
  542.  
  543. function StringToLocaleUpperCase() {
  544.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.toLocaleUpperCase"]);
  545.         return %StringToUpperCase(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)));
  546. }
  547.  
  548. function StringTrimJS() {
  549.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.trim"]);
  550.         return %StringTrim(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), true, true);
  551. }
  552.  
  553. function StringTrimLeft() {
  554.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.trimLeft"]);
  555.         return %StringTrim(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), true, false);
  556. }
  557.  
  558. function StringTrimRight() {
  559.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.trimRight"]);
  560.         return %StringTrim(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), false, true);
  561. }
  562.  
  563. function StringFromCharCode(a) {
  564.         var b = % _ArgumentsLength();
  565.         if (b == 1) {
  566.                 if (! % _IsSmi(a)) a = ToNumber(a);
  567.                 return %_StringCharFromCode(a & 0xffff);
  568.         }
  569.         var c = % NewString(b, true);
  570.         var d;
  571.         for (d = 0; d < b; d++) {
  572.                 var a = % _Arguments(d);
  573.                 if (! % _IsSmi(a)) a = ToNumber(a) & 0xffff;
  574.                 if (a < 0) a = a & 0xffff;
  575.                 if (a > 0xff) break; % _OneByteSeqStringSetChar(d, a, c);
  576.         }
  577.         if (d == b) return c;
  578.         c = % TruncateString(c, d);
  579.         var g = % NewString(b - d, false);
  580.         for (var h = 0; d < b; d++, h++) {
  581.                 var a = % _Arguments(d);
  582.                 if (! % _IsSmi(a)) a = ToNumber(a) & 0xffff; % _TwoByteSeqStringSetChar(h, a, g);
  583.         }
  584.         return c + g;
  585. }
  586.  
  587. function HtmlEscape(a) {
  588.         return ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a)).replace(/"/g, """);
  589. }
  590.  
  591. function StringAnchor(a) {
  592.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.anchor"]);
  593.         return "<a name=\"" + HtmlEscape(a) + "\">" + this + "</a>";
  594. }
  595.  
  596. function StringBig() {
  597.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.big"]);
  598.         return "<big>" + this + "</big>";
  599. }
  600.  
  601. function StringBlink() {
  602.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.blink"]);
  603.         return "<blink>" + this + "</blink>";
  604. }
  605.  
  606. function StringBold() {
  607.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.bold"]);
  608.         return "<b>" + this + "</b>";
  609. }
  610.  
  611. function StringFixed() {
  612.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.fixed"]);
  613.         return "<tt>" + this + "</tt>";
  614. }
  615.  
  616. function StringFontcolor(a) {
  617.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.fontcolor"]);
  618.         return "<font color=\"" + HtmlEscape(a) + "\">" + this + "</font>";
  619. }
  620.  
  621. function StringFontsize(a) {
  622.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.fontsize"]);
  623.         return "<font size=\"" + HtmlEscape(a) + "\">" + this + "</font>";
  624. }
  625.  
  626. function StringItalics() {
  627.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.italics"]);
  628.         return "<i>" + this + "</i>";
  629. }
  630.  
  631. function StringLink(a) {
  632.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.link"]);
  633.         return "<a href=\"" + HtmlEscape(a) + "\">" + this + "</a>";
  634. }
  635.  
  636. function StringSmall() {
  637.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.small"]);
  638.         return "<small>" + this + "</small>";
  639. }
  640.  
  641. function StringStrike() {
  642.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.strike"]);
  643.         return "<strike>" + this + "</strike>";
  644. }
  645.  
  646. function StringSub() {
  647.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.sub"]);
  648.         return "<sub>" + this + "</sub>";
  649. }
  650.  
  651. function StringSup() {
  652.         if ((this == null) && !( % _IsUndetectableObject(this))) throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.sup"]);
  653.         return "<sup>" + this + "</sup>";
  654. }
  655.  
  656. function SetUpString() { % CheckIsBootstrapping(); % SetCode($String, StringConstructor); % FunctionSetPrototype($String, new $String()); % AddNamedProperty($String.prototype, "constructor", $String, 2);
  657.         InstallFunctions($String, 2, $Array(
  658.                 "fromCharCode", StringFromCharCode
  659.         ));
  660.         InstallFunctions($String.prototype, 2, $Array(
  661.                 "valueOf", StringValueOf,
  662.                 "toString", StringToString,
  663.                 "charAt", StringCharAt,
  664.                 "charCodeAt", StringCharCodeAt,
  665.                 "concat", StringConcat,
  666.                 "indexOf", StringIndexOfJS,
  667.                 "lastIndexOf", StringLastIndexOfJS,
  668.                 "localeCompare", StringLocaleCompareJS,
  669.                 "match", StringMatchJS,
  670.                 "normalize", StringNormalizeJS,
  671.                 "replace", StringReplace,
  672.                 "search", StringSearch,
  673.                 "slice", StringSlice,
  674.                 "split", StringSplitJS,
  675.                 "substring", StringSubstring,
  676.                 "substr", StringSubstr,
  677.                 "toLowerCase", StringToLowerCaseJS,
  678.                 "toLocaleLowerCase", StringToLocaleLowerCase,
  679.                 "toUpperCase", StringToUpperCaseJS,
  680.                 "toLocaleUpperCase", StringToLocaleUpperCase,
  681.                 "trim", StringTrimJS,
  682.                 "trimLeft", StringTrimLeft,
  683.                 "trimRight", StringTrimRight,
  684.                 "link", StringLink,
  685.                 "anchor", StringAnchor,
  686.                 "fontcolor", StringFontcolor,
  687.                 "fontsize", StringFontsize,
  688.                 "big", StringBig,
  689.                 "blink", StringBlink,
  690.                 "bold", StringBold,
  691.                 "fixed", StringFixed,
  692.                 "italics", StringItalics,
  693.                 "small", StringSmall,
  694.                 "strike", StringStrike,
  695.                 "sub", StringSub,
  696.                 "sup", StringSup
  697.         ));
  698. }
  699. SetUpString();

评分

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

查看全部评分

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-20 14:53

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表