Esempio n. 1
0
TEST(TCodeConverter, performance2)
{
    string from;
    string to;
    {
        ifstream ifs("../test/testdata/dict.utf8");
        ASSERT_TRUE(!!ifs);
        from << ifs;
    }
    CodeConverter cc = CodeConverter("utf-8","gb2312"); 
    for(size_t i = 0; i < 50000; i++)
    {
        ASSERT_TRUE(cc.convert(from, to));
    }
}
Esempio n. 2
0
TEST(TCodeConverter, Gb2312ToUtf8)
{
    CodeConverter cc = CodeConverter("gb2312", "utf-8"); 
    string to;

    string from;
    {
        ifstream ifs("../test/testdata/dict.gbk");
        ASSERT_TRUE(!!ifs);
        from << ifs;
    }
    
    ASSERT_TRUE(cc.convert(from, to));

    string ans;
    {
        ifstream ifs("../test/testdata/dict.utf8");
        ASSERT_TRUE(!!ifs);
        ans << ifs;
    }

    ASSERT_EQ(ans, to);
}
Esempio n. 3
0
int CViewMng::init(Connection *conn)
{
	CoCycle *cycle = g_cycle;

	if(conn == NULL)	return -1;

	mDBConn = conn;

	StoreQueryResult::const_iterator it;

	Row row ;

	Query query = mDBConn->query();
	
	query << "select id, ltrim(rtrim(name)), ltrim(rtrim(remark)), "
		<< "interruptable, type from t_view_set";
	StoreQueryResult res = query.store();

	if(res.empty()) return -2;

	static char buf[2048];
	CodeConverter cc = CodeConverter("utf-8","gb2312");

	for (it = res.begin(); it != res.end(); ++it) {
		row = *it;

		ViewSet *viewSet = cycle->mPool->newObj<ViewSet>();
		assert(viewSet != NULL);

		viewSet->id = row[0];

		memset(buf, 0, sizeof(buf));
		cc.convert((char *)row[1].c_str(), row[1].length(), buf, sizeof(buf));

		viewSet->name = buf;

		memset(buf, 0, sizeof(buf));
		cc.convert((char *)row[2].c_str(), row[2].length(), buf, sizeof(buf));

		viewSet->remark = buf;

		int interruptable = row[3];
		if(interruptable == 0)		viewSet->interruptable = true;
		else viewSet->interruptable = false;

		viewSet->type = row[4];
		insertViewSet(viewSet);
	}

	query << "select a.id, ltrim(rtrim(a.name)), ltrim(rtrim(a.content)), "
		<< " ltrim(rtrim(b.name)) from t_view as a " 
		<< "left join t_view_set as b on a.view_set_id = b.id";
	res = query.store();


	if(res.empty())	return -3;

	for (it = res.begin(); it != res.end(); ++it) {
		row = *it;

		View *view = cycle->mPool->newObj<View>();
		assert(view != NULL);

		view->id = row[0];

		memset(buf, 0, sizeof(buf));
		cc.convert((char *)row[1].c_str(), row[1].length(), buf, sizeof(buf));

		view->name = buf;

		memset(buf, 0, sizeof(buf));
		cc.convert((char *)row[2].c_str(), row[2].length(), buf, sizeof(buf));

		view->content = buf;

		insertView(row[3].c_str(), view);
	}
	
	query << "select a.id, ltrim(rtrim(a.name)), ltrim(rtrim(a.title)), "
		<< " ltrim(rtrim(a.action)), a.type, ltrim(rtrim(b.name)) "
		<<"from t_click_action as a left join t_view_set as b "
		<< "on a.view_set_id = b.id";
	res = query.store();
	
	if(res.empty())	return -4;

	for (it = res.begin(); it != res.end(); ++it) {
		row = *it;

		ClickAction *clickAction = cycle->mPool->newObj<ClickAction>();
		assert(clickAction != NULL);

		clickAction->id = row[0];

		memset(buf, 0, sizeof(buf));
		cc.convert((char *)row[1].c_str(), row[1].length(), buf, sizeof(buf));

		clickAction->name = buf;

		memset(buf, 0, sizeof(buf));
		cc.convert((char *)row[2].c_str(), row[2].length(), buf, sizeof(buf));

		clickAction->title = buf;

		memset(buf, 0, sizeof(buf));
		cc.convert((char *)row[3].c_str(), row[3].length(), buf, sizeof(buf));

		clickAction->action = buf;

		clickAction->type = row[4];

		insertClickAction(row[5].c_str(), clickAction);
	}

	return 0;
}