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


C++ StringBuilder::Clear方法代码示例

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


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

示例1: test

 bool test()
 {
   StringBuilder sb;
   sb.Clear();
   String s = *sb.ToString();
   return (s.length() == 0);
 }
开发者ID:praveenster,项目名称:leplib,代码行数:7,代码来源:TestStringBuilder.cpp

示例2: Clear

 RF_Type::Bool Clear()
 {
     StringBuilder builder;
     builder.Append("test");
     RF_Type::Size capacity = builder.Capacity();
     builder.Clear();
     return builder.Capacity() == capacity && builder.Size() == 0 &&
         builder.Length() == 0;
 }
开发者ID:wangscript,项目名称:RadonFramework,代码行数:9,代码来源:StringBuilder.cpp

示例3: LogDebugInfo

void ServerVolume::LogDebugInfo()
{
	info("   ---------- ServerVolume");

	StringBuilder msg;

	for (int i = 0; i < 60; i++)
	{
		char szNum[30];
		snprintf(szNum, 30, "[%i]=%lli ", i, m_BytesPerSeconds[i]);
		msg.Append(szNum);
	}
	info("Secs: %s", msg.GetBuffer());

	msg.Clear();
	for (int i = 0; i < 60; i++)
	{
		char szNum[30];
		snprintf(szNum, 30, "[%i]=%lli ", i, m_BytesPerMinutes[i]);
		msg.Append(szNum);
	}
	info("Mins: %s", msg.GetBuffer());

	msg.Clear();
	for (int i = 0; i < 24; i++)
	{
		char szNum[30];
		snprintf(szNum, 30, "[%i]=%lli ", i, m_BytesPerHours[i]);
		msg.Append(szNum);
	}
	info("Hours: %s", msg.GetBuffer());

	msg.Clear();
	for (int i = 0; i < (int)m_BytesPerDays.size(); i++)
	{
		char szNum[30];
		snprintf(szNum, 30, "[%i]=%lli ", m_iFirstDay + i, m_BytesPerDays[i]);
		msg.Append(szNum);
	}
	info("Days: %s", msg.GetBuffer());
}
开发者ID:ta264,项目名称:nzbget_svn,代码行数:41,代码来源:StatMeter.cpp

示例4: parse_dns_packet

void DNSServer::parse_dns_packet(const Buffer& b, dnsreq& req)
{
	StringBuilder sb;
	UShort qs, as;
	const dnshdr* hdr;
	int i, index = sizeof(dnshdr);
	map<UShort, int> queries;
	if (b.Length < (int) sizeof(dnshdr))
		goto err;
	hdr = (const dnshdr*) b.Data;
	req.transaction_id = hdr->transaction_id;
	req.flags = ntohs(hdr->flags);
	req.queries = vector<query>();
	req.answers = vector<answer>();
	qs = ntohs(hdr->queries);
	as = ntohs(hdr->answers);
	for (i = 0; i < qs; i++)
	{
		sb.Clear();
		queries.insert(std::pair<UShort, int>(index, i));
		int tmp = read_dns_name(b, sb, index);
		index += tmp;
		const dnshdr_q* hdr1 = (const dnshdr_q*) (b.Data + index);
		if (index + (int) sizeof(dnshdr_q) > b.Length)
			goto err;
		query q
		{ sb.ToSTDString(), ntohs(hdr1->type), ntohs(hdr1->cls) };
		req.queries.push_back(q);
		index += sizeof(dnshdr_q);
	}
	for (i = 0; i < as; i++)
	{
		const dnshdr_a* hdr1 = (const dnshdr_a*) (b.Data + index);
		if (index + (int) sizeof(dnshdr_a) > b.Length)
			goto err;
		auto it = queries.find(ntohs(hdr1->offset) & ~dns_offset_mask);
		if (it == queries.end())
			goto err;
		index += sizeof(dnshdr_a);
		UShort tmp = ntohs(hdr1->datalen);
		if (index + (int) tmp > b.Length)
			goto err;
		Buffer buf(tmp);
		memcpy(buf.Data, b.Data + index, tmp);
		answer a
		{ (*it).second, ntohs(hdr1->type), ntohs(hdr1->cls), ntohl(hdr1->ttl), buf };
		req.answers.push_back(a);
	}
	return;
	err: throw Exception("invalid or corrupt DNS packet");
}
开发者ID:Dinesh-Ramakrishnan,项目名称:workspace,代码行数:51,代码来源:DNSServer.C

示例5: deleteFriend

void TeamFriend::deleteFriend(TCPConnection::Pointer conn, hf_uint32  roleid)
{
    SessionMgr::SessionPointer smap = SessionMgr::Instance()->GetSession();
    umap_friendList friendList = (*smap)[conn].m_friendList;

    umap_roleSock roleSock = SessionMgr::Instance()->GetRoleSock();

   _umap_friendList::iterator it = friendList->find(roleid);
    if(it == friendList->end()) //要删除的好友存在
    {
        return;
    }
    _umap_roleSock::iterator iter = roleSock->find(roleid);
    if(iter != roleSock->end()) //要删除的好友在线,从其好友列表里删除
    {
        umap_friendList delete_friendList = (*smap)[iter->second].m_friendList;
        _umap_friendList::iterator delete_it = delete_friendList->find((*smap)[conn].m_roleid);
        if(delete_it != delete_friendList->end())
        {
            delete_friendList->erase(delete_it); //从好友列表中删除自己
        }

        STR_PackDeleteFriend t_delFriend;
        t_delFriend.RoleID = (*smap)[conn].m_roleid;
        iter->second->Write_all(&t_delFriend, sizeof(STR_PackDeleteFriend));//给好友发送删除包
    }
    //从数据库删除
    StringBuilder sbd;
    sbd << "delete from t_friendlist where roleid = " << roleid << " and friendroleid = " << (*smap)[conn].m_roleid << ";";
    Logger::GetLogger()->Debug(sbd.str());
    Server *srv = Server::GetInstance();
    hf_int32 t_row = srv->getDiskDB()->Set(sbd.str());
    if(t_row == 1)
    {
        Logger::GetLogger()->Debug("delete success");
    }

    //从好友列表里删除
    friendList->erase(it);
    //从数据库中删除
    sbd.Clear();
    sbd << "delete from t_friendlist where roleid = " << (*smap)[conn].m_roleid << " and friendroleid = " << roleid << ";";
    Logger::GetLogger()->Debug(sbd.str());
    t_row = srv->getDiskDB()->Set(sbd.str());
    if(t_row == 1)
    {
        Logger::GetLogger()->Debug("delete  friend success");
    }
}
开发者ID:ash-github,项目名称:FatCat-Server,代码行数:49,代码来源:teamfriend.cpp

示例6: SendAskAddFriend

//玩家上线,发送离线的添加好友请求
 void TeamFriend::SendAskAddFriend(TCPConnection::Pointer conn)
 {
     SessionMgr::SessionPointer smap = SessionMgr::Instance()->GetSession();
     hf_uint32 roleid = (*smap)[conn].m_roleid;
     StringBuilder sbd;
     sbd << "select requestroleid,requestnick from t_addFriend where addroleid = " << roleid << ";";
     Logger::GetLogger()->Debug(sbd.str());

     Server* srv = Server::GetInstance();
     vector<STR_AddFriend> addFriend;
     hf_int32 t_row = srv->getDiskDB()->GetAskAddFriend(addFriend, sbd.str());
     if(t_row > 0)
     {
         hf_char* buff = (hf_char*)srv->malloc();
         STR_PackHead t_packHead;
         t_packHead.Flag = FLAG_AddFriend;
         t_packHead.Len = t_row*sizeof(STR_AddFriend);
         hf_int32 i = 0;
         for(vector<STR_AddFriend>::iterator it = addFriend.begin(); it != addFriend.end(); it++)
         {
             memcpy(buff + sizeof(STR_PackHead) + i*sizeof(STR_AddFriend),&(*it), sizeof(STR_AddFriend));
             i++;
         }
         memcpy(buff, &t_packHead, sizeof(STR_PackHead));
         conn->Write_all(buff,t_packHead.Len + sizeof(STR_PackHead));

         srv->free(buff);

         //删除保存的离线添加请求
         sbd.Clear();
         sbd << "delete from t_addFriend where addroleid = " << roleid << ";";
         Logger::GetLogger()->Debug(sbd.str());
         t_row = srv->getDiskDB()->Set(sbd.str());
         if(t_row == 1)
         {
             Logger::GetLogger()->Debug("delete asd addfriend success");
         }
     }
 }
开发者ID:ash-github,项目名称:FatCat-Server,代码行数:40,代码来源:teamfriend.cpp

示例7: addFriend

void TeamFriend::addFriend(TCPConnection::Pointer conn, STR_PackAddFriend* addFriend)
{
    Server* srv = Server::GetInstance();

    STR_PackAddFriend t_addFriend;
    SessionMgr::SessionPointer smap = SessionMgr::Instance()->GetSession();
    t_addFriend.RoleID = (*smap)[conn].m_roleid;
    memcpy(t_addFriend.Nick, ((*smap)[conn].m_RoleBaseInfo.Nick), 32);

    if(addFriend->RoleID >= 100000000) //按roleID添加好友(优先)
    {
        umap_roleSock roleSock = SessionMgr::Instance()->GetRoleSock();
        _umap_roleSock::iterator it = roleSock->find(addFriend->RoleID);
        if(it != roleSock->end()) //要添加的好友在线
        {
            it->second->Write_all(&t_addFriend, sizeof(STR_PackAddFriend));
        }
        if(it == roleSock->end()) //玩家不在线
        {
            StringBuilder sbd;
            sbd << "insert into t_addFriend values(" << t_addFriend.RoleID << ",'" << t_addFriend.Nick << "'," << addFriend->RoleID << ");";
            Logger::GetLogger()->Debug(sbd.str());
            if(srv->getDiskDB()->Set(sbd.str()) == -1)
            {
                Logger::GetLogger()->Error("insert add role friend error");
            }
        }
    }
    else  //按昵称添加好友
    {
         SessionMgr::umap_nickSock nickSock = SessionMgr::Instance()->GetNickSock();
         SessionMgr::_umap_nickSock::iterator it = nickSock->find(addFriend->Nick);
         if(it != nickSock->end()) //在线
         {
             it->second->Write_all(&t_addFriend, sizeof(STR_PackAddFriend));
         }
         else //添加的好友不在线
         {
             hf_char nickbuff[40] = { 0 };
             memcpy(nickbuff, addFriend->Nick, sizeof(addFriend->Nick));
             //在数据库中查找昵称是否存在
             StringBuilder sbd;
             sbd << "select roleid from t_playerrolelist where nick = '" << nickbuff << "';";
             Logger::GetLogger()->Debug(sbd.str());
             hf_uint32 addroleid = 0;
             hf_int32 t_row = srv->getDiskDB()->GetNickRoleid(&addroleid, sbd.str());
             if(t_row == 1) //昵称存在,保存为离线请求
             {
                 hf_uint32 Requestroleid = (*smap)[conn].m_roleid;
                 hf_char   RequestNick[40] = { 0 };
                 memcpy(RequestNick, (*smap)[conn].m_RoleBaseInfo.Nick, 32);
                 sbd.Clear();
                 sbd << "insert into t_addFriend values(" << Requestroleid << ",'" << RequestNick << "'," << addroleid << ");";
                 Logger::GetLogger()->Debug(sbd.str());
                 t_row = srv->getDiskDB()->Set(sbd.str());
                 if( t_row == -1)
                 {
                     Logger::GetLogger()->Error("insert add friend error");
                 }
             }
             else if(t_row == 0) //昵称不存在
             {
                 STR_PackAddFriendReturn Raddfriend;

                 memcpy(Raddfriend.Nick, addFriend->Nick, 32);
                 Raddfriend.value = 3;
                 conn->Write_all(&Raddfriend, sizeof(STR_PackAddFriendReturn));
             }
         }
    }
    srv->free(addFriend);
}
开发者ID:ash-github,项目名称:FatCat-Server,代码行数:72,代码来源:teamfriend.cpp

示例8: ReciveAddFriend

//接收到客户端添加好友的回复
void TeamFriend::ReciveAddFriend(TCPConnection::Pointer conn, STR_PackAddFriendReturn* addFriend)
{
    Server* srv = Server::GetInstance();
    SessionMgr::SessionPointer smap = SessionMgr::Instance()->GetSession();
    umap_roleSock roleSock = SessionMgr::Instance()->GetRoleSock();
    if(addFriend->value == 1) //同意添加
    {
        StringBuilder sbd;
        //将要添加的好友写入到该好友列表中
        sbd << "insert into t_friendlist values(" << addFriend->RoleID << "," << (*smap)[conn].m_roleid << ");";
        Logger::GetLogger()->Debug(sbd.str());
        hf_int32 t_row = srv->getDiskDB()->Set(sbd.str());
        if(t_row == -1)
        {
            Logger::GetLogger()->Error("insert add friendlist error");
        }

        //将该好友添加到要添加的好友列表中
        sbd.Clear();
        sbd << "insert into t_friendlist values(" << (*smap)[conn].m_roleid << "," << addFriend->RoleID<< ");";
        Logger::GetLogger()->Debug(sbd.str());
        t_row = srv->getDiskDB()->Set(sbd.str());
        if(t_row == -1)
        {
            Logger::GetLogger()->Error("insert add friendlist error");
        }

        _umap_roleSock::iterator it = roleSock->find(addFriend->RoleID);
        if(it != roleSock->end()) //在线
        {
            //更新在线好友列表
            STR_FriendInfo t_friendInfo;
            t_friendInfo.RoleID = addFriend->RoleID;
            memcpy(t_friendInfo.Nick, addFriend->Nick, 32);
            t_friendInfo.Status = 1;

            umap_friendList friendList = (*smap)[conn].m_friendList;
            (*friendList)[addFriend->RoleID] = t_friendInfo;

            //更新要添加的好友的在线好友列表
            t_friendInfo.RoleID = (*smap)[conn].m_roleid;
            memcpy(t_friendInfo.Nick, (*smap)[conn].m_RoleBaseInfo.Nick, 32);

            friendList = (*smap)[it->second].m_friendList;
            (*friendList)[(*smap)[conn].m_roleid] = t_friendInfo;


            //发送添加好友返回数据包
            addFriend->RoleID = (*smap)[conn].m_roleid;
            memcpy(addFriend->Nick, (*smap)[conn].m_RoleBaseInfo.Nick, 32);
            it->second->Write_all(addFriend, sizeof(STR_PackAddFriend));
        }
    }
    else //不同意
    {
        _umap_roleSock::iterator it = roleSock->find(addFriend->RoleID);
        if(it != roleSock->end()) //在线
        {
            addFriend->RoleID = (*smap)[conn].m_roleid;
            memcpy(addFriend->Nick, (*smap)[conn].m_RoleBaseInfo.Nick, 32);
            it->second->Write_all(addFriend, sizeof(STR_PackAddFriendReturn));
        }
    }
    srv->free(addFriend);
}
开发者ID:ash-github,项目名称:FatCat-Server,代码行数:66,代码来源:teamfriend.cpp

示例9: ParseLexProfile

	bool MetaLexer::ParseLexProfile(const CoreLib::String & lex)
	{
		LinkedList<LexProfileToken> tokens;
		int ptr = 0;
		int state = 0;
		StringBuilder curToken;
		while (ptr < lex.Length())
		{
			wchar_t curChar = lex[ptr];
			wchar_t nextChar = 0;
			if (ptr+1<lex.Length())
				nextChar = lex[ptr+1];
			switch (state)
			{
			case 0:
				{
					if (IsLetter(curChar))
						state = 1;
					else if (IsWhiteSpace(curChar))
						ptr ++;
					else if (curChar == L'{')
					{
						state = 2;
						ptr ++;
					}
					else if (curChar == L'=')
						state = 3;
					else if (curChar == L'/' && nextChar == L'/')
						state = 4;
					else
					{
						LexerError err;
						err.Position = ptr;
						err.Text = String(L"[Profile Error] Illegal character \'") + curChar + L"\'";
						Errors.Add(err);
						ptr ++;
					}
					curToken.Clear();
				}
				break;
			case 1:
				{
					if (IsIdent(curChar))
					{
						curToken.Append(curChar);
						ptr ++;
					}
					else
					{
						LexProfileToken tk;
						tk.str = curToken.ToString();
						tk.type = LexProfileToken::Identifier;
						tokens.AddLast(tk);
						state = 0;
					}
				}
				break;
			case 2:
				{
					if (curChar == L'}' && (nextChar == L'\r' || nextChar == L'\n' || nextChar == 0) )
					{
						LexProfileToken tk;
						tk.str = curToken.ToString();
						tk.type = LexProfileToken::Regex;
						tokens.AddLast(tk);
						ptr ++;
						state = 0;
					}
					else
					{
						curToken.Append(curChar);
						ptr ++;
					}
				}
				break;
			case 3:
				{
					LexProfileToken tk;
					tk.str = curChar;
					tk.type = LexProfileToken::Equal;
					tokens.AddLast(tk);
					ptr ++;
					state = 0;
				}
				break;
			case 4:
				{
					if (curChar == L'\n')
						state = 0;
					else
						ptr ++;
				}
			}
		}

		// Parse tokens
		LinkedNode<LexProfileToken> * l = tokens.FirstNode();
		state = 0;
		String curName, curRegex;
		try
//.........这里部分代码省略.........
开发者ID:Angelineguan,项目名称:Spire,代码行数:101,代码来源:MetaLexer.cpp


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