本文整理汇总了C++中std::string::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ string::clear方法的具体用法?C++ string::clear怎么用?C++ string::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::string
的用法示例。
在下文中一共展示了string::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dotag
void dotag()
{
last_tag = current;
std::string name;
nextword(name);
int spc = next();
if (spc == '>')
unget(spc);
else if (!isspace(spc))
throw CoreException("Invalid character in tag name");
if (name.empty())
throw CoreException("Empty tag name");
ConfigItems* items;
tag = ConfigTag::create(name, current.filename, current.line, items);
while (kv(items))
{
// Do nothing here (silences a GCC warning).
}
if (name == mandatory_tag)
{
// Found the mandatory tag
mandatory_tag.clear();
}
if (name == "include")
{
stack.DoInclude(tag, flags);
}
else if (name == "files")
{
for(ConfigItems::iterator i = items->begin(); i != items->end(); i++)
{
stack.DoReadFile(i->first, i->second, flags, false);
}
}
else if (name == "execfiles")
{
for(ConfigItems::iterator i = items->begin(); i != items->end(); i++)
{
stack.DoReadFile(i->first, i->second, flags, true);
}
}
else if (name == "define")
{
if (flags & FLAG_USE_COMPAT)
throw CoreException("<define> tags may only be used in XML-style config (add <config format=\"xml\">)");
std::string varname = tag->getString("name");
std::string value = tag->getString("value");
if (varname.empty())
throw CoreException("Variable definition must include variable name");
stack.vars[varname] = value;
}
else if (name == "config")
{
std::string format = tag->getString("format");
if (format == "xml")
flags &= ~FLAG_USE_COMPAT;
else if (format == "compat")
flags |= FLAG_USE_COMPAT;
else if (!format.empty())
throw CoreException("Unknown configuration format " + format);
}
else
{
stack.output.insert(std::make_pair(name, tag));
}
// this is not a leak; reference<> takes care of the delete
tag = NULL;
}
示例2: main
int main(int argc, char **argv)
{
bool force_selector = false;
bool no_variadic = false;
bool no_macro = false;
bool no_include = false;
char const *author = "Unknown Author";
char const *hwprefix = "";
if(argc <= 1)
usage();
while(1)
{
static struct option long_options[] =
{
{"help", no_argument, 0, '?'},
{"selector", no_argument, 0, 's'},
{"no-macro", no_argument, 0, 'm'},
{"no-include", no_argument, 0, 'i'},
{"no-variadic", no_argument, 0, 'v'},
{"reg-prefix", required_argument, 0, 'p'},
{"author", required_argument, 0, 'a'},
{0, 0, 0, 0}
};
int c = getopt_long(argc, argv, "?smivp:a:", long_options, NULL);
if(c == -1)
break;
switch(c)
{
case -1:
break;
case '?':
usage();
break;
case 's':
force_selector = true;
break;
case 'm':
no_macro = true;
break;
case 'i':
no_include = true;
break;
case 'v':
no_variadic = true;
break;
case 'a' :
author = optarg;
break;
case 'p' :
hwprefix = optarg;
break;
default:
abort();
}
}
std::vector< soc_t > socs;
for(int i = optind; i < argc - 1; i++)
{
soc_t s;
if(!parse_xml(argv[i], s))
{
printf("Cannot parse %s\n", argv[i]);
return 1;
}
socs.push_back(s);
}
g_gen_selector = force_selector || socs.size() > 1;
if(!no_macro)
{
g_macro_filename = std::string(argv[argc - 1]) + "/regs-macro.h";
gen_macro(g_macro_filename, !no_variadic, author, hwprefix);
g_macro_filename = "regs-macro.h";
if(no_include)
g_macro_filename.clear();
}
if(g_gen_selector)
{
gen_selectors(argv[argc - 1], socs, author);
g_macro_filename.clear();
}
gen_headers(argv[argc - 1], socs, author, hwprefix);
return 0;
}
示例3: execute
// CancelWithHUD
bool mwseCancelWithHUD::execute(mwseInstruction *_this)
{
currentHUDName.clear();
currentHUD = MGEhud::invalid_hud_id;
return true;
}
示例4: process
virtual void process(const std::string& message)
{
mFormattedMessage.clear();
MessageFormatParser::process(message);
}
示例5: sendImpl
virtual void sendImpl(const void *data, int size, int code, bool chunked) {
m_response.clear();
m_response.append((const char *)data, size);
m_code = code;
}
示例6: GetServer
bool AuthManagerImpl::GetServer(std::string &_ipAddress, std::string &_port)
{
//获取server.ini绝对路径
char path[MAX_PATH] = {0};
GetModuleFileNameA(GetModuleHandleA(AUTH_IMPL_DLL), path, MAX_PATH);
std::string sPath(path);
sPath = sPath.substr(0, sPath.rfind("\\")+1);
sPath.append(SERVER_INI_FILE);
//先清空
_ipAddress.clear();
_port.clear();
const int IP_LENGTH = 16;
char acIPAddr[IP_LENGTH] = {0};
const int PORT_LENGTH = 8;
char acPort[PORT_LENGTH] = {0};
//读取server.ini文件中的SSO Server IP和端口号
DWORD dwNum = ::GetPrivateProfileStringA(NODE_STRING,IP_STRING,"",acIPAddr,IP_LENGTH,sPath.c_str());
DWORD dwNum1 = ::GetPrivateProfileStringA(NODE_STRING,PORT_STRING,"",acPort,PORT_LENGTH,sPath.c_str());
if ((0 == dwNum) || (0 == dwNum1))
{
//读取eSpace当前使用的服务器,server1 or server2
const int SERVER_LENGTH = 16;
char acServer[SERVER_LENGTH] = {0};
dwNum = ::GetPrivateProfileStringA(NODE_STRING,SERVER_STRING,"",acServer,SERVER_LENGTH,sPath.c_str());
if (0 == dwNum)
{
return false;
}
//判断当前使用的服务器是server1还是server2
if (0 == _stricmp(acServer, "server1"))
{
//读取server1的IP和端口号
dwNum = ::GetPrivateProfileStringA(NODE_STRING,SERVER1IP_STRING,"",acIPAddr,IP_LENGTH,sPath.c_str());
dwNum1 = ::GetPrivateProfileStringA(NODE_STRING,SERVER1PORT_STRING,"",acPort,PORT_LENGTH,sPath.c_str());
if ((0 == dwNum) || (0 == dwNum1))
{
//读取server1备用的IP和端口号
dwNum = ::GetPrivateProfileStringA(NODE_STRING,SERVER1IPBAK_STRING,"",acIPAddr,IP_LENGTH,sPath.c_str());
dwNum1 = ::GetPrivateProfileStringA(NODE_STRING,SERVER1PORTBAK_STRING,"",acPort,PORT_LENGTH,sPath.c_str());
if ((0 == dwNum) || (0 == dwNum1))
{
return false;
}
}
}
else if (0 == _stricmp(acServer, "server2"))
{
//读取server2的IP和端口号
dwNum = ::GetPrivateProfileStringA(NODE_STRING,SERVER2IP_STRING,"",acIPAddr,IP_LENGTH,sPath.c_str());
dwNum1 = ::GetPrivateProfileStringA(NODE_STRING,SERVER2PORT_STRING,"",acPort,PORT_LENGTH,sPath.c_str());
if ((0 == dwNum) || (0 == dwNum1))
{
//读取server2备用的IP和端口号
dwNum = ::GetPrivateProfileStringA(NODE_STRING,SERVER2IPBAK_STRING,"",acIPAddr,IP_LENGTH,sPath.c_str());
dwNum1 = ::GetPrivateProfileStringA(NODE_STRING,SERVER2PORTBAK_STRING,"",acPort,PORT_LENGTH,sPath.c_str());
if ((0 == dwNum) || (0 == dwNum1))
{
return false;
}
}
}
else
{
return false;
}
}
//检查IP地址和端口的合法性
bool bRet = CheckIpAndPort(acIPAddr, acPort);
if (!bRet)
{
return false;
}
_ipAddress = acIPAddr;
_port = acPort;
return true;
}
示例7: GetImageData
bool EasyDarwinDeviceSnapUpdateReq::GetImageData(std::string &sImageBase64Data)
{
sImageBase64Data.clear();
sImageBase64Data = GetBodyValue("Img");
return !sImageBase64Data.empty();
}
示例8: l
~logger()
{
mutex::scoped_lock l(file_mutex);
log_file.close();
open_filename.clear();
}
示例9: Create
bool CDlgEventLog::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin CDlgEventLog member initialisation
CMainDocument* pDoc = wxGetApp().GetDocument();
wxASSERT(pDoc);
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
m_iPreviousRowCount = 0;
m_iTotalDocCount = 0;
m_iPreviousFirstMsgSeqNum = pDoc->GetFirstMsgSeqNum();
m_iPreviousLastMsgSeqNum = m_iPreviousFirstMsgSeqNum - 1;
m_iNumDeletedFilteredRows = 0;
m_iTotalDeletedFilterRows = 0;
if (!s_bIsFiltered) {
s_strFilteredProjectName.clear();
}
m_iFilteredIndexes.Clear();
m_bProcessingRefreshEvent = false;
m_bWasConnected = false;
m_bEventLogIsOpen = true;
////@end CDlgEventLog member initialisation
CSkinAdvanced* pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
wxPoint oTempPoint;
wxSize oTempSize;
wxASSERT(pSkinAdvanced);
wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced));
if ((pos == wxDefaultPosition) && (size == wxDefaultSize)) {
// Get size and position from the previous configuration
GetWindowDimensions( oTempPoint, oTempSize );
#ifdef __WXMSW__
// Get the current display space for the current window
int iDisplay = wxNOT_FOUND;
if ( wxGetApp().GetFrame() != NULL ) iDisplay = wxDisplay::GetFromWindow(wxGetApp().GetFrame());
if ( iDisplay == wxNOT_FOUND ) iDisplay = 0;
wxDisplay *display = new wxDisplay(iDisplay);
wxRect rDisplay = display->GetClientArea();
// Check that the saved height and width is not larger than the displayable space.
// If it is, then reduce the size.
if ( oTempSize.GetWidth() > rDisplay.width ) oTempSize.SetWidth(rDisplay.width);
if ( oTempSize.GetHeight() > rDisplay.height ) oTempSize.SetHeight(rDisplay.height);
// Check if part of the display was going to be off the screen, if so, center the
// display on that axis
if ( oTempPoint.x < rDisplay.x ) {
oTempPoint.x = rDisplay.x;
} else if ( oTempPoint.x + oTempSize.GetWidth() > rDisplay.x + rDisplay.width ) {
oTempPoint.x = rDisplay.x + rDisplay.width - oTempSize.GetWidth();
}
if ( oTempPoint.y < rDisplay.y ) {
oTempPoint.y = rDisplay.y;
} else if ( oTempPoint.y + oTempSize.GetHeight() > rDisplay.y + rDisplay.height ) {
oTempPoint.y = rDisplay.y + rDisplay.height - oTempSize.GetHeight();
}
delete display;
#endif
#ifdef __WXMAC__
// If the user has changed the arrangement of multiple
// displays, make sure the window title bar is still on-screen.
if (!IsWindowOnScreen(oTempPoint.x, oTempPoint.y, oTempSize.GetWidth(), oTempSize.GetHeight())) {
oTempPoint.y = oTempPoint.x = 30;
}
#endif // ! __WXMAC__
} else {
oTempPoint = pos;
oTempSize = size;
}
wxDialog::Create( parent, id, caption, oTempPoint, oTempSize, style );
SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
// Initialize Application Title
wxString strCaption = caption;
if (strCaption.IsEmpty()) {
strCaption.Printf(_("%s - Event Log"), pSkinAdvanced->GetApplicationName().c_str());
}
SetTitle(strCaption);
// Initialize Application Icon
wxIconBundle icons;
icons.AddIcon(*pSkinAdvanced->GetApplicationIcon());
icons.AddIcon(*pSkinAdvanced->GetApplicationIcon32());
SetIcons(icons);
CreateControls();
// Create List Pane Items
m_pList->InsertColumn(COLUMN_PROJECT, _("Project"), wxLIST_FORMAT_LEFT, 109);
m_pList->InsertColumn(COLUMN_TIME, _("Time"), wxLIST_FORMAT_LEFT, 130);
m_pList->InsertColumn(COLUMN_MESSAGE, _("Message"), wxLIST_FORMAT_LEFT, 378);
//.........这里部分代码省略.........
示例10: LoadDump
DumpReturn PlayerDumpReader::LoadDump(std::string const& file, uint32 account, std::string name, uint32 guid)
{
uint32 charcount = AccountMgr::GetCharactersCount(account);
if (charcount >= 10)
return DUMP_TOO_MANY_CHARS;
FILE* fin = fopen(file.c_str(), "r");
if (!fin)
return DUMP_FILE_OPEN_ERROR;
char newguid[20], chraccount[20], newpetid[20], currpetid[20], lastpetid[20];
// make sure the same guid doesn't already exist and is safe to use
bool incHighest = true;
if (guid != 0 && guid < sObjectMgr->_hiCharGuid)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHECK_GUID);
stmt->setUInt32(0, guid);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
guid = sObjectMgr->_hiCharGuid; // use first free if exists
else incHighest = false;
}
else
guid = sObjectMgr->_hiCharGuid;
// normalize the name if specified and check if it exists
if (!normalizePlayerName(name))
name.clear();
if (ObjectMgr::CheckPlayerName(name, true) == CHAR_NAME_SUCCESS)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHECK_NAME);
stmt->setString(0, name);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
name.clear(); // use the one from the dump
}
else
name.clear();
// name encoded or empty
snprintf(newguid, 20, "%u", guid);
snprintf(chraccount, 20, "%u", account);
snprintf(newpetid, 20, "%u", sObjectMgr->GeneratePetNumber());
snprintf(lastpetid, 20, "%s", "");
std::map<uint32, uint32> items;
std::map<uint32, uint32> mails;
char buf[32000] = "";
typedef std::map<uint32, uint32> PetIds; // old->new petid relation
typedef PetIds::value_type PetIdsPair;
PetIds petids;
uint8 gender = GENDER_NONE;
uint8 race = RACE_NONE;
uint8 playerClass = 0;
uint8 level = 1;
SQLTransaction trans = CharacterDatabase.BeginTransaction();
while (!feof(fin))
{
if (!fgets(buf, 32000, fin))
{
if (feof(fin))
break;
ROLLBACK(DUMP_FILE_BROKEN);
}
std::string line; line.assign(buf);
// skip empty strings
size_t nw_pos = line.find_first_not_of(" \t\n\r\7");
if (nw_pos == std::string::npos)
continue;
// skip logfile-side dump start notice, the important notes and dump end notices
if ((line.substr(nw_pos, 16) == "== START DUMP ==") ||
(line.substr(nw_pos, 15) == "IMPORTANT NOTE:") ||
(line.substr(nw_pos, 14) == "== END DUMP =="))
continue;
// add required_ check
/*
if (line.substr(nw_pos, 41) == "UPDATE character_db_version SET required_")
{
if (!CharacterDatabase.Execute(line.c_str()))
ROLLBACK(DUMP_FILE_BROKEN);
continue;
}
*/
// determine table name and load type
std::string tn = gettablename(line);
if (tn.empty())
//.........这里部分代码省略.........
示例11: SendAndRecvResponse
// 发送webservice调用消息
int CTMSSensor::SendAndRecvResponse(bool bTMSWS,const std::string &request, std::string &response, int delayTime)
{
if(m_strIP.empty())
{
return 0;
}
TcpTransport tcp;
int result= -1;
std::string strIP;
if(bTMSWS)
{
strIP="127.0.0.1";
}
else
{
strIP=m_strIP;
}
result = tcp.TcpConnect(strIP.c_str(), m_nTMSWBPort,delayTime);
if(result < 0)
{
LOGFMT(ULOG_ERROR,"CTMSSensor::SendAndRecvResponse TcpConnect %s:%d Fail !\n",strIP.c_str(), m_nTMSWBPort);
if(!bTMSWS)
{
IPMgr::GetInstance()->GetNextOtherIP(strIP);
if(strIP!=m_strIP)
{
result = tcp.TcpConnect(strIP.c_str(), m_nTMSWBPort,delayTime);
if(result < 0)
{
LOGFMT(ULOG_ERROR,"CTMSSensor::SendAndRecvResponse TcpConnect %s:%d Fail !\n",strIP.c_str(), m_nTMSWBPort);
return ERROR_SENSOR_TCP_CONNECT;
}
else
{
m_strIP=strIP;
LOGFMT(ULOG_ERROR,"CTMSSensor::Set Default Other IP=%s!\n",strIP.c_str());
}
}
}
if(result < 0)
{
return ERROR_SENSOR_TCP_CONNECT;
}
}
result = tcp.BlockSend(request.c_str(), request.size());
if(result < 0)
{
LOGFMT(ULOG_ERROR,"CTMSSensor::SendAndRecvResponse Tcp Send %s Fail(%s:%d) !\n",request.c_str(),
m_strIP.c_str(),m_nTMSWBPort);
return ERROR_SENSOR_TCP_SEND;
}
char buffer[1024];
timeval timeOut;
timeOut.tv_sec = delayTime;
timeOut.tv_usec = 0;
response.clear();
while((result = tcp.SelectRecv(buffer, 1024-1, timeOut)) >= 0)
{
if(result == 0)
break;
buffer[result] = 0;
response += buffer;
if(response.find(":Envelope>") != std::string::npos)
break;
timeOut.tv_sec = 2;
timeOut.tv_usec = 0;
}
return result <0 ? ERROR_SENSOR_TCP_RECV : 0;
}
示例12: builtin_set_color
//.........这里部分代码省略.........
}
if (fgcolor == NULL && bgcolor == NULL && !bold && !underline)
{
append_format(stderr_buffer,
_(L"%ls: Expected an argument\n"),
argv[0]);
return STATUS_BUILTIN_ERROR;
}
const rgb_color_t fg = rgb_color_t(fgcolor ? fgcolor : L"");
if (fgcolor && (fg.is_none() || fg.is_ignore()))
{
append_format(stderr_buffer, _(L"%ls: Unknown color '%ls'\n"), argv[0], fgcolor);
return STATUS_BUILTIN_ERROR;
}
const rgb_color_t bg = rgb_color_t(bgcolor ? bgcolor : L"");
if (bgcolor && (bg.is_none() || bg.is_ignore()))
{
append_format(stderr_buffer, _(L"%ls: Unknown color '%ls'\n"), argv[0], bgcolor);
return STATUS_BUILTIN_ERROR;
}
/* Make sure that the term exists */
if (cur_term == NULL && setupterm(0, STDOUT_FILENO, &errret) == ERR)
{
append_format(stderr_buffer, _(L"%ls: Could not set up terminal\n"), argv[0]);
return STATUS_BUILTIN_ERROR;
}
/*
Test if we have at least basic support for setting fonts, colors
and related bits - otherwise just give up...
*/
if (! exit_attribute_mode)
{
return STATUS_BUILTIN_ERROR;
}
/* Save old output function so we can restore it */
int (* const saved_writer_func)(char) = output_get_writer();
/* Set our output function, which writes to a std::string */
builtin_set_color_output.clear();
output_set_writer(set_color_builtin_outputter);
if (bold)
{
if (enter_bold_mode)
writembs(tparm(enter_bold_mode));
}
if (underline)
{
if (enter_underline_mode)
writembs(enter_underline_mode);
}
if (bgcolor != NULL)
{
if (bg.is_normal())
{
write_background_color(0);
writembs(tparm(exit_attribute_mode));
}
}
if (fgcolor != NULL)
{
if (fg.is_normal() || fg.is_reset())
{
write_foreground_color(0);
writembs(tparm(exit_attribute_mode));
}
else
{
write_foreground_color(index_for_color(fg));
}
}
if (bgcolor != NULL)
{
if (! bg.is_normal() && ! bg.is_reset())
{
write_background_color(index_for_color(bg));
}
}
/* Restore saved writer function */
output_set_writer(saved_writer_func);
/* Output the collected string */
std::string local_output;
std::swap(builtin_set_color_output, local_output);
stdout_buffer.append(str2wcstring(local_output));
return STATUS_BUILTIN_OK;
}
示例13: CleanupDecoder
void CleanupDecoder()
{
s_formatInfos.clear();
s_supportedFormatsFilter.clear();
}
示例14: clear
void clear()
{
cat_.clear();
antecedents_.clear();
removed_ = false;
}
示例15:
StrBlock(){
str.clear();
size=0;
pos.Set(0);
hasStr=false;
}