当前位置: 首页>>代码示例>>C++>>正文


C++ CL_String::find方法代码示例

本文整理汇总了C++中CL_String::find方法的典型用法代码示例。如果您正苦于以下问题:C++ CL_String::find方法的具体用法?C++ CL_String::find怎么用?C++ CL_String::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CL_String的用法示例。


在下文中一共展示了CL_String::find方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: escape_text

CL_String CL_CSSLayoutNode_Impl::escape_text(CL_String text)
{
	while (true)
	{
		CL_String::size_type pos = text.find('\r');
		if (pos == CL_String::npos)
			break;
		text.replace(pos, 1, "\\r");
	}
	while (true)
	{
		CL_String::size_type pos = text.find('\n');
		if (pos == CL_String::npos)
			break;
		text.replace(pos, 1, "\\n");
	}
	while (true)
	{
		CL_String::size_type pos = text.find('\t');
		if (pos == CL_String::npos)
			break;
		text.replace(pos, 1, "\\t");
	}
	return text;
}
开发者ID:animehunter,项目名称:clanlib-2.3,代码行数:25,代码来源:css_layout_node.cpp

示例2: download_url

CL_String HTMLPage::download_url(const CL_String &page_url, const CL_String &refererer_url)
{
	HTMLUrl url(page_url, refererer_url);
	CL_Console::write_line("Downloading URL: %1", url.to_string());
	CL_String8 request;
	request = cl_format("GET %1 HTTP/1.1\r\n", url.path+url.query);
	if (refererer_url.empty())
		request += cl_format("Host: %1\r\nConnection: close\r\nAccept: text/plain, text/html\r\nUser-Agent: CSSTokenize/0.1\r\n\r\n", url.host);
	else
		request += cl_format("Host: %1\r\nConnection: close\r\nReferer: %2\r\nAccept: text/plain, text/html\r\nUser-Agent: CSSTokenize/0.1\r\n\r\n", url.host, refererer_url);
	//MessageBoxW(0, CL_StringHelp::utf8_to_ucs2(cl_format("GET %1 HTTP/1.1\r\n", url.path+url.query)).c_str(), L"Download URL", MB_OK);;

	CL_TCPConnection connection(CL_SocketName(url.host, url.port));
	connection.set_nodelay(true);
	connection.send(request.data(), request.length(), true);

	CL_String response;
	while (connection.get_read_event().wait(15000))
	{
		char buffer[16*1024];
		int received = connection.read(buffer, 16*1024, false);
		if (received == 0)
			break;
		response.append(buffer, received);
	}
	connection.disconnect_graceful();

	CL_String response_header = response.substr(0, response.find("\r\n\r\n"));
	CL_String content = response.substr(response_header.length() + 4);

	if (response_header.find("Transfer-Encoding: chunked") != CL_String::npos)
	{
		CL_String::size_type start = 0;
		while (true)
		{
			CL_String::size_type end = content.find("\r\n", start);
			if (end == CL_String::npos)
				end = content.length();

			CL_String str_length = content.substr(start, end-start);
			int length = CL_StringHelp::text_to_int(str_length, 16);
			content = content.substr(0, start) + content.substr(end+2);
			start += length;


			end = content.find("\r\n", start);
			if (end == CL_String::npos)
				end = content.length();
			content = content.substr(0, start) + content.substr(end+2);

			if (length == 0)
				break;
		}
	}

	return content;
}
开发者ID:animehunter,项目名称:clanlib-2.3,代码行数:57,代码来源:html_page.cpp

示例3: load_image

CL_Image HTMLPage::load_image(CL_GraphicContext &gc, const CL_String &image_url)
{
	HTMLUrl url(image_url, pageurl);
	CL_Console::write_line("Downloading image: %1", url.to_string());
	CL_String8 request;
	request = cl_format("GET %1 HTTP/1.1\r\n", url.path+url.query);
	request += cl_format("Host: %1\r\nConnection: close\r\nReferer: %2\r\nAccept: image/png, image/jpeg\r\nUser-Agent: CSSTokenize/0.1\r\n\r\n", url.host, pageurl.to_string());

	CL_TCPConnection connection(CL_SocketName(url.host, url.port));
	connection.set_nodelay(true);
	connection.send(request.data(), request.length(), true);

	CL_String response;
	while (connection.get_read_event().wait(15000))
	{
		char buffer[16*1024];
		int received = connection.read(buffer, 16*1024, false);
		if (received == 0)
			break;
		response.append(buffer, received);
	}
	connection.disconnect_graceful();

	CL_String response_header = response.substr(0, response.find("\r\n\r\n"));
	CL_String content = response.substr(response_header.length() + 4);

	if (response_header.find("Transfer-Encoding: chunked") != CL_String::npos)
	{
		CL_String::size_type start = 0;
		while (true)
		{
			CL_String::size_type end = content.find("\r\n", start);
			if (end == CL_String::npos)
				end = content.length();

			CL_String str_length = content.substr(start, end-start);
			int length = CL_StringHelp::text_to_int(str_length, 16);
			content = content.substr(0, start) + content.substr(end+2);
			start += length;


			end = content.find("\r\n", start);
			if (end == CL_String::npos)
				end = content.length();
			content = content.substr(0, start) + content.substr(end+2);

			if (length == 0)
				break;
		}
	}

	CL_DataBuffer buffer(content.data(), content.length());
	CL_IODevice_Memory device(buffer);
	if (response_header.find("image/png") != CL_String::npos)
	{
		CL_PixelBuffer pb = CL_PNGProvider::load(device);
		return CL_Image(gc, pb, pb.get_size());
	}
	else if (response_header.find("image/jpeg") != CL_String::npos)
	{
		CL_PixelBuffer pb = CL_JPEGProvider::load(device);
		return CL_Image(gc, pb, pb.get_size());
	}
	else if (response_header.find("image/gif") != CL_String::npos)
	{
		CL_PixelBuffer pb = GIFProvider::load(device);
		return CL_Image(gc, pb, pb.get_size());
	}
	else
	{
		CL_Console::write_line("Unknown image type: %1", CL_String8(buffer.get_data(), buffer.get_size()));
		return CL_Image();
	}
}
开发者ID:animehunter,项目名称:clanlib-2.3,代码行数:74,代码来源:html_page.cpp

示例4: make_relative


//.........这里部分代码省略.........
				TCHAR working_dir[MAX_PATH];
				memset(working_dir, 0, sizeof(TCHAR)*MAX_PATH);
				if (GetCurrentDirectory(MAX_PATH, working_dir) == FALSE)
					throw CL_Exception(cl_format("Unable to get current working directory for %1!", absolute_location));

				absolute = add_trailing_slash(working_dir, path_type) + absolute;
			}
			else
			{
				throw CL_Exception(cl_format("Error in make_relative with absolute path: %1", absolute_path));
			}
#else
			char working_dir[1024];
			memset(working_dir, 0, 1024);
			if (getcwd(working_dir, 1024) == 0)
				throw CL_Exception("Unable to get current working directory!");
			absolute = add_trailing_slash(working_dir, path_type) + absolute;
#endif
		}

		base_location = get_location(base, path_type_file);
		absolute_location = get_location(absolute, path_type_file);
		if (CL_StringHelp::compare(absolute_location, base_location, true) != 0)
			return absolute_path;
	}

	if (is_relative(base, path_type))
		throw CL_Exception(cl_format("Relative path %1 used as base path for make_relative", base_path));
	if (is_relative(absolute, path_type))
		throw CL_Exception(cl_format("Relative path %1 used as absolute path for make_relative", absolute_path));

	CL_String relative;
	CL_String relative_end;

	bool differs = false;
	CL_String::size_type start_pos = 0, end_pos = 0;
	while (true)
	{
		if (path_type == path_type_file)
		{
			end_pos = base.find_first_of("\\/", start_pos);
		}
		else
		{
			end_pos = base.find('/', start_pos);
		}
		if (end_pos == CL_String::npos)
			break;

		if (!differs)
		{
			CL_String base_element = base.substr(start_pos, end_pos - start_pos + 1);
			CL_String absolute_element = absolute.substr(start_pos, end_pos - start_pos + 1);

			bool same_element = false;
			if (path_type == path_type_file)
			{
#ifdef WIN32
				same_element = (CL_StringHelp::compare(base_element, absolute_element, true) == 0);
#else
				same_element = (base_element == absolute_element);
#endif
			}
			else
			{
				same_element = (base_element == absolute_element);
			}

			if (!same_element)
			{
				relative_end = absolute.substr(start_pos);
				differs = true;
			}
			else
			{
				relative_end = absolute.substr(end_pos+1);
			}
		}

		if (differs)
		{
			if (path_type_file)
			{
#ifdef WIN32
				relative += "..\\";
#else
				relative += "../";
#endif
			}
			else
			{
				relative += "../";
			}
		}

		start_pos = end_pos + 1;
	}

	return relative + relative_end;
}
开发者ID:PaulFSherwood,项目名称:cplusplus,代码行数:101,代码来源:path_help.cpp


注:本文中的CL_String::find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。