Пример #1
0
void
editor_type::substhere (
    std::wstring::const_iterator const bos,
    std::wstring const& replacement,
    std::vector<std::size_t>& cap, std::wstring& doc)
{
    std::wstring::const_iterator i;
    for (i = replacement.cbegin (); i < replacement.cend (); ++i)
        if ('$' == i[0] && i + 1 < replacement.cend ()
                && ('&' == i[1] || ('0' <= i[1] && i[1] <= '9'))) {
            std::size_t n = '&' == i[1] ? 0 : i[1] - '0';
            if (n * 2 + 1 < cap.size ()
                    && cap[n * 2] != std::wstring::npos
                    && cap[n * 2 + 1] != std::wstring::npos)
                doc.append (bos + cap[n * 2], bos + cap[n * 2 + 1]);
            ++i;
        }
        else if ('\\' == *i && i + 1 < replacement.cend ()) {
            int c = *++i;
            c = 'n' == c ? '\n' : 't' == c ? '\t' : c;
            doc.push_back (c);
        }
        else
            doc.push_back (*i);
}
Пример #2
0
 // Format wide character versions of the above.
 std::string format_value(std::wstring const& value)
 {
     static_assert(sizeof(wchar_t) == 2, "This method needs to be inspected / updated if wchar_t is not UTF-16.");
     std::string result;
     result.reserve(value.size());
     utf8::utf16to8(value.cbegin(), value.cend(), std::back_inserter(result));
     return result;
 }
Пример #3
0
void MultiLineTextView::typesetGlyphs(const std::wstring& str,
                                      const zeus::CColor& defaultColor,
                                      unsigned wrap)
{
    if (wrap)
    {
        typesetGlyphs(LineWrap(str, wrap), defaultColor);
        return;
    }

    m_width = 0;
    m_lines.clear();
    size_t rem = str.size() + 1;
    auto it = str.cbegin();

    size_t lineCount = 0;
    while (rem)
    {
        if (*it == L'\n' || *it == L'\0')
            ++lineCount;
        --rem;
        ++it;
    }

    m_lines.reserve(lineCount);
    rem = str.size() + 1;
    it = str.cbegin();
    auto beginIt = it;

    while (rem)
    {
        if (*it == L'\n' || *it == L'\0')
        {
            m_lines.emplace_back(new TextView(m_viewSystem, *this, m_fontAtlas, m_align, m_lineCapacity));
            m_lines.back()->typesetGlyphs(std::wstring(beginIt, it), defaultColor);
            m_width = std::max(m_width, m_lines.back()->nominalWidth());
            beginIt = it + 1;
        }
        --rem;
        ++it;
    }

    updateSize();
}
Пример #4
0
    path::path(std::wstring const& string)
        : capacity_(0)
        , base_(nullptr)
    {
        this->size_ = string.size();
        this->ensure_capacity(string.size());

        auto upperStart = this->upperBase();
        std::copy(string.cbegin(), string.cend(), this->base_);
        this->base_[this->size_] = L'\0';
        path::uppercase_range(this->size_, this->base_, upperStart);
        upperStart[this->size_] = L'\0';
    }
Пример #5
0
void
editor_type::unquote (std::wstring const& src, std::wstring& dst)
{
    std::wstring::const_iterator i;
    for (i = src.cbegin (); i < src.cend (); ++i)
        if ('\\' == *i && i + 1 < src.cend ()) {
            int c = *++i;
            c = 'n' == c ? '\n' : 't' == c ? '\t' : c;
            dst.push_back (c);
        }
        else
            dst.push_back (*i);
}
Пример #6
0
ulong CCmdLog::msg(ulong id, const std::wstring& msg, bool append)
{
	std::wstring *pmsg; LPLOGGER plog; if (id <= 0) return 0;

	EnterCriticalSection(&m_csShare);

	// Initialize the sorted data if it hasn't initialize yet ..
	if (Issortedinit(&m_Table.sorted) == 0) {
		if (Createsorteddata (				// Make sure it's already initialized.
			&m_Table.sorted,			// Descriptor of sorted data
			sizeof(LOGGER),					// Size of single data item
			10,									// Initial number of allocated items
			(SORTFUNC *)CCmdLog::SortProc,	// Sorting function
			(DESTFUNC *)CCmdLog::DestProc,	// Data destructor
			0
		) != 0)  { LeaveCriticalSection(&m_csShare); return 0; }
	}
	
	
	// Get the logger ..
	void *temp = Findsorteddata(&m_Table.sorted, id, 0);
	if ((plog = reinterpret_cast<LPLOGGER>(temp)) != nullptr) {

		m_Table.custommode -= plog->rows;

		pmsg = reinterpret_cast<std::wstring*>(plog->msge);
		if (pmsg == nullptr) pmsg = new std::wstring();
		if (append == false) { pmsg->clear(); plog->rows = 0; }
		else if (pmsg->back() != text('\n')) --plog->rows;
		// Extract the message ...
		std::wstring::const_iterator itr, eitr = msg.cend();
		for (itr = msg.cbegin(); itr != eitr; ++itr) {
			// We don't support old mac format ...
			if (*itr == text('\t')) { pmsg->append(8, text(' ')); continue; }
			if (*itr == text('\r')) continue;
			if (*itr == text('\n')) ++ plog->rows;
			pmsg->push_back(*itr);
		} if (pmsg->back() != text('\n')) ++ plog->rows;
		plog->msge = pmsg;			// Set the string ...

		m_Table.custommode += plog->rows;

	} else id = 0;	// return 0 if the logger doesn't exist.

	LeaveCriticalSection(&m_csShare);

	// Redrawing the logger window and return ..
	if (m_Table.offset <= 0) Updatetable(&m_Table, false);
	else PostMessage(m_Table.hw,WM_VSCROLL,SB_PAGEDOWN,0); 
	return id;
}
Пример #7
0
std::wstring MultiLineTextView::LineWrap(const std::wstring& str, int wrap)
{
    uint32_t lCh = -1;
    int adv = 0;

    std::wstring ret;
    ret.reserve(str.size());
    std::wstring::const_iterator lastSpaceIt = str.cend();
    size_t rollbackPos;
    for (std::wstring::const_iterator it = str.cbegin() ; it != str.cend() ; ++it)
    {
        wchar_t ch = *it;
        if (ch == L'\n')
        {
            ret += L'\n';
            lCh = -1;
            lastSpaceIt = str.cend();
            adv = 0;
            continue;
        }

        const FontAtlas::Glyph* glyph = m_fontAtlas.lookupGlyph(ch);
        if (!glyph)
            continue;

        if (lCh != -1)
            adv += TextView::DoKern(m_fontAtlas.lookupKern(lCh, glyph->m_glyphIdx), m_fontAtlas);
        adv += glyph->m_advance;

        if (adv > wrap && lastSpaceIt != str.cend())
        {
            ret.assign(ret.cbegin(), ret.cbegin() + rollbackPos);
            ret += L'\n';
            lCh = -1;
            it = lastSpaceIt;
            lastSpaceIt = str.cend();
            adv = 0;
            continue;
        }

        if (ch == L' ' || ch == L'-')
        {
            lastSpaceIt = it + 1;
            rollbackPos = ret.size() + 1;
        }
        ret += ch;
        lCh = glyph->m_glyphIdx;
    }

    return ret;
}
Пример #8
0
std::wstring ParseExtensionFromString(const std::wstring& src)
{
	std::wstring::const_iterator extensionStart = src.cend();

	for (auto it = src.cbegin(); it != src.cend(); it++)
	{
		if ((*it) == '.')
		{
			extensionStart = it;
		}
	}

	return std::wstring(extensionStart, src.cend());
}
Пример #9
0
bool WStrToUtf8(const std::wstring& wstr, std::string& utf8str)
{
    try
    {
        std::string utf8str2;
        utf8str2.resize(wstr.size() * 4);                   // allocate for most long case

        auto end = utf8::utf16to8(wstr.cbegin(), wstr.cend(), utf8str2.begin());
        if (end != utf8str2.end())
            utf8str2.erase(end, utf8str2.end());

        utf8str = utf8str2;
    }
    catch (const std::exception&)
    {
        utf8str = "";
        return false;
    }

    return true;
}
Пример #10
0
ulong CCmdLog::log(ulong id, int code, int type, const std::wstring &msg)
{
	std::wstring *pmsg = nullptr; void *temp = nullptr;
	LPLOGGER plog = nullptr; ulong ulNewId = 0;

	EnterCriticalSection(&m_csShare);

	if (Issortedinit(&m_Table.sorted) == 0) {
		if (Createsorteddata (				// Make sure it's already initialized.
			&m_Table.sorted,					// Descriptor of sorted data
			sizeof(LOGGER),					// Size of single data item
			10,									// Initial number of allocated items
			(SORTFUNC *)CCmdLog::SortProc,	// Sorting function
			(DESTFUNC *)CCmdLog::DestProc,	// Data destructor
			0
		) != 0) { LeaveCriticalSection(&m_csShare); return 0; }
	}
	
	if (id <= 0) {							// Add new record ..
		// Can't add logger any more ...
		if (m_Table.custommode < MAXINT) {

			// Find a new id ..
			while (Findsorteddata(&m_Table.sorted, m_nNextId, 0))
				++ m_nNextId;

			// Initialize a new item ...
			time_t timer; time(&timer); LOGGER logger = {
				m_nNextId, 1, type, 0, LOGGER_FLAG_IDLE, 
				timer, code, nullptr
			};
			// Initialize a new string.. (it's suck without c++11)
			std::wstring *pmsg = new std::wstring();
			std::wstring::const_iterator itr, eitr = msg.cend();
			for (itr = msg.cbegin(); itr != eitr; ++itr) {
				// We don't support old mac format ...
				if (*itr == text('\r')) continue;
				if (*itr == text('\n')) ++logger.rows;
				pmsg->push_back(*itr);
			} if (pmsg->back() != text('\n')) {
				pmsg->push_back(text('\n')); ++logger.rows;
			}	logger.msge = pmsg;	// Set the string ....

			// Add a new item and return it's id ..
			temp = Addsorteddata(&m_Table.sorted, &logger);;
			plog = reinterpret_cast<LPLOGGER>(temp);
			if (plog != nullptr) ulNewId = plog->addr;
			else { ulNewId = 0; delete logger.msge; }
			
			// Update the line count ..
			if (plog) m_Table.custommode += plog->rows;
			
		}
		
	} else {									// Modify existed records .
		temp = Findsorteddata(&m_Table.sorted, id, 0);
		if ((plog = reinterpret_cast<LPLOGGER>(temp)) != nullptr) {

			m_Table.custommode -= plog->rows;

			// Update the logger ..
			plog->code = code; plog->type = type; plog->rows = 0;
			pmsg = reinterpret_cast<std::wstring*>(plog->msge);
			if (pmsg == nullptr) pmsg = new std::wstring();
			else pmsg->clear();		// Clear the message first..
			std::wstring::const_iterator itr, eitr = msg.cend();
			for (itr = msg.cbegin(); itr != eitr; ++itr) {
				// We don't support old mac format ...
				if (*itr == text('\r')) continue;
				if (*itr == text('\n')) ++plog->rows;
				pmsg->push_back(*itr);
			} if (pmsg->back() != text('\n')) {
				pmsg->push_back(text('\n')); ++plog->rows;
			}	plog->msge = pmsg;		// Set the string ....

			m_Table.custommode += plog->rows;

			// Return this id .
			ulNewId = plog->addr;
		
		}
	}

	LeaveCriticalSection(&m_csShare);

	// Redrawing the logger window and return ..
	if (m_Table.offset <= 0) Updatetable(&m_Table, false);
	else PostMessage(m_Table.hw,WM_VSCROLL,SB_PAGEDOWN,0); 
	return ulNewId;
}
Пример #11
0
	Message::bytes Message::serializeUTF16(const std::wstring& str)
	{
		std::string u;
		utf8::utf16to8(str.cbegin(), str.cend(), std::back_inserter(u));
		return serializeString(u);
	}