本文整理汇总了C++中StringTokenizer::hasNextToken方法的典型用法代码示例。如果您正苦于以下问题:C++ StringTokenizer::hasNextToken方法的具体用法?C++ StringTokenizer::hasNextToken怎么用?C++ StringTokenizer::hasNextToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringTokenizer
的用法示例。
在下文中一共展示了StringTokenizer::hasNextToken方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readCookies
void CookieJar::readCookies(HttpHeader* header, CookieOrigin origin)
{
// parse cookies if appropriate cookie field exists
const char* field = (origin == Server ? "Set-Cookie" : "Cookie");
int count = header->getFieldCount(field);
if(count > 0)
{
// Set-Cookie: cookie1_name=cookie1_value; max-age=0; path=/
// Set-Cookie: c2=v2; expires=Thu, 21-Aug-2008 23:47:25 GMT; path=/
// Cookie: cookie1_name=cookie1_value; cookie2_name=cookie2_value
// parse cookies by semi-colons (cannot parse by commas because
// the "expires" value may contain a comma and no one follows the
// standard)
string cookies;
Cookie cookie(NULL);
TimeZone gmt = TimeZone::getTimeZone("GMT");
Date d;
Date now;
bool name;
StringTokenizer pairs;
for(int i = 0; i < count; ++i)
{
name = true;
header->getField(field, cookies, i);
pairs.tokenize(cookies.c_str(), ';');
while(pairs.hasNextToken())
{
// get next token (name=value)
const char* token = pairs.nextToken();
// get name part of token
size_t nameLength = strcspn(token, "=");
char tmpName[nameLength + 1];
strncpy(tmpName, token, nameLength);
tmpName[nameLength] = 0;
// trim whitespace from name
char* namePtr = (tmpName + nameLength);
for(; namePtr != tmpName && *namePtr == ' '; --namePtr)
{
*namePtr = 0;
}
for(namePtr = tmpName; *namePtr != 0 && *namePtr == ' ';
++namePtr);
// get value part of token (ensure value length is at least 0 in
// case bad parsing because of no equals sign after name)
size_t valueLength = strlen(token);
valueLength = (nameLength == valueLength ?
0 : valueLength - nameLength - 1);
char tmpValue[valueLength + 1];
if(valueLength > 0)
{
strncpy(tmpValue, token + nameLength + 1, valueLength);
}
tmpValue[valueLength] = 0;
if(origin == Client)
{
// set cookie
setCookie(namePtr, tmpValue, 0, false, false);
}
else
{
if(name)
{
// first token *must* be cookie name = cookie value
cookie = Cookie();
cookie["name"] = namePtr;
cookie["value"] = tmpValue;
name = false;
}
else
{
if(strcmp(namePtr, "expires") == 0)
{
// parse expiration time
if(d.parse(tmpValue, HttpHeader::sDateFormat, &gmt))
{
int64_t age = d.getSeconds() - now.getSeconds();
cookie["maxAge"] = (age <= 0 ? 0 : age);
}
else
{
// bad date format, use maxAge of 0
cookie["maxAge"] = 0;
}
}
else if(strcasecmp(namePtr, "secure") == 0)
{
// cookie is secure
cookie["secure"] = true;
}
else if(strcasecmp(namePtr, "HttpOnly") == 0)
{
// cookie is http-only (non-javascript)
cookie["httpOnly"] = true;
}
else
//.........这里部分代码省略.........