本文整理汇总了C++中behaviac::string::size方法的典型用法代码示例。如果您正苦于以下问题:C++ string::size方法的具体用法?C++ string::size怎么用?C++ string::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类behaviac::string
的用法示例。
在下文中一共展示了string::size方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsArrayString
//it returns true if 'str' starts with a count followed by ':'
//3:{....}
bool IsArrayString(const behaviac::string& str, int posStart, behaviac::string::size_type& posEnd)
{
//begin of the count of an array?
//int posStartOld = posStart;
bool bIsDigit = false;
int strLen = (int)str.size();
while (posStart < strLen)
{
char c = str[posStart++];
if (isdigit(c))
{
bIsDigit = true;
}
else if (c == ':' && bIsDigit)
{
//transit_points = 3:{coordX = 0; coordY = 0; } | {coordX = 0; coordY = 0; } | {coordX = 0; coordY = 0; };
//skip array item which is possible a struct
int depth = 0;
for (int posStart2 = posStart; posStart2 < strLen; posStart2++)
{
char c1 = str[posStart2];
if (c1 == ';' && depth == 0)
{
//the last ';'
posEnd = posStart2;
break;
}
else if (c1 == '{')
{
BEHAVIAC_ASSERT(depth < 10);
depth++;
}
else if (c1 == '}')
{
BEHAVIAC_ASSERT(depth > 0);
depth--;
}
}
return true;
}
else
{
break;
}
}
return false;
}
示例2: MBSToWCS
/// convert multibyte string to wide char string
bool MBSToWCS(behaviac::wstring& resultString, const behaviac::string& str, const char* locale)
{
BEHAVIAC_UNUSED_VAR(resultString);
BEHAVIAC_UNUSED_VAR(str);
BEHAVIAC_UNUSED_VAR(locale);
bool ret = false;
#if BEHAVIAC_COMPILER_MSVC
const int cp = (strcmp(locale, LOCALE_CN_UTF8) == 0) ? CP_UTF8 : CP_ACP;
const int dwNum = MultiByteToWideChar(cp, 0, str.c_str(), -1, 0, 0);
wchar_t* buffer = (wchar_t*)BEHAVIAC_MALLOC_WITHTAG(dwNum * 2 + 2, "MBSToWCS");
if (buffer)
{
MultiByteToWideChar(cp, 0, str.c_str(), -1, buffer, dwNum);
resultString = buffer;
BEHAVIAC_FREE(buffer);
ret = true;
}
#else
uint32_t dwNum = (str.size() + 1) * 4;
wchar_t* buffer = (wchar_t*)BEHAVIAC_MALLOC_WITHTAG(dwNum, "MBSToWCS");
if (buffer)
{
//remember it to restore it later
char* currrentLocale = setlocale(LC_ALL, 0);
char* loc = setlocale(LC_ALL, locale);
if (loc)
{
mbstowcs(buffer, str.c_str(), dwNum);
ret = true;
}
//restore
setlocale(LC_ALL, currrentLocale);
resultString = buffer;
BEHAVIAC_FREE(buffer);
}
#endif//#if BEHAVIAC_COMPILER_MSVC
return ret;
}
示例3: ParseForParams
//suppose params are seprated by ','
static void ParseForParams(const behaviac::string& tsrc, behaviac::vector<behaviac::string>& params)
{
int tsrcLen = (int)tsrc.size();
int startIndex = 0;
int index = 0;
int quoteDepth = 0;
for (; index < tsrcLen; ++index)
{
if (tsrc[index] == '"')
{
quoteDepth++;
//if (quoteDepth == 1)
//{
// startIndex = index;
//}
if ((quoteDepth & 0x1) == 0)
{
//closing quote
quoteDepth -= 2;
BEHAVIAC_ASSERT(quoteDepth >= 0);
}
}
else if (quoteDepth == 0 && tsrc[index] == ',')
{
//skip ',' inside quotes, like "count, count"
int lengthTemp = index - startIndex;
behaviac::string strTemp = tsrc.substr(startIndex, lengthTemp);
params.push_back(strTemp);
startIndex = index + 1;
}
}//end for
// the last param
int lengthTemp = index - startIndex;
if (lengthTemp > 0)
{
behaviac::string strTemp = tsrc.substr(startIndex, lengthTemp);
params.push_back(strTemp);
//params.push_back(strTemp);
}
}