コード例 #1
0
ファイル: Context.cpp プロジェクト: hackshields/antivirus
std::string Context::fullContextInfo() const {
	std::string lineInfo;
	
	if (getFirstLine() == getLastLine()) {
		lineInfo = (boost::format("%1%.%2%-%3%") % getFirstLine() % getFirstColon() % getLastColon()).str();
	} else {
		lineInfo = (boost::format("%1%.%2%-%3%.%4%") % getFirstLine() % getFirstColon() % getLastLine() % getLastColon()).str();
	}

	return (boost::format("[%1%: %2% `%3%']") % getSource() % lineInfo % getText()).str();
}
コード例 #2
0
ファイル: Context.cpp プロジェクト: hackshields/antivirus
std::string	Context::shortContextInfo() const {
	std::string lineInfo;
	
	if (getFirstLine() == getLastLine()) {
		lineInfo = (boost::format("%1%.%2%-%3%") % getFirstLine() % getFirstColon() % getLastColon()).str();
	} else {
		lineInfo = (boost::format("%1%.%2%-%3%.%4%") % getFirstLine() % getFirstColon() % getLastLine() % getLastColon()).str();
	}

	return (boost::format("%1%(%2%)") % getSource() % lineInfo).str();
}
コード例 #3
0
ファイル: mailbox.cpp プロジェクト: HeberPcL/forgottenserver
bool Mailbox::getReceiver(Item* item, std::string& name)
{
	if (!item) {
		return false;
	}

	if (item->getID() == ITEM_PARCEL) { /**We need to get the text from the label incase its a parcel**/
		Container* parcel = item->getContainer();
		if (parcel) {
			for (ItemDeque::const_iterator cit = parcel->getItems(), end = parcel->getEnd(); cit != end; ++cit) {
				if ((*cit)->getID() == ITEM_LABEL) {
					item = (*cit);
					if (!item->getText().empty()) {
						break;
					}
				}
			}
		}
	} else if (item->getID() != ITEM_LETTER) { /**The item is somehow not a parcel or letter**/
		std::cout << "Mailbox::getReciver error, trying to get reciecer from unkown item! ID: " << item->getID() << "." << std::endl;
		return false;
	}

	if (!item || item->getText().empty()) { /**No label/letter found or its empty.**/
		return false;
	}

	name = getFirstLine(item->getText());
	trimString(name);
	return true;
}
コード例 #4
0
ファイル: Context.cpp プロジェクト: hackshields/antivirus
std::string Context::mediumContextInfo() const {
	std::string lineInfo;

	std::string text = getText();
	
	const size_t MaxInfoLength = 16;
	if (text.length() > MaxInfoLength) {
		text = text.substr(0, MaxInfoLength) + "...";
	}
		
	if (getFirstLine() == getLastLine()) {
		lineInfo = (boost::format("%1%.%2%-%3%") % getFirstLine() % getFirstColon() % getLastColon()).str();
	} else {
		lineInfo = (boost::format("%1%.%2%-%3%.%4%") % getFirstLine() % getFirstColon() % getLastLine() % getLastColon()).str();
	}

	return (boost::format("[%1%: %2%] `%3%'") % getSource() % lineInfo % text).str();
}
コード例 #5
0
ファイル: to_utf8_test.cpp プロジェクト: 0xmono/openmw
/// Test character encoding conversion to and from UTF-8
void testEncoder(ToUTF8::FromType encoding, const std::string &legacyEncFile,
                 const std::string &utf8File)
{
    // get some test data
    std::string legacyEncLine = getFirstLine(legacyEncFile);
    std::string utf8Line = getFirstLine(utf8File);

    // create an encoder for specified character encoding
    ToUTF8::Utf8Encoder encoder (encoding);

    // convert text to UTF-8
    std::string convertedUtf8Line = encoder.getUtf8(legacyEncLine);

    std::cout << "original:  " << utf8Line          << std::endl;
    std::cout << "converted: " << convertedUtf8Line << std::endl;

    // check correctness
    assert(convertedUtf8Line == utf8Line);

    // convert UTF-8 text to legacy encoding
    std::string convertedLegacyEncLine = encoder.getLegacyEnc(utf8Line);
    // check correctness
    assert(convertedLegacyEncLine == legacyEncLine);
}
コード例 #6
0
ファイル: LOOLProtocol.cpp プロジェクト: pranavk/online
    std::string getAbbreviatedMessage(const char *message, const int length)
    {
        if (message == nullptr || length <= 0)
        {
            return "";
        }

        const auto firstLine = getFirstLine(message, length);

        // If first line is less than the length (minus newline), add eclipes.
        if (firstLine.size() < static_cast<std::string::size_type>(length) - 1)
        {
            return std::string('\'' + firstLine + "'...");
        }

        return std::string('\'' + firstLine + '\'');
    }
コード例 #7
0
/*------------------------------------------------------------------------*/
BOOL HistoryManager::loadFromFile(char *filename)
{

    if (filename)
    {
        char *commentbeginsession = NULL;

        std::string name;
        name.assign(filename);

        if (my_file.loadFromFile(name) == HISTORY_TRUNCATED)
        {
            bTruncated = TRUE;
        }

        CommandsList.clear();
        CommandsList = my_file.getHistory();

        if (CommandsList.size() > 0)
        {
            char *firstLine = getFirstLine();

            if (firstLine)
            {
                if (!isBeginningSessionLine(firstLine))
                {
                    fixHistorySession();
                }
                FREE(firstLine);
                firstLine = NULL;
            }
        }

        /* add date & time @ begin session */
        commentbeginsession = getCommentDateSession(FALSE);
        appendLine(commentbeginsession);
        FREE(commentbeginsession);
        commentbeginsession = NULL;

        CommandHistoryLoadFromFile();

        return TRUE;
    }
    return FALSE;
}
コード例 #8
0
ファイル: Protocol.hpp プロジェクト: LibreOffice/online
    /// Returns an abbereviation of the message (the first line, indicating truncation). We assume
    /// that it adhers to the LOOL protocol, i.e. that there is always a first (or only) line that
    /// is in printable UTF-8. I.e. no encoding of binary bytes is done. The format of the result is
    /// not guaranteed to be stable. It is to be used for logging purposes only, not for decoding
    /// protocol frames.
    inline
    std::string getAbbreviatedMessage(const char *message, const int length)
    {
        if (message == nullptr || length <= 0)
        {
            return std::string();
        }

        const std::string firstLine = getFirstLine(message, std::min(length, 500));

        // If first line is less than the length (minus newline), add ellipsis.
        if (firstLine.size() < static_cast<std::string::size_type>(length) - 1)
        {
            return firstLine + "...";
        }

        return firstLine;
    }
コード例 #9
0
bool Mailbox::getReceiver(Item* item, std::string& name)
{
	if (!item) {
		return false;
	}

	const std::string* text = nullptr;

	if (item->getID() == ITEM_PARCEL) { /**We need to get the text from the label incase its a parcel**/
		Container* parcel = item->getContainer();
		if (parcel) {
			for (Item* parcelItem : parcel->getItemList()) {
				if (parcelItem->getID() == ITEM_LABEL) {
					item = parcelItem;
					text = &item->getText();
					if (!text->empty()) {
						break;
					}
				}
			}
		}
	} else if (item->getID() != ITEM_LETTER) { /**The item is somehow not a parcel or letter**/
		std::cout << "Mailbox::getReciver error, trying to get reciecer from unkown item! ID: " << item->getID() << '.' << std::endl;
		return false;
	}

	if (!item) {
		return false;
	}

	if (!text) {
		text = &item->getText();
	}

	if (text->empty()) {
		return false;
	}

	name = getFirstLine(*text);
	trimString(name);
	return true;
}
コード例 #10
0
/*------------------------------------------------------------------------*/
BOOL HistoryManager::loadFromFile(char* _pstFilename)
{
    if (_pstFilename)
    {
        char* pstCommentBeginSession = NULL;
        if (m_HF.loadFromFile(_pstFilename) == HISTORY_TRUNCATED)
        {
            m_bTruncated = TRUE;
        }

        m_Commands.clear();
        m_Commands = m_HF.getHistory();

        if (m_Commands.size() > 0)
        {
            char* pstFirstLine = getFirstLine();
            if (pstFirstLine)
            {
                if (!isBeginningSessionLine(pstFirstLine))
                {
                    fixHistorySession();
                }
                FREE(pstFirstLine);
                pstFirstLine = NULL;
            }
        }

        /* add date & time @ begin session */
        pstCommentBeginSession = getCommentDateSession(FALSE);
        appendLine(pstCommentBeginSession);
        FREE(pstCommentBeginSession);
        pstCommentBeginSession = NULL;

        CommandHistoryLoadFromFile();

        return TRUE;
    }
    return FALSE;
}
コード例 #11
0
ファイル: LOOLProtocol.hpp プロジェクト: BJFletcher94/online
 std::string getFirstLine(const T& message)
 {
     return getFirstLine(message.data(), message.size());
 }