本文整理汇总了C++中CStdString::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ CStdString::reserve方法的具体用法?C++ CStdString::reserve怎么用?C++ CStdString::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CStdString
的用法示例。
在下文中一共展示了CStdString::reserve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Process
void InfoPage::Process()
{
while (!m_bStop)
{
PrintMenu();
int i;
static char buff[200] = "";
scanf("%d %s", &i, buff);
if (i == 0) {
exit(0);
}
std::map<int, std::pair<InfoPageble*, CStdString> >::iterator iter;
iter = pages.find(i);
if (iter != pages.end()) {
CStdString page;
CStdString params(buff);
page.reserve(10000);
iter->second.first->GetInfoPage(&page, params);
printf("%s\n", page.c_str());
} else {
printf("Page not found\n");
}
}
}
示例2: Get
CStdString CURL::Get() const
{
unsigned int sizeneed = m_strProtocol.length()
+ m_strDomain.length()
+ m_strUserName.length()
+ m_strPassword.length()
+ m_strHostName.length()
+ m_strFileName.length()
+ m_strOptions.length()
+ m_strProtocolOptions.length()
+ 10;
if (m_strProtocol == "")
return m_strFileName;
CStdString strURL;
strURL.reserve(sizeneed);
strURL = GetWithoutFilename();
strURL += m_strFileName;
if( m_strOptions.length() > 0 )
strURL += m_strOptions;
if (m_strProtocolOptions.length() > 0)
strURL += "|"+m_strProtocolOptions;
return strURL;
}
示例3: GetURLWithoutFilename
void CURL::GetURLWithoutFilename(CStdString& strURL) const
{
unsigned int sizeneed = m_strProtocol.length()
+ m_strDomain.length()
+ m_strUserName.length()
+ m_strPassword.length()
+ m_strHostName.length()
+ 10;
if( strURL.capacity() < sizeneed )
strURL.reserve(sizeneed);
if (m_strProtocol == "")
{
#ifdef _LINUX
strURL.Empty();
#else
strURL = m_strFileName.substr(0, 2); // only copy 'e:'
#endif
return ;
}
strURL = m_strProtocol;
strURL += "://";
if (m_strDomain != "")
{
strURL += m_strDomain;
strURL += ";";
}
else if (m_strUserName != "")
{
strURL += URLEncodeInline(m_strUserName);
if (m_strPassword != "")
{
strURL += ":";
strURL += URLEncodeInline(m_strPassword);
}
strURL += "@";
}
else if (m_strDomain != "")
strURL += "@";
if (m_strHostName != "")
{
if( m_strProtocol.Equals("rar") || m_strProtocol.Equals("zip") || m_strProtocol.Equals("musicsearch"))
strURL += URLEncodeInline(m_strHostName);
else
strURL += m_strHostName;
if (HasPort())
{
CStdString strPort;
strPort.Format("%i", m_iPort);
strURL += ":";
strURL += strPort;
}
strURL += "/";
}
}
示例4: LoadFile
bool CXBMCTinyXML::LoadFile(const CStdString &_filename, TiXmlEncoding encoding)
{
// There was a really terrifying little bug here. The code:
// value = filename
// in the STL case, cause the assignment method of the std::string to
// be called. What is strange, is that the std::string had the same
// address as it's c_str() method, and so bad things happen. Looks
// like a bug in the Microsoft STL implementation.
// Add an extra string to avoid the crash.
CStdString filename(_filename);
value = filename;
XFILE::CFileStream file;
if (!file.Open(value))
{
SetError(TIXML_ERROR_OPENING_FILE, NULL, NULL, TIXML_ENCODING_UNKNOWN);
return false;
}
// Delete the existing data:
Clear();
location.Clear();
CStdString data;
data.reserve(8 * 1000);
StreamIn(&file, &data);
file.Close();
Parse(data, NULL, encoding);
if (Error())
return false;
return true;
}
示例5: GetURL
void CURL::GetURL(CStdString& strURL) const
{
unsigned int sizeneed = m_strProtocol.length()
+ m_strDomain.length()
+ m_strUserName.length()
+ m_strPassword.length()
+ m_strHostName.length()
+ m_strFileName.length()
+ m_strOptions.length()
+ 10;
if( strURL.capacity() < sizeneed )
strURL.reserve(sizeneed);
if (m_strProtocol == "")
{
strURL = m_strFileName;
return ;
}
GetURLWithoutFilename(strURL);
strURL += m_strFileName;
if( m_strOptions.length() > 0 )
strURL += m_strOptions;
}
示例6: GetWithoutFilename
CStdString CURL::GetWithoutFilename() const
{
if (m_strProtocol == "")
return "";
unsigned int sizeneed = m_strProtocol.length()
+ m_strDomain.length()
+ m_strUserName.length()
+ m_strPassword.length()
+ m_strHostName.length()
+ 10;
CStdString strURL;
strURL.reserve(sizeneed);
strURL = m_strProtocol;
strURL += "://";
if (m_strDomain != "")
{
strURL += m_strDomain;
strURL += ";";
}
else if (m_strUserName != "")
{
strURL += URLEncodeInline(m_strUserName);
if (m_strPassword != "")
{
strURL += ":";
strURL += URLEncodeInline(m_strPassword);
}
strURL += "@";
}
else if (m_strDomain != "")
strURL += "@";
if (m_strHostName != "")
{
if( URIUtils::ProtocolHasEncodedHostname(m_strProtocol) )
strURL += URLEncodeInline(m_strHostName);
else
strURL += m_strHostName;
if (HasPort())
{
CStdString strPort;
strPort.Format("%i", m_iPort);
strURL += ":";
strURL += strPort;
}
strURL += "/";
}
return strURL;
}
示例7: Log
void ILogger::Log(int loglevel, const char *format, ... )
{
CStdString strData;
strData.reserve(16384);
va_list va;
va_start(va, format);
strData.FormatV(format,va);
va_end(va);
log(loglevel, strData);
}
示例8: DebugLog
void CLog::DebugLog(const char *format, ... )
{
#ifdef _DEBUG
CSingleLock waitLock(critSec);
CStdString strData;
strData.reserve(16384);
va_list va;
va_start(va, format);
strData.FormatV(format, va);
va_end(va);
OutputDebugString(strData.c_str());
if( strData.Right(1) != "\n" )
OutputDebugString("\n");
#endif
}
示例9: Encode
void CURL::Encode(CStdString& strURLData)
{
CStdString strResult;
/* wonder what a good value is here is, depends on how often it occurs */
strResult.reserve( strURLData.length() * 2 );
for (int i = 0; i < (int)strURLData.size(); ++i)
{
int kar = (unsigned char)strURLData[i];
//if (kar == ' ') strResult += '+'; // obsolete
if (isalnum(kar) || strchr("-_.!()" , kar) ) // Don't URL encode these according to RFC1738
{
strResult += kar;
}
else
{
CStdString strTmp;
strTmp.Format("%%%02.2x", kar);
strResult += strTmp;
}
}
strURLData = strResult;
}
示例10: Decode
void CURL::Decode(CStdString& strURLData)
//modified to be more accomodating - if a non hex value follows a % take the characters directly and don't raise an error.
// However % characters should really be escaped like any other non safe character (www.rfc-editor.org/rfc/rfc1738.txt)
{
CStdString strResult;
/* result will always be less than source */
strResult.reserve( strURLData.length() );
for (unsigned int i = 0; i < strURLData.size(); ++i)
{
int kar = (unsigned char)strURLData[i];
if (kar == '+') strResult += ' ';
else if (kar == '%')
{
if (i < strURLData.size() - 2)
{
CStdString strTmp;
strTmp.assign(strURLData.substr(i + 1, 2));
int dec_num=-1;
sscanf(strTmp,"%x",(unsigned int *)&dec_num);
if (dec_num<0 || dec_num>255)
strResult += kar;
else
{
strResult += (char)dec_num;
i += 2;
}
}
else
strResult += kar;
}
else strResult += kar;
}
strURLData = strResult;
}
示例11: Log
void CLog::Log(int loglevel, const char *format, ... )
{
if (g_advancedSettings.m_logLevel > LOG_LEVEL_NORMAL ||
(g_advancedSettings.m_logLevel > LOG_LEVEL_NONE && loglevel >= LOGNOTICE))
{
CSingleLock waitLock(critSec);
if (!fd)
{
// g_stSettings.m_logFolder is initialized in the CSettings constructor to Q:
// and if we are running from DVD, it's changed to T: in CApplication::Create()
CStdString strLogFile, strLogFileOld;
strLogFile.Format("%sxbmc.log", _P(g_stSettings.m_logFolder).c_str());
strLogFileOld.Format("%sxbmc.old.log", _P(g_stSettings.m_logFolder).c_str());
#ifndef _LINUX
::DeleteFile(strLogFileOld.c_str());
::MoveFile(strLogFile.c_str(), strLogFileOld.c_str());
#else
::unlink(strLogFileOld.c_str());
::rename(strLogFile.c_str(), strLogFileOld.c_str());
#endif
#ifndef _LINUX
fd = _fsopen(strLogFile, "a+", _SH_DENYWR);
#else
fd = fopen(strLogFile, "a+");
#endif
}
if (!fd)
return ;
SYSTEMTIME time;
GetLocalTime(&time);
MEMORYSTATUS stat;
GlobalMemoryStatus(&stat);
CStdString strPrefix, strData;
#ifdef __APPLE__
strPrefix.Format("%02.2d:%02.2d:%02.2d T:%lu M:%9ju %7s: ", time.wHour, time.wMinute, time.wSecond, GetCurrentThreadId(), stat.dwAvailPhys, levelNames[loglevel]);
#else
strPrefix.Format("%02.2d:%02.2d:%02.2d T:%lu M:%9u %7s: ", time.wHour, time.wMinute, time.wSecond, GetCurrentThreadId(), stat.dwAvailPhys, levelNames[loglevel]);
#endif
strData.reserve(16384);
va_list va;
va_start(va, format);
strData.FormatV(format,va);
va_end(va);
int length = 0;
while ( length != (int)strData.length() )
{
length = strData.length();
strData.TrimRight(" ");
strData.TrimRight('\n');
strData.TrimRight("\r");
}
#if !defined(_LINUX) && (defined(_DEBUG) || defined(PROFILE))
OutputDebugString(strData.c_str());
OutputDebugString("\n");
#endif
/* fixup newline alignment, number of spaces should equal prefix length */
strData.Replace("\n", "\n ");
strData += "\n";
fwrite(strPrefix.c_str(), strPrefix.size(), 1, fd);
fwrite(strData.c_str(), strData.size(), 1, fd);
fflush(fd);
}
#ifndef _LINUX
#if defined(_DEBUG) || defined(PROFILE)
else
{
// In debug mode dump everything to devstudio regardless of level
CSingleLock waitLock(critSec);
CStdString strData;
strData.reserve(16384);
va_list va;
va_start(va, format);
strData.FormatV(format, va);
va_end(va);
OutputDebugString(strData.c_str());
if( strData.Right(1) != "\n" )
OutputDebugString("\n");
}
#endif
#endif
}
示例12: GetDirectory
bool CDirectoryTuxBox::GetDirectory(const CStdString& strPath, CFileItemList &items)
{
// so we know that we have enigma2
static bool enigma2 = false;
// Detect and delete slash at end
CStdString strRoot = strPath;
if (CUtil::HasSlashAtEnd(strRoot))
strRoot.Delete(strRoot.size() - 1);
//Get the request strings
CStdString strBQRequest;
CStdString strXMLRootString;
CStdString strXMLChildString;
if(!GetRootAndChildString(strRoot, strBQRequest, strXMLRootString, strXMLChildString))
return false;
//Set url Protocol
CURL url(strRoot);
CStdString strFilter;
CStdString protocol = url.GetProtocol();
CStdString strOptions = url.GetOptions();
url.SetProtocol("http");
bool bIsBouquet=false;
int ipoint = strOptions.Find("?path=");
if (ipoint >=0)
{
// send Zap!
return g_tuxbox.ZapToUrl(url, strOptions, ipoint);
}
else
{
ipoint = strOptions.Find("&reference=");
if (ipoint >=0 || enigma2)
{
//List reference
strFilter = strOptions.Right((strOptions.size()-(ipoint+11)));
bIsBouquet = false; //On Empty is Bouquet
if (enigma2)
{
CStdString strPort;
strPort.Format(":%i",url.GetPort());
if (strRoot.Right(strPort.GetLength()) != strPort) // If not root dir, enable Channels
strFilter = "e2"; // Disable Bouquets for Enigma2
GetRootAndChildStringEnigma2(strBQRequest, strXMLRootString, strXMLChildString);
url.SetOptions("");
url.SetFileName(strBQRequest);
}
}
}
if(strFilter.IsEmpty())
{
url.SetOptions(strBQRequest);
bIsBouquet = true;
}
//Open
CFileCurl http;
int iTryConnect = 0;
int iWaitTimer = 20;
bool result = false;
while (iTryConnect < 4)
{
http.SetTimeout(iWaitTimer);
if(http.Open(url))
{
//We are connected!
iTryConnect = 4;
// restore protocol
url.SetProtocol(protocol);
int size_read = 0;
int size_total = (int)http.GetLength();
int data_size = 0;
CStdString data;
data.reserve(size_total);
// read response from server into string buffer
char buffer[16384];
while ((size_read = http.Read(buffer, sizeof(buffer)-1)) > 0)
{
buffer[size_read] = 0;
data += buffer;
data_size += size_read;
}
http.Close();
// parse returned xml
TiXmlDocument doc;
data.Replace("></",">-</"); //FILL EMPTY ELEMENTS WITH "-"!
doc.Parse(data.c_str());
TiXmlElement *root = doc.RootElement();
if(root == NULL)
{
CLog::Log(LOGERROR, "%s - Unable to parse xml", __FUNCTION__);
CLog::Log(LOGERROR, "%s - Sample follows...\n%s", __FUNCTION__, data.c_str());
return false;
}
//.........这里部分代码省略.........
示例13: Log
void CLog::Log(int loglevel, const char *format, ... )
{
if (g_advancedSettings.m_logLevel > LOG_LEVEL_NORMAL ||
(g_advancedSettings.m_logLevel > LOG_LEVEL_NONE && loglevel >= LOGNOTICE))
{
CSingleLock waitLock(critSec);
if (!m_file)
return;
SYSTEMTIME time;
GetLocalTime(&time);
MEMORYSTATUS stat;
GlobalMemoryStatus(&stat);
CStdString strPrefix, strData;
strPrefix.Format("%02.2d:%02.2d:%02.2d T:%"PRIu64" M:%9"PRIu64" %7s: ", time.wHour, time.wMinute, time.wSecond, (uint64_t)CThread::GetCurrentThreadId(), (uint64_t)stat.dwAvailPhys, levelNames[loglevel]);
strData.reserve(16384);
va_list va;
va_start(va, format);
strData.FormatV(format,va);
va_end(va);
if (m_repeatLogLevel == loglevel && *m_repeatLine == strData)
{
m_repeatCount++;
return;
}
else if (m_repeatCount)
{
CStdString strPrefix2, strData2;
strPrefix2.Format("%02.2d:%02.2d:%02.2d T:%"PRIu64" M:%9"PRIu64" %7s: ", time.wHour, time.wMinute, time.wSecond, (uint64_t)CThread::GetCurrentThreadId(), (uint64_t)stat.dwAvailPhys, levelNames[m_repeatLogLevel]);
strData2.Format("Previous line repeats %d times." LINE_ENDING, m_repeatCount);
fwrite(strPrefix2.c_str(),strPrefix2.size(),1,m_file);
fwrite(strData2.c_str(),strData2.size(),1,m_file);
#if !defined(_LINUX) && (defined(_DEBUG) || defined(PROFILE))
OutputDebugString(strData2.c_str());
#endif
m_repeatCount = 0;
}
*m_repeatLine = strData;
m_repeatLogLevel = loglevel;
unsigned int length = 0;
while ( length != strData.length() )
{
length = strData.length();
strData.TrimRight(" ");
strData.TrimRight('\n');
strData.TrimRight("\r");
}
if (!length)
return;
#if !defined(_LINUX) && (defined(_DEBUG) || defined(PROFILE))
OutputDebugString(strData.c_str());
OutputDebugString("\n");
#endif
/* fixup newline alignment, number of spaces should equal prefix length */
strData.Replace("\n", LINE_ENDING" ");
strData += LINE_ENDING;
fwrite(strPrefix.c_str(),strPrefix.size(),1,m_file);
fwrite(strData.c_str(),strData.size(),1,m_file);
fflush(m_file);
}
#ifndef _LINUX
#if defined(_DEBUG) || defined(PROFILE)
else
{
// In debug mode dump everything to devstudio regardless of level
CSingleLock waitLock(critSec);
CStdString strData;
strData.reserve(16384);
va_list va;
va_start(va, format);
strData.FormatV(format, va);
va_end(va);
OutputDebugString(strData.c_str());
if( strData.Right(1) != "\n" )
OutputDebugString("\n");
}
#endif
#endif
}
示例14: GetWithoutUserDetails
CStdString CURL::GetWithoutUserDetails() const
{
CStdString strURL;
if (m_strProtocol.Equals("stack"))
{
CFileItemList items;
CStdString strURL2;
strURL2 = Get();
XFILE::CStackDirectory dir;
dir.GetDirectory(strURL2,items);
vector<CStdString> newItems;
for (int i=0;i<items.Size();++i)
{
CURL url(items[i]->GetPath());
items[i]->SetPath(url.GetWithoutUserDetails());
newItems.push_back(items[i]->GetPath());
}
dir.ConstructStackPath(newItems,strURL);
return strURL;
}
unsigned int sizeneed = m_strProtocol.length()
+ m_strDomain.length()
+ m_strHostName.length()
+ m_strFileName.length()
+ m_strOptions.length()
+ m_strProtocolOptions.length()
+ 10;
strURL.reserve(sizeneed);
if (m_strProtocol == "")
return m_strFileName;
strURL = m_strProtocol;
strURL += "://";
if (m_strHostName != "")
{
if (URIUtils::ProtocolHasParentInHostname(m_strProtocol))
strURL += CURL(m_strHostName).GetWithoutUserDetails();
else
strURL += m_strHostName;
if ( HasPort() )
{
CStdString strPort;
strPort.Format("%i", m_iPort);
strURL += ":";
strURL += strPort;
}
strURL += "/";
}
strURL += m_strFileName;
if( m_strOptions.length() > 0 )
strURL += m_strOptions;
if( m_strProtocolOptions.length() > 0 )
strURL += "|"+m_strProtocolOptions;
return strURL;
}
示例15: GetDirectory
bool CShoutcastDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
{
CStdString strRoot = strPath;
if (CUtil::HasSlashAtEnd(strRoot))
strRoot.Delete(strRoot.size() - 1);
/* for old users wich doesn't have the full url */
if( strRoot.Equals("shout://www.shoutcast.com") )
strRoot = "shout://www.shoutcast.com/sbin/newxml.phtml";
if (g_directoryCache.GetDirectory(strRoot, items))
return true;
CGUIDialogProgress* dlgProgress = (CGUIDialogProgress*)m_gWindowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
if (dlgProgress)
{
dlgProgress->ShowProgressBar(false);
dlgProgress->SetHeading(260);
dlgProgress->SetLine(0, 14003);
dlgProgress->SetLine(1, "");
dlgProgress->SetLine(2, "");
dlgProgress->StartModal();
}
CURL url(strRoot);
CStdString protocol = url.GetProtocol();
url.SetProtocol("http");
CFileCurl http;
//CURL doesn't seem to understand that data is encoded.. odd
// opening as text for now
//http.SetContentEncoding("deflate");
if( !http.Open(url, false) )
{
CLog::Log(LOGERROR, "%s - Unable to get shoutcast dir", __FUNCTION__);
if (dlgProgress) dlgProgress->Close();
return false;
}
/* restore protocol */
url.SetProtocol(protocol);
CStdString content = http.GetContent();
if( !(content.Equals("text/html") || content.Equals("text/xml")
|| content.Equals("text/html;charset=utf-8") || content.Equals("text/xml;charset=utf-8") ))
{
CLog::Log(LOGERROR, "%s - Invalid content type %s", __FUNCTION__, content.c_str());
if (dlgProgress) dlgProgress->Close();
return false;
}
int size_read = 0;
int size_total = (int)http.GetLength();
int data_size = 0;
CStdString data;
data.reserve(size_total);
/* read response from server into string buffer */
char buffer[16384];
while( (size_read = http.Read(buffer, sizeof(buffer)-1)) > 0 )
{
buffer[size_read] = 0;
data += buffer;
data_size += size_read;
dlgProgress->Progress();
if (dlgProgress->IsCanceled())
{
dlgProgress->Close();
return false;
}
}
/* parse returned xml */
TiXmlDocument doc;
doc.Parse(data.c_str());
TiXmlElement *root = doc.RootElement();
if(root == NULL)
{
CLog::Log(LOGERROR, "%s - Unable to parse xml", __FUNCTION__);
CLog::Log(LOGDEBUG, "%s - Sample follows...\n%s", __FUNCTION__, data.c_str());
dlgProgress->Close();
return false;
}
/* clear data to keep memusage down, not needed anymore */
data.Empty();
bool result = false;
if( strcmp(root->Value(), "genrelist") == 0 )
result = ParseGenres(root, items, url);
else if( strcmp(root->Value(), "stationlist") == 0 )
//.........这里部分代码省略.........