📄 stringprototype.cpp
字号:
if (i != limit) result->put(exec, i++, jsSubstring(exec, s, p0, s.size() - p0)); return result;}JSValuePtr stringProtoFuncSubstr(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList& args){ UString s = thisValue.toThisString(exec); int len = s.size(); JSValuePtr a0 = args.at(exec, 0); JSValuePtr a1 = args.at(exec, 1); double start = a0.toInteger(exec); double length = a1.isUndefined() ? len : a1.toInteger(exec); if (start >= len || length <= 0) return jsEmptyString(exec); if (start < 0) { start += len; if (start < 0) start = 0; } if (start + length > len) length = len - start; return jsSubstring(exec, s, static_cast<unsigned>(start), static_cast<unsigned>(length));}JSValuePtr stringProtoFuncSubstring(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList& args){ UString s = thisValue.toThisString(exec); int len = s.size(); JSValuePtr a0 = args.at(exec, 0); JSValuePtr a1 = args.at(exec, 1); double start = a0.toNumber(exec); double end = a1.toNumber(exec); if (isnan(start)) start = 0; if (isnan(end)) end = 0; if (start < 0) start = 0; if (end < 0) end = 0; if (start > len) start = len; if (end > len) end = len; if (a1.isUndefined()) end = len; if (start > end) { double temp = end; end = start; start = temp; } return jsSubstring(exec, s, static_cast<unsigned>(start), static_cast<unsigned>(end) - static_cast<unsigned>(start));}JSValuePtr stringProtoFuncToLowerCase(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList&){ JSString* sVal = thisValue.toThisJSString(exec); const UString& s = sVal->value(); int sSize = s.size(); if (!sSize) return sVal; const UChar* sData = s.data(); Vector<UChar> buffer(sSize); UChar ored = 0; for (int i = 0; i < sSize; i++) { UChar c = sData[i]; ored |= c; buffer[i] = toASCIILower(c); } if (!(ored & ~0x7f)) return jsString(exec, UString(buffer.releaseBuffer(), sSize, false)); bool error; int length = Unicode::toLower(buffer.data(), sSize, sData, sSize, &error); if (error) { buffer.resize(length); length = Unicode::toLower(buffer.data(), length, sData, sSize, &error); if (error) return sVal; } if (length == sSize && memcmp(buffer.data(), sData, length * sizeof(UChar)) == 0) return sVal; return jsString(exec, UString(buffer.releaseBuffer(), length, false));}JSValuePtr stringProtoFuncToUpperCase(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList&){ JSString* sVal = thisValue.toThisJSString(exec); const UString& s = sVal->value(); int sSize = s.size(); if (!sSize) return sVal; const UChar* sData = s.data(); Vector<UChar> buffer(sSize); UChar ored = 0; for (int i = 0; i < sSize; i++) { UChar c = sData[i]; ored |= c; buffer[i] = toASCIIUpper(c); } if (!(ored & ~0x7f)) return jsString(exec, UString(buffer.releaseBuffer(), sSize, false)); bool error; int length = Unicode::toUpper(buffer.data(), sSize, sData, sSize, &error); if (error) { buffer.resize(length); length = Unicode::toUpper(buffer.data(), length, sData, sSize, &error); if (error) return sVal; } if (length == sSize && memcmp(buffer.data(), sData, length * sizeof(UChar)) == 0) return sVal; return jsString(exec, UString(buffer.releaseBuffer(), length, false));}JSValuePtr stringProtoFuncLocaleCompare(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList& args){ if (args.size() < 1) return jsNumber(exec, 0); UString s = thisValue.toThisString(exec); JSValuePtr a0 = args.at(exec, 0); return jsNumber(exec, localeCompare(s, a0.toString(exec)));}JSValuePtr stringProtoFuncBig(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList&){ UString s = thisValue.toThisString(exec); return jsNontrivialString(exec, "<big>" + s + "</big>");}JSValuePtr stringProtoFuncSmall(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList&){ UString s = thisValue.toThisString(exec); return jsNontrivialString(exec, "<small>" + s + "</small>");}JSValuePtr stringProtoFuncBlink(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList&){ UString s = thisValue.toThisString(exec); return jsNontrivialString(exec, "<blink>" + s + "</blink>");}JSValuePtr stringProtoFuncBold(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList&){ UString s = thisValue.toThisString(exec); return jsNontrivialString(exec, "<b>" + s + "</b>");}JSValuePtr stringProtoFuncFixed(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList&){ UString s = thisValue.toThisString(exec); return jsString(exec, "<tt>" + s + "</tt>");}JSValuePtr stringProtoFuncItalics(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList&){ UString s = thisValue.toThisString(exec); return jsNontrivialString(exec, "<i>" + s + "</i>");}JSValuePtr stringProtoFuncStrike(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList&){ UString s = thisValue.toThisString(exec); return jsNontrivialString(exec, "<strike>" + s + "</strike>");}JSValuePtr stringProtoFuncSub(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList&){ UString s = thisValue.toThisString(exec); return jsNontrivialString(exec, "<sub>" + s + "</sub>");}JSValuePtr stringProtoFuncSup(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList&){ UString s = thisValue.toThisString(exec); return jsNontrivialString(exec, "<sup>" + s + "</sup>");}JSValuePtr stringProtoFuncFontcolor(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList& args){ UString s = thisValue.toThisString(exec); JSValuePtr a0 = args.at(exec, 0); return jsNontrivialString(exec, "<font color=\"" + a0.toString(exec) + "\">" + s + "</font>");}JSValuePtr stringProtoFuncFontsize(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList& args){ UString s = thisValue.toThisString(exec); JSValuePtr a0 = args.at(exec, 0); uint32_t smallInteger; if (a0.getUInt32(smallInteger) && smallInteger <= 9) { unsigned stringSize = s.size(); unsigned bufferSize = 22 + stringSize; UChar* buffer = static_cast<UChar*>(tryFastMalloc(bufferSize * sizeof(UChar))); if (!buffer) return jsUndefined(); buffer[0] = '<'; buffer[1] = 'f'; buffer[2] = 'o'; buffer[3] = 'n'; buffer[4] = 't'; buffer[5] = ' '; buffer[6] = 's'; buffer[7] = 'i'; buffer[8] = 'z'; buffer[9] = 'e'; buffer[10] = '='; buffer[11] = '"'; buffer[12] = '0' + smallInteger; buffer[13] = '"'; buffer[14] = '>'; memcpy(&buffer[15], s.data(), stringSize * sizeof(UChar)); buffer[15 + stringSize] = '<'; buffer[16 + stringSize] = '/'; buffer[17 + stringSize] = 'f'; buffer[18 + stringSize] = 'o'; buffer[19 + stringSize] = 'n'; buffer[20 + stringSize] = 't'; buffer[21 + stringSize] = '>'; return jsNontrivialString(exec, UString(buffer, bufferSize, false)); } return jsNontrivialString(exec, "<font size=\"" + a0.toString(exec) + "\">" + s + "</font>");}JSValuePtr stringProtoFuncAnchor(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList& args){ UString s = thisValue.toThisString(exec); JSValuePtr a0 = args.at(exec, 0); return jsNontrivialString(exec, "<a name=\"" + a0.toString(exec) + "\">" + s + "</a>");}JSValuePtr stringProtoFuncLink(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList& args){ UString s = thisValue.toThisString(exec); JSValuePtr a0 = args.at(exec, 0); UString linkText = a0.toString(exec); unsigned linkTextSize = linkText.size(); unsigned stringSize = s.size(); unsigned bufferSize = 15 + linkTextSize + stringSize; UChar* buffer = static_cast<UChar*>(tryFastMalloc(bufferSize * sizeof(UChar))); if (!buffer) return jsUndefined(); buffer[0] = '<'; buffer[1] = 'a'; buffer[2] = ' '; buffer[3] = 'h'; buffer[4] = 'r'; buffer[5] = 'e'; buffer[6] = 'f'; buffer[7] = '='; buffer[8] = '"'; memcpy(&buffer[9], linkText.data(), linkTextSize * sizeof(UChar)); buffer[9 + linkTextSize] = '"'; buffer[10 + linkTextSize] = '>'; memcpy(&buffer[11 + linkTextSize], s.data(), stringSize * sizeof(UChar)); buffer[11 + linkTextSize + stringSize] = '<'; buffer[12 + linkTextSize + stringSize] = '/'; buffer[13 + linkTextSize + stringSize] = 'a'; buffer[14 + linkTextSize + stringSize] = '>'; return jsNontrivialString(exec, UString(buffer, bufferSize, false));}} // namespace JSC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -