Exemplo n.º 1
0
std::wstring CServerPath::GetSafePath() const
{
	if (empty()) {
		return std::wstring();
	}

	#define INTLENGTH 20 // 2^64 - 1

	int len = 5 // Type and 2x' ' and terminating 0
		+ INTLENGTH; // Max length of prefix

	len += m_data->m_prefix ? m_data->m_prefix->size() : 0;
	for (auto const& segment : m_data->m_segments) {
		len += segment.size() + 2 + INTLENGTH;
	}

	std::wstring safepath;
	safepath.resize(len);
	wchar_t * const start = &safepath[0];
	wchar_t * t = &safepath[0];

	t = fast_sprint_number(t, m_type);
	*(t++) = ' ';
	t = fast_sprint_number(t, m_data->m_prefix ? m_data->m_prefix->size() : 0);

	if (m_data->m_prefix) {
		*(t++) = ' ';
		tstrcpy(t, m_data->m_prefix->c_str());
		t += m_data->m_prefix->size();
	}

	for (auto const& segment : m_data->m_segments) {
		*(t++) = ' ';
		t = fast_sprint_number(t, segment.size());
		*(t++) = ' ';
		tstrcpy(t, segment.c_str());
		t += segment.size();
	}
	safepath.resize(t - start);
	safepath.shrink_to_fit();

	return safepath;
}
Exemplo n.º 2
0
wxString CServerPath::GetSafePath() const
{
	if (empty())
		return wxString();

	#define INTLENGTH 20 // 2^64 - 1

	int len = 5 // Type and 2x' ' and terminating 0
		+ INTLENGTH; // Max length of prefix

	len += m_data->m_prefix ? m_data->m_prefix->size() : 0;
	for( auto const& segment : m_data->m_segments ) {
		len += segment.size() + 2 + INTLENGTH;
	}

	wxString safepath;
	{
		wxStringBuffer start(safepath, len);
		wxChar* t = start;

		t = fast_sprint_number(t, m_type);
		*(t++) = ' ';
		t = fast_sprint_number(t, m_data->m_prefix ? m_data->m_prefix->size() : 0);

		if (m_data->m_prefix) {
			*(t++) = ' ';
			tstrcpy(t, m_data->m_prefix->c_str());
			t += m_data->m_prefix->size();
		}

		for( auto const& segment : m_data->m_segments ) {
			*(t++) = ' ';
			t = fast_sprint_number(t, segment.size());
			*(t++) = ' ';
			tstrcpy(t, segment.c_str());
			t += segment.size();
		}
		*t = 0;
	}
	safepath.Shrink();

	return safepath;
}