Exemple #1
0
void StringTest::testCat()
{
    std::string s1("one");
    std::string s2("two");
    std::string s3("three");
    std::string s4("four");
    std::string s5("five");
    std::string s6("six");

    assert (cat(s1, s2) == "onetwo");
    assert (cat(s1, s2, s3) == "onetwothree");
    assert (cat(s1, s2, s3, s4) == "onetwothreefour");
    assert (cat(s1, s2, s3, s4, s5) == "onetwothreefourfive");
    assert (cat(s1, s2, s3, s4, s5, s6) == "onetwothreefourfivesix");

    std::vector<std::string> vec;
    assert (cat(std::string(), vec.begin(), vec.end()) == "");
    assert (cat(std::string(","), vec.begin(), vec.end()) == "");
    vec.push_back(s1);
    assert (cat(std::string(","), vec.begin(), vec.end()) == "one");
    vec.push_back(s2);
    assert (cat(std::string(","), vec.begin(), vec.end()) == "one,two");
    vec.push_back(s3);
    assert (cat(std::string(","), vec.begin(), vec.end()) == "one,two,three");
}
Exemple #2
0
	void handleRequest (HTTPServerRequest &request, HTTPServerResponse &response)
	{
		Application& app = Application::instance();
		app.logger().information("Запрос от " + request.clientAddress().toString());
		
		
//		std::cout << request.getURI() << std::endl;
		
//		std::string filename(request.getURI().substr(0, request.getURI().find("?")));
//		app.logger().information("Файл: " + filename);
		
		/*
		if (opendir(std::string("www" + filename).c_str()) != NULL)
		{
			response.setStatus(Poco::Net::HTTPResponse::HTTP_NOT_FOUND);
			return;
		}
		
		if (filename != "balda.json")
		{
			ifstream fin(filename.c_str());
			
			if (fin.is_open())
			{
			
			}
			
			return;
		}
	*/	
		response.setChunkedTransferEncoding(true);
		std::ostream &ostr = response.send();

	//	try
	//	{
//			response.sendFile("/media/hdisk0/programming/project/anbal/2001/www" + filename, "text/plain");
//		}
	//	catch (...)
	//	{
//			ostr << "BAD" << std::endl;
	//	}
		
//		return;
	
		response.setContentType("text/javascript; charset=UTF-8");
		HTMLForm form(request, request.stream());
				
		if (!form.empty())
		{
			std::map < std::string , Glib::ustring > params;

			for (NameValueCollection::ConstIterator it = form.begin(); it != form.end(); ++it)
				params[it->first] = Glib::ustring(it->second);
			
			if (params["map"].length() != 25)
				return;
			
			std::vector < std::vector < SMyGUniChar > > char_map(5, std::vector < SMyGUniChar >(5));
			Glib::ustring u_map = params["map"];
			
			for (int i = 0, len = u_map.length(); i < len; ++i)
				char_map[i / 5][i % 5] = SMyGUniChar(u_map[i], i / 5, i % 5, u_map[i] == Glib::ustring(".")[0]);
			
			CBalda balda(*dictionary);
			std::vector < Glib::ustring > words = balda.calc(char_map);
			
			ostr << params["callback"] << "({\"word\": [\"" << cat(std::string("\", \""), words.begin(), words.end()) << "\"]})";
		}
	}