Example #1
0
String
getConfigDir(void)
{
    String path;
    char *buf = path.buf(MAX_PATH);
    HRESULT hr = SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, buf);
    if (SUCCEEDED(hr)) {
        path.truncate();
    } else {
        path.truncate(0);
    }
    return path;
}
Example #2
0
String directoryName(const String& path)
{
    String fileName = pathGetFileName(path);
    String dirName = String(path);
    dirName.truncate(dirName.length() - pathGetFileName(path).length());
    return dirName;
}
void Resource::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProcessMemoryDump* memoryDump) const
{
    static const size_t kMaxURLReportLength = 128;
    static const int kMaxResourceClientToShowInMemoryInfra = 10;

    const String dumpName = getMemoryDumpName();
    WebMemoryAllocatorDump* dump = memoryDump->createMemoryAllocatorDump(dumpName);
    dump->addScalar("encoded_size", "bytes", m_encodedSize);
    if (canDelete()) {
        dump->addScalar("dead_size", "bytes", m_encodedSize);
    } else {
        dump->addScalar("live_size", "bytes", m_encodedSize);
    }

    if (m_data) {
        dump->addScalar("purgeable_size", "bytes", isPurgeable() && !wasPurged() ? encodedSize() + overheadSize() : 0);
        m_data->onMemoryDump(dumpName, memoryDump);
    }

    if (levelOfDetail == WebMemoryDumpLevelOfDetail::Detailed) {
        String urlToReport = url().string();
        if (urlToReport.length() > kMaxURLReportLength) {
            urlToReport.truncate(kMaxURLReportLength);
            urlToReport = urlToReport + "...";
        }
        dump->addString("url", "", urlToReport);

        dump->addString("reason_not_deletable", "", reasonNotDeletable());

        Vector<String> clientNames;
        ResourceClientWalker<ResourceClient> walker(m_clients);
        while (ResourceClient* client = walker.next())
            clientNames.append(client->debugName());
        ResourceClientWalker<ResourceClient> walker2(m_clientsAwaitingCallback);
        while (ResourceClient* client = walker2.next())
            clientNames.append("(awaiting) " + client->debugName());
        ResourceClientWalker<ResourceClient> walker3(m_finishedClients);
        while (ResourceClient* client = walker3.next())
            clientNames.append("(finished) " + client->debugName());
        std::sort(clientNames.begin(), clientNames.end(), codePointCompareLessThan);

        StringBuilder builder;
        for (size_t i = 0; i < clientNames.size() && i < kMaxResourceClientToShowInMemoryInfra; ++i) {
            if (i > 0)
                builder.append(" / ");
            builder.append(clientNames[i]);
        }
        if (clientNames.size() > kMaxResourceClientToShowInMemoryInfra) {
            builder.append(" / and ");
            builder.appendNumber(clientNames.size() - kMaxResourceClientToShowInMemoryInfra);
            builder.append(" more");
        }
        dump->addString("ResourceClient", "", builder.toString());
    }

    const String overheadName = dumpName + "/metadata";
    WebMemoryAllocatorDump* overheadDump = memoryDump->createMemoryAllocatorDump(overheadName);
    overheadDump->addScalar("size", "bytes", overheadSize());
    memoryDump->addSuballocation(overheadDump->guid(), String(WTF::Partitions::kAllocatedObjectPoolName));
}
String Value_datetime_imp::get_String( tslen inLimit ) const
{
	String str;

	if( inLimit != 0 )
	{
		UChar* p = str.getBuffer(kDateTimeStrMaxLength + 1);

		const DTFormat* pDTFormat = get_DTFormat();

		Convert_datetime_str_fast( 
			(DateTimeEncoded&)mValue, 
			pDTFormat->mDateFormat,
			pDTFormat->mDateSep,
			pDTFormat->mTimeSep,
			p );

		if( ((DateTimeEncoded&)mValue).encoded < 0 )
			str.releaseBuffer(kDateTimeStrMaxLength);		// 24 symbols for negative dates
		else
			str.releaseBuffer(kDateTimeStrMaxLength - 1);	// 23 symbols for positive dates

		// not -1 and less than maxLen
		if( inLimit > 0 && vuint32(inLimit) < kDateTimeStrMaxLength )
		{
			str.truncate( inLimit );
		}
	}

	return str;
}
Example #5
0
void WebInspectorServer::didReceiveUnrecognizedHTTPRequest(WebSocketServerConnection* connection, PassRefPtr<HTTPRequest> request)
{
    // request->url() contains only the path extracted from the HTTP request line
    // and URL is poor at parsing incomplete URLs, so extract the interesting parts manually.
    String path = request->url();
    size_t pathEnd = path.find('?');
    if (pathEnd == notFound)
        pathEnd = path.find('#');
    if (pathEnd != notFound)
        path.truncate(pathEnd);

    // Ask for the complete payload in memory for the sake of simplicity. A more efficient way would be
    // to ask for header data and then let the platform abstraction write the payload straight on the connection.
    Vector<char> body;
    String contentType;
    bool found = platformResourceForPath(path, body, contentType);

    HTTPHeaderMap headerFields;
    headerFields.set("Connection", "close");
    headerFields.set("Content-Length", String::number(body.size()));
    if (found)
        headerFields.set("Content-Type", contentType);

    // Send when ready and close immediately afterwards.
    connection->sendHTTPResponseHeader(found ? 200 : 404, found ? "OK" : "Not Found", headerFields);
    connection->sendRawData(body.data(), body.size());
    connection->shutdownAfterSendOrNow();
}
Example #6
0
static void RemoveLastId() {
  int index = fieldId.size();
  while (index != 0 && fieldId[index - 1] != '^' && fieldId[index - 1] != ':') {
    --index;
  }
  fieldId.truncate(index);
}
Example #7
0
String StyledMarkupAccumulator::stringValueForRange(const Text& node)
{
    if (m_start.isNull())
        return node.data();

    String str = node.data();
    if (m_start.text() == node)
        str.truncate(m_end.offset());
    if (m_end.text() == node)
        str.remove(0, m_start.offset());
    return str;
}
Example #8
0
String StyledMarkupAccumulator::stringValueForRange(const Node* node, const Range* range)
{
    if (!range)
        return node->nodeValue();

    String str = node->nodeValue();
    if (node == range->endContainer())
        str.truncate(range->endOffset());
    if (node == range->startContainer())
        str.remove(0, range->startOffset());
    return str;
}
Example #9
0
String StyledMarkupAccumulator::stringValueForRange(const Node& node, const Range* range)
{
    if (!range)
        return node.nodeValue();

    String nodeValue = node.nodeValue();
    if (&node == &range->endContainer())
        nodeValue.truncate(range->endOffset());
    if (&node == &range->startContainer())
        nodeValue.remove(0, range->startOffset());
    return nodeValue;
}
void validateFilename(String& name, String& extension)
{
    // Remove any invalid file system characters.
    name = name.removeCharacters(&isInvalidFileCharacter);
    extension = extension.removeCharacters(&isInvalidFileCharacter);

    if (extension.length() >= maxFilenameLength)
        extension = String();

    // Truncate overly-long filenames, reserving one character for a dot.
    name.truncate(maxFilenameLength - extension.length() - 1);
}
Example #11
0
String StyledMarkupAccumulator::stringValueForRange(const Node& node, const Range* range)
{
    if (!node.isTextNode())
        return emptyString();
    String text = toText(node).data();
    if (!range)
        return text;
    if (node == range->endContainer())
        text.truncate(range->endOffset());
    if (node == range->startContainer())
        text.remove(0, range->startOffset());
    return text;
}
Example #12
0
String
getCurrentDir(void)
{
    String path;
    DWORD size = MAX_PATH;
    char *buf = path.buf(size);
    
    DWORD ret = GetCurrentDirectoryA(size, buf);
    (void)ret;
    
    buf[size - 1] = 0;
    path.truncate();

    return path;
}
Example #13
0
String Value_money_imp::get_String( tslen inLimit ) const
{
	String str;
	
	if( inLimit != 0 )
	{
		tslen MaxLen = get_MaxChars();
		tslen BuffLength = MaxLen + 1;
		UChar* pBuffer = str.getBuffer( BuffLength );
		UChar* pEnd    = get_String( pBuffer, MaxLen ); // copy str into buffer.

		str.releaseBuffer( static_cast<tslen>(pEnd - pBuffer) );

		// not -1 and less than maxLen
		if( inLimit > 0 && inLimit < MaxLen )
		{
			str.truncate( inLimit );
		}
	}
	
	return str;
}
void TextFieldInputType::handleBeforeTextInsertedEvent(BeforeTextInsertedEvent* event)
{
    // Make sure that the text to be inserted will not violate the maxLength.

    // We use RenderTextControlSingleLine::text() instead of InputElement::value()
    // because they can be mismatched by sanitizeValue() in
    // HTMLInputElement::subtreeHasChanged() in some cases.
    String innerText = element().innerTextValue();
    unsigned oldLength = numGraphemeClusters(innerText);

    // selectionLength represents the selection length of this text field to be
    // removed by this insertion.
    // If the text field has no focus, we don't need to take account of the
    // selection length. The selection is the source of text drag-and-drop in
    // that case, and nothing in the text field will be removed.
    unsigned selectionLength = 0;
    if (element().focused()) {
        ASSERT(enclosingTextFormControl(element().document().frame()->selection().selection().start()) == &element());
        selectionLength = numGraphemeClusters(innerText.substring(element().selectionStart(), element().selectionEnd()));
    }
    ASSERT(oldLength >= selectionLength);

    // Selected characters will be removed by the next text event.
    unsigned baseLength = oldLength - selectionLength;
    unsigned maxLength = static_cast<unsigned>(isTextType() ? element().maxLength() : HTMLInputElement::maximumLength); // maxLength can never be negative.
    unsigned appendableLength = maxLength > baseLength ? maxLength - baseLength : 0;

    // Truncate the inserted text to avoid violating the maxLength and other constraints.
    String eventText = event->text();
    unsigned textLength = eventText.length();
    while (textLength > 0 && isASCIILineBreak(eventText[textLength - 1]))
        textLength--;
    eventText.truncate(textLength);
    eventText.replace("\r\n", " ");
    eventText.replace('\r', ' ');
    eventText.replace('\n', ' ');

    event->setText(limitLength(eventText, appendableLength));
}
void TextFieldInputType::handleBeforeTextInsertedEvent(BeforeTextInsertedEvent* event)
{
    // Make sure that the text to be inserted will not violate the maxLength.

    // We use HTMLInputElement::innerEditorValue() instead of
    // HTMLInputElement::value() because they can be mismatched by
    // sanitizeValue() in HTMLInputElement::subtreeHasChanged() in some cases.
    unsigned oldLength = element().innerEditorValue().length();

    // selectionLength represents the selection length of this text field to be
    // removed by this insertion.
    // If the text field has no focus, we don't need to take account of the
    // selection length. The selection is the source of text drag-and-drop in
    // that case, and nothing in the text field will be removed.
    unsigned selectionLength = 0;
    if (element().focused()) {
        const VisibleSelection& selection = element().document().frame()->selection().selection();
        selectionLength = plainText(selection.toNormalizedEphemeralRange()).length();
    }
    ASSERT(oldLength >= selectionLength);

    // Selected characters will be removed by the next text event.
    unsigned baseLength = oldLength - selectionLength;
    unsigned maxLength = static_cast<unsigned>(this->maxLength()); // maxLength can never be negative.
    unsigned appendableLength = maxLength > baseLength ? maxLength - baseLength : 0;

    // Truncate the inserted text to avoid violating the maxLength and other constraints.
    String eventText = event->text();
    unsigned textLength = eventText.length();
    while (textLength > 0 && isASCIILineBreak(eventText[textLength - 1]))
        textLength--;
    eventText.truncate(textLength);
    eventText.replace("\r\n", " ");
    eventText.replace('\r', ' ');
    eventText.replace('\n', ' ');

    event->setText(limitLength(eventText, appendableLength));
}
Example #16
0
static void RemoveLastIdChar() {
  if (fieldId.size() != 0) {
    fieldId.truncate(fieldId.size() - 1);
  }
}