Esempio n. 1
0
void MCParagraph::Replace(uint4 p_start, uint4 p_finish, const MCParagraph *p_other, uint4 p_other_start, uint4 p_other_finish)
{
	assert(p_start <= p_finish);
	assert(p_finish <= m_text_size);

	assert(p_other_start <= p_other_finish);
	assert(p_other_finish <= p_other -> m_text_size);

	ReplaceText(p_start, p_finish, p_other -> m_text, p_other_start, p_other_finish);
	DeleteStyles(p_start, p_finish);

	uint4 t_at;
	SearchStyleEntries(p_start, t_at);

	uint4 *t_other_styles;
	t_other_styles = p_other -> m_styles;

	uint4 t_other_lower, t_other_upper;
	DoSearchStyleEntries(p_other -> m_styles,

}

void MCParagraph::Compact(void)
{
	if (m_text != NULL)
	{
		if (m_text_size == 0)
		{
			free(m_text);
			m_text = NULL;
		}
		else
			m_text = realloc(m_text, m_text_size);

		m_state &= ~kStateTextAvailable;
	}

	if (m_styles != NULL)
	{
		if (m_styles_size == 0)
		{
			free(m_styles);
			m_styles = NULL;
		}
		else if (m_styles_size == 2 && GetStyleEntryIndex(m_styles[0]) == 0)
		{
			free(m_styles);
			m_styles = NULL;
			m_styles_size = 0;
		}
		else
			m_styles = (uint4 *)realloc(m_styles, sizeof(uint4) * m_styles_size);

		m_state &= ~kStateStylesAvailable;
	}
}

///////////////////////////////////////////////////////////////////////////////

void MCParagraph::DestroyText(void)
{
	if (m_text == NULL)
		return;

	free(m_text);
	m_text_size = 0;
}


void MCParagraph::DestroyStyles(void)
{
	if (m_styles == NULL)
		return;

	for(uint4 i = 0; i < m_styles_size; ++i)
		ReleaseCharStyle(GetStyleEntryIndex(m_styles[i]));

	free(m_styles);
	m_styles_size = 0;
}

void MCParagraph::DestroyLines(void)
{
	if (m_lines == NULL)
		return;

	free(m_lines);
	m_lines_size = 0;
}

///////////////////////////////////////////////////////////////////////////////

static inline bool CloneBuffer(const void *p_buffer, uint2 p_buffer_size, void** r_new_buffer)
{
	if (p_buffer_size == 0)
	{
		*r_new_buffer = NULL;
		return true;
	}

	*r_new_buffer = malloc(p_buffer_size);
	if (*r_new_buffer == NULL)
		return false;

	memcpy(*r_new_buffer, p_buffer, p_buffer_size);

	return true;
}

void MCParagraph::CloneText(void*& r_text, uint2& r_text_size) const
{
	if (CloneBuffer(m_text, m_text_size, &r_text))
		r_text_size = m_text_size;
	else
		r_text_size = 0;
}

void MCParagraph::CloneStyles(uint4*& r_styles, uint2& r_styles_size) const
{
	if (CloneBuffer(m_styles, m_styles_size * sizeof(uint4), (void **)&r_styles))
		r_styles_size = m_styles_size;
	else
		r_styles_size = 0;
}

//

void MCParagraph::CopyText(uint4 p_start, uint4 p_finish, void*& r_text, uint2& r_text_size) const
{
	assert(p_finish <= m_text_size);
	assert(p_start <= p_finish);

	if (p_finish - p_start == 0)
	{
		r_text = NULL;
		r_text_size = 0;
		return;
	}

	if (CloneBuffer((char *)m_text + p_start, p_finish - p_start, &r_text))
		r_text_size = p_finish - p_start;
	else
		r_text_size = 0;
}
Esempio n. 2
0
/* Replace all &markers; and &#NNNN;s with UTF-8. */
void FontCharAliases::ReplaceMarkers( CString &sText )
{
	InitCharAliases();
	ReplaceText(sText, CharAliasRepl);
	Replace_Unicode_Markers(sText);
}