Exemplo n.º 1
0
void CL_SpanLayout_Impl::next_line(CurrentLine &current_line)
{
	current_line.cur_line.width = current_line.x_position;
	for (std::vector<LineSegment>::reverse_iterator it = current_line.cur_line.segments.rbegin(); it != current_line.cur_line.segments.rend(); ++it)
	{
		LineSegment &segment = *it;
		if (segment.type == object_text)
		{
			CL_StringRef s = text.substr(segment.start, segment.end-segment.start);
			if (s.find_first_not_of(" \t\r\n") != CL_StringRef::npos)
			{
				current_line.cur_line.width = segment.x_position + segment.width;
				break;
			}
		}
		else
		{
			current_line.cur_line.width = segment.x_position + segment.width;
			break;
		}
	}

	int height = current_line.cur_line.height;
	lines.push_back(current_line.cur_line);
	current_line.cur_line = Line();
	current_line.x_position = 0;
	current_line.y_position += height;
}
Exemplo n.º 2
0
CL_DomString CL_DomElement::get_attribute_ns(
	const CL_DomString &namespace_uri,
	const CL_DomString &local_name,
	const CL_DomString &default_value) const
{
	if (impl)
	{
		CL_DomDocument_Generic *doc_impl = (CL_DomDocument_Generic *) impl->owner_document.lock().get();
		const CL_DomTreeNode *tree_node = impl->get_tree_node();
		unsigned int cur_index = tree_node->first_attribute;
		const CL_DomTreeNode *cur_attribute = tree_node->get_first_attribute(doc_impl);
		while (cur_attribute)
		{
			CL_StringRef lname = cur_attribute->get_node_name();
			CL_StringRef::size_type lpos = lname.find_first_of(':');
			if (lpos != CL_StringRef::npos)
				lname = lname.substr(lpos + 1);

			if (cur_attribute->get_namespace_uri() == namespace_uri && lname == local_name)
				return cur_attribute->get_node_value();

			cur_index = cur_attribute->next_sibling;
			cur_attribute = cur_attribute->get_next_sibling(doc_impl);
		}
		return default_value;
	}
	return default_value;
}
Exemplo n.º 3
0
CL_StringRef CL_CSSSelector::get_type(const CL_StringRef &path_element)
{
	CL_StringRef::size_type pos = path_element.find_first_of(".#:");
	if (pos == CL_StringRef::npos)
		return path_element;
	else
		return path_element.substr(0, pos);
}
Exemplo n.º 4
0
CL_StringRef CL_CSSSelector::get_state(const CL_StringRef &path_element)
{
	CL_StringRef::size_type pos1 = path_element.find_first_of(':');
	if (pos1 == CL_StringRef::npos)
		return CL_StringRef();
	CL_StringRef::size_type pos2 = path_element.find_first_of(".#", pos1);
	if (pos2 == CL_StringRef::npos)
		return path_element.substr(pos1);
	else
		return path_element.substr(pos1, pos2 - pos1);
}
Exemplo n.º 5
0
int CL_PgsqlReaderProvider::get_name_index(const CL_StringRef &name) const
{
	int index = PQfnumber(result, name.c_str());
	if (index < 0)
		throw CL_Exception(cl_format("No such column name %1", name));
	return index;
}
Exemplo n.º 6
0
void CL_RegistryKey::set_value_int(const CL_StringRef &name, int value)
{
	DWORD v = value;
	LONG result = RegSetValueEx(impl->key, name.empty() ? 0 : CL_StringHelp::utf8_to_ucs2(name).c_str(), 0, REG_DWORD, (const BYTE *) &v, sizeof(DWORD));
	if (result != ERROR_SUCCESS)
		throw CL_Exception(cl_format("Unable to set registry key value %1", name));
}
Exemplo n.º 7
0
void CL_GlyphCache::insert_glyph(CL_FontEngine *font_engine, CL_GraphicContext &gc, const CL_StringRef &text)
{
	for (CL_String::size_type p = 0; p < text.length(); ++p)
	{
		insert_glyph(font_engine, gc, text[p]);
	}
}
Exemplo n.º 8
0
void CL_ZipWriter::begin_file(const CL_StringRef &filename, bool compress)
{
	if (impl->file_begun)
		throw CL_Exception("CL_ZipWriter already writing a file");
	impl->file_begun = true;

	impl->uncompressed_length = 0;
	impl->compressed_length = 0;
	impl->compress = compress;
	impl->crc32 = CL_ZIP_CRC_START_VALUE;

	impl->local_header_offset = impl->output.get_position();
	impl->local_header = CL_ZipLocalFileHeader();
	impl->local_header.version_needed_to_extract = 20;
	if (impl->storeFilenamesAsUTF8)
		impl->local_header.general_purpose_bit_flag = CL_ZIP_USE_UTF8;
	else
		impl->local_header.general_purpose_bit_flag = 0;
	impl->local_header.compression_method = compress ? zip_compress_deflate : zip_compress_store;
	CL_ZipArchive_Impl::calc_time_and_date(
		impl->local_header.last_mod_file_date,
		impl->local_header.last_mod_file_time);
	impl->local_header.crc32 = 0;
	impl->local_header.uncompressed_size = 0;
	impl->local_header.compressed_size = 0;
	impl->local_header.file_name_length = filename.length();
	impl->local_header.filename = filename;

	if (!impl->storeFilenamesAsUTF8) // Add UTF-8 as extra field if we aren't storing normal UTF-8 filenames
	{
		// -Info-ZIP Unicode Path Extra Field (0x7075)
		CL_String8 filename_cp437 = CL_StringHelp::text_to_cp437(filename);
		CL_String8 filename_utf8 = CL_StringHelp::text_to_utf8(filename);
		CL_DataBuffer unicode_path(9 + filename_utf8.length());
		cl_ubyte16 *extra_id = (cl_ubyte16 *) (unicode_path.get_data());
		cl_ubyte16 *extra_len = (cl_ubyte16 *) (unicode_path.get_data() + 2);
		cl_ubyte8 *extra_version = (cl_ubyte8 *) (unicode_path.get_data() + 4);
		cl_ubyte32 *extra_crc32 = (cl_ubyte32 *) (unicode_path.get_data() + 5);
		*extra_id = 0x7075;
		*extra_len = 5 + filename_utf8.length();
		*extra_version = 1;
		*extra_crc32 = CL_ZipArchive_Impl::calc_crc32(filename_cp437.data(), filename_cp437.size());
		memcpy(unicode_path.get_data() + 9, filename_utf8.data(), filename_utf8.length());
		impl->local_header.extra_field_length = unicode_path.get_size();
		impl->local_header.extra_field = unicode_path;
	}

	impl->local_header.save(impl->output);

	if (compress)
	{
		memset(&impl->zs, 0, sizeof(z_stream));
		int result = deflateInit2(&impl->zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY); // Undocumented: if wbits is negative, zlib skips header check
		if (result != Z_OK)
			throw CL_Exception("Zlib deflateInit failed for zip index!");
	}
}
Exemplo n.º 9
0
inline CL_StringRef CL_XMLTokenizer_Generic::trim_whitespace(const CL_StringRef &text)
{
	CL_StringRef::size_type pos_start = text.find_first_not_of(" \t\r\n");
	if (pos_start == CL_StringRef::npos)
		return CL_StringRef();
	CL_StringRef::size_type pos_end = text.find_last_not_of(" \t\r\n", pos_start);
	if (pos_end == CL_StringRef::npos)
	{
		if (pos_start == 0)
			return text;
		else
			return string_allocator.alloc(text.substr(pos_start));
	}
	else
	{
		return string_allocator.alloc(text.substr(pos_start, pos_end - pos_start + 1));
	}
}
Exemplo n.º 10
0
CL_StringRef CL_XMLWriter_Generic::insert_escapes_fast(const CL_StringRef &str)
{
	static CL_StringRef const amp("&amp;");
	static CL_StringRef const quot("&quot;");
	static CL_StringRef const apos("&apos;");
	static CL_StringRef const lt("&lt;");
	static CL_StringRef const gt("&gt;");

	escaped_string = str;
	CL_StringRef::size_type pos = 0;
	while (pos < escaped_string.size())
	{
		switch(escaped_string[pos])
		{
		case '&':
			escaped_string.replace(pos, 1, amp);
			pos += amp.size();
			break;
		case '\'':
			escaped_string.replace(pos, 1, apos);
			pos += apos.size();
			break;
		case '\"':
			escaped_string.replace(pos, 1, quot);
			pos += quot.size();
			break;
		case '<':
			escaped_string.replace(pos, 1, lt);
			pos += lt.size();
			break;
		case '>':
			escaped_string.replace(pos, 1, gt);
			pos += gt.size();
			break;
		default:
			++pos;
			break;
		}
	}
	return escaped_string;
}
Exemplo n.º 11
0
void CL_StringFormat::set_arg(int index, const CL_StringRef &text)
{
	if (index >= (int) args.size())
		return;
		
	ArgPosition pos = args[index];
	if (pos.length == 0)
		return;
		
	int delta_size = ((int) text.length()) - pos.length;
	string = string.substr(0, pos.start) + text + string.substr(pos.start + pos.length);
	args[index].length = text.length();
	
	std::vector<ArgPosition>::size_type i, size;
	size = args.size();
	for (i = 0; i < size; i++)
	{
		if (args[i].start > pos.start)
			args[i].start += delta_size;
	}
}
Exemplo n.º 12
0
inline void CL_XMLTokenizer_Generic::unescape(CL_StringRef &text, const CL_StringRef &search, CL_String::char_type replace)
{
	CL_StringRef::size_type read_pos = 0;
	CL_StringRef::size_type length = text.length();
	CL_StringRef::size_type search_length = search.length();
	CL_StringRef::char_type *data = text.data();
	while (true)
	{
		CL_StringRef::size_type next_match = text.find(search, read_pos);
		if (next_match == CL_StringRef::npos)
			break;

		CL_StringRef::size_type copy_size = length - (next_match + search_length);
		memcpy(data + next_match + 1, data + next_match + search_length, copy_size * sizeof(CL_StringRef::char_type));
		data[next_match] = replace;
		length -= search_length - 1;
		read_pos = next_match + 1;
		if (read_pos > length)
			break;
	}
	text.set_length(length);
}
Exemplo n.º 13
0
void CL_Console::write(const CL_StringRef &text)
{
#ifdef WIN32
    /*
    	Do not replace WriteConsole with the commented WriteFile code unless you
    	really know what you are doing and understand when ANSI code pages are used and
    	when OEM code pages are used.  -- mbn 29. jan 2008

    CL_String8 t = CL_StringHelp::text_to_local8(text);
    DWORD written = 0;
    WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), t.data(), t.length(), &written, 0);
    */

    DWORD written = 0;

    CL_String16 str = CL_StringHelp::utf8_to_ucs2(text);
    WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), str.c_str(), str.length(), &written, 0);

#else
    ::write(1, text.data(), text.length());
#endif
}
Exemplo n.º 14
0
std::vector<CL_String> CL_RegistryKey::get_value_multi_string(const CL_StringRef &name, const std::vector<CL_String> &default_value) const
{
	DWORD type = 0, size_data = 0;
	LONG result = RegQueryValueEx(impl->key, CL_StringHelp::utf8_to_ucs2(name).c_str(), 0, &type, 0, &size_data);
	if (result != ERROR_SUCCESS || type != REG_MULTI_SZ)
		return default_value;

	CL_DataBuffer buffer(size_data);
	size_data = buffer.get_size();
	result = RegQueryValueEx(impl->key, CL_StringHelp::utf8_to_ucs2(name).c_str(), 0, &type, (LPBYTE) buffer.get_data(), &size_data);
	if (result != ERROR_SUCCESS || type != REG_MULTI_SZ)
		return default_value;

	std::vector<CL_String> results;
	TCHAR *pos = (TCHAR *) buffer.get_data();
	while (*pos != 0)
	{
		CL_StringRef s = pos;
		results.push_back(s);
		pos += s.length()+1;
	}

	return results;
}
Exemplo n.º 15
0
unsigned int CL_CSSDocument_Impl::style_load_until(const CL_StringRef::char_type *chars, const CL_StringRef &style_text, unsigned int pos)
{
	bool quotes1 = false;
	bool quotes2 = false;
	int level = 0;
	while (pos < style_text.length())
	{
		if (level == 0 && quotes1 == false && quotes2 == false)
		{
			for (int i = 0; chars[i] != 0; i++)
			{
				if (style_text[pos] == chars[i])
					return pos;
			}
		}

		switch (style_text[pos++])
		{
		case '"':
			quotes1 = !quotes1;
			break;
		case '\'':
			quotes2 = !quotes2;
			break;
		case '(':
		case '{':
		case '[':
			if (quotes1 || quotes2)
				break;
			level++;
			break;
		case ')':
		case '}':
		case ']':
			if (quotes1 || quotes2)
				break;
			level--;
			break;
		case '\\':
			pos++;
			break;
		}
	}
	return pos;
}
Exemplo n.º 16
0
void CL_GlyphCache::draw_text(CL_FontEngine *font_engine, CL_GraphicContext &gc, float xpos, float ypos, const CL_StringRef &text, const CL_Colorf &color) 
{
	CL_String::size_type string_length = text.length();
	if (string_length==0)
	{
		return;
	}

	CL_RenderBatcherSprite *batcher = gc.impl->current_internal_batcher;

	// Scan the string
	CL_UTF8_Reader reader(text);
	while(!reader.is_end())
	{
		unsigned int glyph = reader.get_char();
		reader.next();

		CL_Font_TextureGlyph *gptr = get_glyph(font_engine, gc, glyph);
		if (gptr == NULL) continue;

		if (!gptr->empty_buffer)
		{
			float xp = xpos + gptr->offset.x;
			float yp = ypos + gptr->offset.y;

			CL_Rectf dest_size(xp, yp, CL_Sizef(gptr->geometry.get_size()));
			if (enable_subpixel)
			{
				batcher->draw_glyph_subpixel(gc, gptr->geometry, dest_size, color, gptr->subtexture.get_texture());
			}else
			{
				batcher->draw_image(gc, gptr->geometry, dest_size, color, gptr->subtexture.get_texture());
			}
		}
		xpos += gptr->increment.x;
		ypos += gptr->increment.y;
	}
}
Exemplo n.º 17
0
void CL_RegistryKey::set_value_string(const CL_StringRef &name, const CL_StringRef &value)
{
	LONG result = RegSetValueEx(impl->key, name.empty() ? 0 : CL_StringHelp::utf8_to_ucs2(name).c_str(), 0, REG_SZ, (const BYTE *) value.c_str(), (value.length()+1) * sizeof(TCHAR));
	if (result != ERROR_SUCCESS)
		throw CL_Exception(cl_format("Unable to set registry key value %1", name));
}
Exemplo n.º 18
0
void CL_RegistryKey::set_value_binary(const CL_StringRef &name, const CL_DataBuffer &value)
{
	LONG result = RegSetValueEx(impl->key, name.empty() ? 0 : CL_StringHelp::utf8_to_ucs2(name).c_str(), 0, REG_BINARY, (const BYTE *) value.get_data(), value.get_size());
	if (result != ERROR_SUCCESS)
		throw CL_Exception(cl_format("Unable to set registry key value %1", name));
}
Exemplo n.º 19
0
void CL_ZipFileEntry::set_archive_filename(const CL_StringRef &filename)
{
	impl->record.file_name_length = filename.length();
	impl->record.filename = filename;
}