本文整理汇总了C++中StringBuilder类的典型用法代码示例。如果您正苦于以下问题:C++ StringBuilder类的具体用法?C++ StringBuilder怎么用?C++ StringBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: print
void MemberExpr::print(StringBuilder& buffer, unsigned indent) const {
buffer.indent(indent);
buffer.setColor(COL_EXPR);
buffer << "MemberExpr";
buffer.setColor(COL_ATTR);
if (isModulePrefix()) buffer << " mod-prefix";
buffer << ' ';
Expr::print(buffer, 0);
buffer << '\n';
buffer.indent(indent + INDENT);
buffer.setColor(COL_ATTR);
buffer << "LHS=\n";
Base->print(buffer, indent + INDENT);
buffer.indent(indent + INDENT);
buffer.setColor(COL_ATTR);
buffer << "RHS=";
buffer.setColor(COL_VALUE);
buffer << member << '\n';
buffer.indent(indent);
buffer.setColor(COL_ATTR);
buffer << "decl=";
if (decl) {
buffer << decl->getName();
} else {
buffer.setColor(ANSI_RED);
buffer << "NULL";
}
buffer << '\n';
}
示例2: CFAttributedStringGetString
void InbandTextTrackPrivateAVF::processCueAttributes(CFAttributedStringRef attributedString, GenericCueData* cueData)
{
// Some of the attributes we translate into per-cue WebVTT settings are are repeated on each part of an attributed string so only
// process the first instance of each.
enum AttributeFlags {
Line = 1 << 0,
Position = 1 << 1,
Size = 1 << 2,
Vertical = 1 << 3,
Align = 1 << 4,
FontName = 1 << 5
};
unsigned processed = 0;
StringBuilder content;
String attributedStringValue = CFAttributedStringGetString(attributedString);
CFIndex length = attributedStringValue.length();
if (!length)
return;
CFRange effectiveRange = CFRangeMake(0, 0);
while ((effectiveRange.location + effectiveRange.length) < length) {
CFDictionaryRef attributes = CFAttributedStringGetAttributes(attributedString, effectiveRange.location + effectiveRange.length, &effectiveRange);
if (!attributes)
continue;
StringBuilder tagStart;
CFStringRef valueString;
String tagEnd;
CFIndex attributeCount = CFDictionaryGetCount(attributes);
Vector<const void*> keys(attributeCount);
Vector<const void*> values(attributeCount);
CFDictionaryGetKeysAndValues(attributes, keys.data(), values.data());
for (CFIndex i = 0; i < attributeCount; ++i) {
CFStringRef key = static_cast<CFStringRef>(keys[i]);
CFTypeRef value = values[i];
if (CFGetTypeID(key) != CFStringGetTypeID() || !CFStringGetLength(key))
continue;
if (CFStringCompare(key, kCMTextMarkupAttribute_Alignment, 0) == kCFCompareEqualTo) {
valueString = static_cast<CFStringRef>(value);
if (CFGetTypeID(valueString) != CFStringGetTypeID() || !CFStringGetLength(valueString))
continue;
if (processed & Align)
continue;
processed |= Align;
if (CFStringCompare(valueString, kCMTextMarkupAlignmentType_Start, 0) == kCFCompareEqualTo)
cueData->setAlign(GenericCueData::Start);
else if (CFStringCompare(valueString, kCMTextMarkupAlignmentType_Middle, 0) == kCFCompareEqualTo)
cueData->setAlign(GenericCueData::Middle);
else if (CFStringCompare(valueString, kCMTextMarkupAlignmentType_End, 0) == kCFCompareEqualTo)
cueData->setAlign(GenericCueData::End);
else
ASSERT_NOT_REACHED();
continue;
}
if (CFStringCompare(key, kCMTextMarkupAttribute_BoldStyle, 0) == kCFCompareEqualTo) {
if (static_cast<CFBooleanRef>(value) != kCFBooleanTrue)
continue;
tagStart.append("<b>");
tagEnd.insert("</b>", 0);
continue;
}
if (CFStringCompare(key, kCMTextMarkupAttribute_ItalicStyle, 0) == kCFCompareEqualTo) {
if (static_cast<CFBooleanRef>(value) != kCFBooleanTrue)
continue;
tagStart.append("<i>");
tagEnd.insert("</i>", 0);
continue;
}
if (CFStringCompare(key, kCMTextMarkupAttribute_UnderlineStyle, 0) == kCFCompareEqualTo) {
if (static_cast<CFBooleanRef>(value) != kCFBooleanTrue)
continue;
tagStart.append("<u>");
tagEnd.insert("</u>", 0);
continue;
}
if (CFStringCompare(key, kCMTextMarkupAttribute_OrthogonalLinePositionPercentageRelativeToWritingDirection, 0) == kCFCompareEqualTo) {
if (CFGetTypeID(value) != CFNumberGetTypeID())
continue;
if (processed & Line)
continue;
processed |= Line;
CFNumberRef valueNumber = static_cast<CFNumberRef>(value);
double line;
CFNumberGetValue(valueNumber, kCFNumberFloat64Type, &line);
cueData->setLine(line);
continue;
//.........这里部分代码省略.........
示例3: toString
String ParsedCookie::toString() const
{
StringBuilder builder;
builder.append(name());
builder.append(" = ");
builder.append(value());
builder.append("; Domain = ");
builder.append(domain());
builder.append("; Path = ");
builder.append(path());
builder.append("; Protocol = ");
builder.append(protocol());
return builder.toString();
}
示例4: _getExtent
Status RecordStoreV1Base::validate( OperationContext* txn,
bool full, bool scanData,
ValidateAdaptor* adaptor,
ValidateResults* results, BSONObjBuilder* output ) const {
// 1) basic status that require no iteration
// 2) extent level info
// 3) check extent start and end
// 4) check each non-deleted record
// 5) check deleted list
// -------------
// 1111111111111111111
if ( isCapped() ){
output->appendBool("capped", true);
output->appendNumber("max", _details->maxCappedDocs());
}
output->appendNumber("datasize", _details->dataSize());
output->appendNumber("nrecords", _details->numRecords());
output->appendNumber("lastExtentSize", _details->lastExtentSize(txn));
output->appendNumber("padding", _details->paddingFactor());
if ( _details->firstExtent(txn).isNull() )
output->append( "firstExtent", "null" );
else
output->append( "firstExtent",
str::stream() << _details->firstExtent(txn).toString()
<< " ns:"
<< _getExtent( txn, _details->firstExtent(txn) )->nsDiagnostic.toString());
if ( _details->lastExtent(txn).isNull() )
output->append( "lastExtent", "null" );
else
output->append( "lastExtent", str::stream() << _details->lastExtent(txn).toString()
<< " ns:"
<< _getExtent( txn, _details->lastExtent(txn) )->nsDiagnostic.toString());
// 22222222222222222222222222
{ // validate extent basics
BSONArrayBuilder extentData;
int extentCount = 0;
DiskLoc extentDiskLoc;
try {
if ( !_details->firstExtent(txn).isNull() ) {
_getExtent( txn, _details->firstExtent(txn) )->assertOk();
_getExtent( txn, _details->lastExtent(txn) )->assertOk();
}
extentDiskLoc = _details->firstExtent(txn);
while (!extentDiskLoc.isNull()) {
Extent* thisExtent = _getExtent( txn, extentDiskLoc );
if (full) {
extentData << thisExtent->dump();
}
if (!thisExtent->validates(extentDiskLoc, &results->errors)) {
results->valid = false;
}
DiskLoc nextDiskLoc = thisExtent->xnext;
if (extentCount > 0 && !nextDiskLoc.isNull()
&& _getExtent( txn, nextDiskLoc )->xprev != extentDiskLoc) {
StringBuilder sb;
sb << "'xprev' pointer " << _getExtent( txn, nextDiskLoc )->xprev.toString()
<< " in extent " << nextDiskLoc.toString()
<< " does not point to extent " << extentDiskLoc.toString();
results->errors.push_back( sb.str() );
results->valid = false;
}
if (nextDiskLoc.isNull() && extentDiskLoc != _details->lastExtent(txn)) {
StringBuilder sb;
sb << "'lastExtent' pointer " << _details->lastExtent(txn).toString()
<< " does not point to last extent in list " << extentDiskLoc.toString();
results->errors.push_back( sb.str() );
results->valid = false;
}
extentDiskLoc = nextDiskLoc;
extentCount++;
txn->checkForInterrupt();
}
}
catch (const DBException& e) {
StringBuilder sb;
sb << "exception validating extent " << extentCount
<< ": " << e.what();
results->errors.push_back( sb.str() );
results->valid = false;
return Status::OK();
}
output->append("extentCount", extentCount);
if ( full )
output->appendArray( "extents" , extentData.arr() );
}
try {
// 333333333333333333333333333
bool testingLastExtent = false;
try {
//.........这里部分代码省略.........
示例5: appendFloat
static void appendFloat(StringBuilder& stringBuilder, float value)
{
stringBuilder.append(' ');
stringBuilder.appendNumber(value);
}
示例6: edit
static void edit(const string& var){
static const char * editor = getenv("EDITOR");
if (!editor) {
cout << "please define the EDITOR environment variable" << endl;
return;
}
for (const char* p=var.data(); *p ; p++){
if (! (isalnum(*p) || *p == '_' || *p == '.')){
cout << "can only edit variable or property" << endl;
return;
}
}
if (!shellMainScope->exec("__jsout__ = tojson("+var+")", "tojs", false, false, false))
return; // Error already printed
const string js = shellMainScope->getString("__jsout__");
if (strstr(js.c_str(), "[native code]")) {
cout << "Can't edit native functions" << endl;
return;
}
string filename;
int fd;
for (int i=0; i < 10; i++){
StringBuilder sb;
sb << "/tmp/mongo_edit" << time(0)+i << ".js";
filename = sb.str();
fd = open(filename.c_str(), O_RDWR|O_CREAT|O_EXCL, 0600);
if (fd > 0)
break;
if (errno != EEXIST) {
cout << "couldn't open temp file: " << errnoWithDescription() << endl;
return;
}
}
if (fd == -1){
cout << "couldn't create unique temp file after 10 attempts" << endl;
return;
}
// just to make sure this gets closed no matter what
File holder;
holder.fd = fd;
if (write(fd, js.data(), js.size()) != (int)js.size()){
cout << "failed to write to temp file: " << errnoWithDescription() << endl;
return;
}
StringBuilder sb;
sb << editor << " " << filename;
int ret = ::system(sb.str().c_str());
int systemErrno = errno;
remove(filename.c_str()); // file already open, deleted on close
if (ret){
if (ret == -1) {
cout << "failed to launch $EDITOR (" << editor << "): " << errnoWithDescription(systemErrno) << endl;
return;
}
cout << "editor exited with error, not applying changes" << endl;
return;
}
lseek(fd, 0, SEEK_SET);
sb.reset();
sb << var << " = ";
int bytes;
do {
char buf[1024];
bytes = read(fd, buf, sizeof(buf));
if (bytes < 0) {
cout << "failed to read temp file: " << errnoWithDescription() << endl;
return;
}
sb.append( StringData(buf, bytes) );
}while (bytes);
const string code = sb.str();
if (!shellMainScope->exec(code, "tojs", false, false, false))
return; // Error already printed
}
示例7: asJSON
void Entry::asJSON(StringBuilder& json, const Storage::RecordInfo& info) const
{
json.appendLiteral("{\n");
json.appendLiteral("\"hash\": ");
json.appendQuotedJSONString(m_key.hashAsString());
json.appendLiteral(",\n");
json.appendLiteral("\"bodySize\": ");
json.appendNumber(info.bodySize);
json.appendLiteral(",\n");
json.appendLiteral("\"worth\": ");
json.appendNumber(info.worth);
json.appendLiteral(",\n");
json.appendLiteral("\"partition\": ");
json.appendQuotedJSONString(m_key.partition());
json.appendLiteral(",\n");
json.appendLiteral("\"timestamp\": ");
json.appendNumber(std::chrono::duration_cast<std::chrono::milliseconds>(m_timeStamp.time_since_epoch()).count());
json.appendLiteral(",\n");
json.appendLiteral("\"URL\": ");
json.appendQuotedJSONString(m_response.url().string());
json.appendLiteral(",\n");
json.appendLiteral("\"bodyHash\": ");
json.appendQuotedJSONString(info.bodyHash);
json.appendLiteral(",\n");
json.appendLiteral("\"bodyShareCount\": ");
json.appendNumber(info.bodyShareCount);
json.appendLiteral(",\n");
json.appendLiteral("\"headers\": {\n");
bool firstHeader = true;
for (auto& header : m_response.httpHeaderFields()) {
if (!firstHeader)
json.appendLiteral(",\n");
firstHeader = false;
json.appendLiteral(" ");
json.appendQuotedJSONString(header.key);
json.appendLiteral(": ");
json.appendQuotedJSONString(header.value);
}
json.appendLiteral("\n}\n");
json.appendLiteral("}");
}
示例8: parse
bool DateTimeFormat::parse(const String& source, TokenHandler& tokenHandler)
{
enum State {
StateInQuote,
StateInQuoteQuote,
StateLiteral,
StateQuote,
StateSymbol,
} state = StateLiteral;
FieldType fieldType = FieldTypeLiteral;
StringBuilder literalBuffer;
int fieldCounter = 0;
for (unsigned index = 0; index < source.length(); ++index) {
const UChar ch = source[index];
switch (state) {
case StateInQuote:
if (ch == '\'') {
state = StateInQuoteQuote;
break;
}
literalBuffer.append(ch);
break;
case StateInQuoteQuote:
if (ch == '\'') {
literalBuffer.append('\'');
state = StateInQuote;
break;
}
fieldType = mapCharacterToFieldType(ch);
if (fieldType == FieldTypeInvalid)
return false;
if (fieldType == FieldTypeLiteral) {
literalBuffer.append(ch);
state = StateLiteral;
break;
}
if (literalBuffer.length()) {
tokenHandler.visitLiteral(literalBuffer.toString());
literalBuffer.clear();
}
fieldCounter = 1;
state = StateSymbol;
break;
case StateLiteral:
if (ch == '\'') {
state = StateQuote;
break;
}
fieldType = mapCharacterToFieldType(ch);
if (fieldType == FieldTypeInvalid)
return false;
if (fieldType == FieldTypeLiteral) {
literalBuffer.append(ch);
break;
}
if (literalBuffer.length()) {
tokenHandler.visitLiteral(literalBuffer.toString());
literalBuffer.clear();
}
fieldCounter = 1;
state = StateSymbol;
break;
case StateQuote:
literalBuffer.append(ch);
state = ch == '\'' ? StateLiteral : StateInQuote;
break;
case StateSymbol: {
ASSERT(fieldType != FieldTypeInvalid);
ASSERT(fieldType != FieldTypeLiteral);
ASSERT(literalBuffer.isEmpty());
FieldType fieldType2 = mapCharacterToFieldType(ch);
if (fieldType2 == FieldTypeInvalid)
return false;
if (fieldType == fieldType2) {
++fieldCounter;
break;
}
tokenHandler.visitField(fieldType, fieldCounter);
if (fieldType2 == FieldTypeLiteral) {
if (ch == '\'') {
state = StateQuote;
//.........这里部分代码省略.........
示例9: getBoundAddrs
//.........这里部分代码省略.........
}
}
#elif defined(_WIN32)
// Start with the MS recommended 15KB buffer. Use multiple attempts
// for the rare case that the adapter config changes between calls
ULONG adaptersLen = 15 * 1024;
boost::scoped_array<char> buf(new char[adaptersLen]);
IP_ADAPTER_ADDRESSES* adapters = reinterpret_cast<IP_ADAPTER_ADDRESSES*>(buf.get());
DWORD err;
ULONG family = ipv6enabled ? AF_UNSPEC : AF_INET;
for (int tries = 0; tries < 3; ++tries) {
err = GetAdaptersAddresses(family,
GAA_FLAG_SKIP_ANYCAST | // only want unicast addrs
GAA_FLAG_SKIP_MULTICAST |
GAA_FLAG_SKIP_DNS_SERVER,
NULL,
adapters,
&adaptersLen);
if (err == ERROR_BUFFER_OVERFLOW) {
// in this case, adaptersLen will be set to the size we need to allocate
buf.reset(new char[adaptersLen]);
adapters = reinterpret_cast<IP_ADAPTER_ADDRESSES*>(buf.get());
}
else {
break; // only retry for incorrectly sized buffer
}
}
if (err != NO_ERROR) {
warning() << "GetAdaptersAddresses() failed: " << errnoWithDescription(err)
<< std::endl;
return out;
}
for (IP_ADAPTER_ADDRESSES* adapter = adapters;
adapter != NULL; adapter = adapter->Next) {
for (IP_ADAPTER_UNICAST_ADDRESS* addr = adapter->FirstUnicastAddress;
addr != NULL; addr = addr->Next) {
short family =
reinterpret_cast<SOCKADDR_STORAGE*>(addr->Address.lpSockaddr)->ss_family;
if (family == AF_INET) {
// IPv4
SOCKADDR_IN* sock = reinterpret_cast<SOCKADDR_IN*>(addr->Address.lpSockaddr);
char addrstr[INET_ADDRSTRLEN] = {0};
boost::system::error_code ec;
// Not all windows versions have inet_ntop
boost::asio::detail::socket_ops::inet_ntop(AF_INET,
&(sock->sin_addr),
addrstr,
INET_ADDRSTRLEN,
0,
ec);
if (ec) {
warning() << "inet_ntop failed during IPv4 address conversion: "
<< ec.message() << std::endl;
continue;
}
out.push_back(addrstr);
}
else if (family == AF_INET6) {
// IPv6
SOCKADDR_IN6* sock = reinterpret_cast<SOCKADDR_IN6*>(addr->Address.lpSockaddr);
char addrstr[INET6_ADDRSTRLEN] = {0};
boost::system::error_code ec;
boost::asio::detail::socket_ops::inet_ntop(AF_INET6,
&(sock->sin6_addr),
addrstr,
INET6_ADDRSTRLEN,
0,
ec);
if (ec) {
warning() << "inet_ntop failed during IPv6 address conversion: "
<< ec.message() << std::endl;
continue;
}
out.push_back(addrstr);
}
}
}
#endif // defined(_WIN32)
if (shouldLog(logger::LogSeverity::Debug(2))) {
StringBuilder builder;
builder << "getBoundAddrs():";
for (std::vector<std::string>::const_iterator o = out.begin(); o != out.end(); ++o) {
builder << " [ " << *o << "]";
}
LOG(2) << builder.str();
}
return out;
}
示例10: makeRFC2822DateString
// See http://tools.ietf.org/html/rfc2822#section-3.3 for more information.
String makeRFC2822DateString(unsigned dayOfWeek, unsigned day, unsigned month, unsigned year, unsigned hours, unsigned minutes, unsigned seconds, int utcOffset)
{
StringBuilder stringBuilder;
stringBuilder.append(weekdayName[dayOfWeek]);
stringBuilder.appendLiteral(", ");
stringBuilder.appendNumber(day);
stringBuilder.append(' ');
stringBuilder.append(monthName[month]);
stringBuilder.append(' ');
stringBuilder.appendNumber(year);
stringBuilder.append(' ');
appendTwoDigitNumber(stringBuilder, hours);
stringBuilder.append(':');
appendTwoDigitNumber(stringBuilder, minutes);
stringBuilder.append(':');
appendTwoDigitNumber(stringBuilder, seconds);
stringBuilder.append(' ');
stringBuilder.append(utcOffset > 0 ? '+' : '-');
int absoluteUTCOffset = abs(utcOffset);
appendTwoDigitNumber(stringBuilder, absoluteUTCOffset / 60);
appendTwoDigitNumber(stringBuilder, absoluteUTCOffset % 60);
return stringBuilder.toString();
}
示例11: toString
string ChunkRange::toString() const {
StringBuilder sb;
sb << "ChunkRange(min=" << _min << ", max=" << _max << ", shard=" << _shardId << ")";
return sb.str();
}
示例12: addGlobalOptions
void CmdLine::addGlobalOptions( boost::program_options::options_description& general ,
boost::program_options::options_description& hidden ,
boost::program_options::options_description& ssl_options ) {
/* support for -vv -vvvv etc. */
for (string s = "vv"; s.length() <= 12; s.append("v")) {
hidden.add_options()(s.c_str(), "verbose");
}
StringBuilder portInfoBuilder;
StringBuilder maxConnInfoBuilder;
portInfoBuilder << "specify port number - " << DefaultDBPort << " by default";
maxConnInfoBuilder << "max number of simultaneous connections - " << DEFAULT_MAX_CONN << " by default";
general.add_options()
("help,h", "show this usage information")
("version", "show version information")
("config,f", po::value<string>(), "configuration file specifying additional options")
("verbose,v", "be more verbose (include multiple times for more verbosity e.g. -vvvvv)")
("quiet", "quieter output")
("port", po::value<int>(&cmdLine.port), portInfoBuilder.str().c_str())
("bind_ip", po::value<string>(&cmdLine.bind_ip), "comma separated list of ip addresses to listen on - all local ips by default")
("maxConns",po::value<int>(), maxConnInfoBuilder.str().c_str())
("logpath", po::value<string>() , "log file to send write to instead of stdout - has to be a file, not directory" )
("logappend" , "append to logpath instead of over-writing" )
("pidfilepath", po::value<string>(), "full path to pidfile (if not set, no pidfile is created)")
("keyFile", po::value<string>(), "private key for cluster authentication")
("setParameter", po::value< std::vector<std::string> >()->composing(),
"Set a configurable parameter")
#ifndef _WIN32
("nounixsocket", "disable listening on unix sockets")
("unixSocketPrefix", po::value<string>(), "alternative directory for UNIX domain sockets (defaults to /tmp)")
("fork" , "fork server process" )
("syslog" , "log to system's syslog facility instead of file or stdout" )
#endif
;
#ifdef MONGO_SSL
ssl_options.add_options()
("sslOnNormalPorts" , "use ssl on configured ports" )
("sslPEMKeyFile" , po::value<string>(&cmdLine.sslPEMKeyFile), "PEM file for ssl" )
("sslPEMKeyPassword" , new PasswordValue(&cmdLine.sslPEMKeyPassword) , "PEM file password" )
("sslCAFile", po::value<std::string>(&cmdLine.sslCAFile),
"Certificate Authority file for SSL")
("sslCRLFile", po::value<std::string>(&cmdLine.sslCRLFile),
"Certificate Revocation List file for SSL")
("sslWeakCertificateValidation", "allow client to connect without presenting a certificate")
#endif
;
// Extra hidden options
hidden.add_options()
("objcheck", "inspect client data for validity on receipt (DEFAULT)")
("noobjcheck", "do NOT inspect client data for validity on receipt")
("traceExceptions", "log stack traces for every exception")
("enableExperimentalIndexStatsCmd", po::bool_switch(&cmdLine.experimental.indexStatsCmdEnabled),
"EXPERIMENTAL (UNSUPPORTED). Enable command computing aggregate statistics on indexes.")
("enableExperimentalStorageDetailsCmd", po::bool_switch(&cmdLine.experimental.storageDetailsCmdEnabled),
"EXPERIMENTAL (UNSUPPORTED). Enable command computing aggregate statistics on storage.")
;
}
示例13: buildEllipseString
static String buildEllipseString(const String& radiusX, const String& radiusY, const String& centerX, const String& centerY, const String& box)
{
char opening[] = "ellipse(";
char at[] = "at";
char separator[] = " ";
StringBuilder result;
result.appendLiteral(opening);
bool needsSeparator = false;
if (!radiusX.isNull()) {
result.append(radiusX);
needsSeparator = true;
}
if (!radiusY.isNull()) {
if (needsSeparator)
result.appendLiteral(separator);
result.append(radiusY);
needsSeparator = true;
}
if (!centerX.isNull() || !centerY.isNull()) {
if (needsSeparator)
result.appendLiteral(separator);
result.appendLiteral(at);
result.appendLiteral(separator);
result.append(centerX);
result.appendLiteral(separator);
result.append(centerY);
}
result.appendLiteral(")");
if (box.length()) {
result.appendLiteral(separator);
result.append(box);
}
return result.toString();
}
示例14: clientHandshakeMessage
CString WebSocketHandshake::clientHandshakeMessage() const
{
// Keep the following consistent with clientHandshakeRequest().
StringBuilder builder;
builder.append("GET ");
builder.append(resourceName(m_url));
builder.append(" HTTP/1.1\r\n");
builder.append("Upgrade: WebSocket\r\n");
builder.append("Connection: Upgrade\r\n");
builder.append("Host: ");
builder.append(m_url.host().lower());
if (m_url.port() && ((!m_secure && m_url.port() != 80) || (m_secure && m_url.port() != 443))) {
builder.append(":");
builder.append(String::number(m_url.port()));
}
builder.append("\r\n");
builder.append("Origin: ");
builder.append(clientOrigin());
builder.append("\r\n");
if (!m_clientProtocol.isEmpty()) {
builder.append("WebSocket-Protocol: ");
builder.append(m_clientProtocol);
builder.append("\r\n");
}
KURL url = httpURLForAuthenticationAndCookies();
if (m_context->isDocument()) {
Document* document = static_cast<Document*>(m_context);
String cookie = cookieRequestHeaderFieldValue(document, url);
if (!cookie.isEmpty()) {
builder.append("Cookie: ");
builder.append(cookie);
builder.append("\r\n");
}
// Set "Cookie2: <cookie>" if cookies 2 exists for url?
}
builder.append("\r\n");
return builder.toString().utf8();
}
示例15: buildPolygonString
static String buildPolygonString(const WindRule& windRule, const Vector<String>& points, const String& box)
{
ASSERT(!(points.size() % 2));
StringBuilder result;
char evenOddOpening[] = "polygon(evenodd, ";
char nonZeroOpening[] = "polygon(";
char commaSeparator[] = ", ";
COMPILE_ASSERT(sizeof(evenOddOpening) >= sizeof(nonZeroOpening), polygon_evenodd_is_longest_string_opening);
// Compute the required capacity in advance to reduce allocations.
size_t length = sizeof(evenOddOpening) - 1;
for (size_t i = 0; i < points.size(); i += 2) {
if (i)
length += (sizeof(commaSeparator) - 1);
// add length of two strings, plus one for the space separator.
length += points[i].length() + 1 + points[i + 1].length();
}
if (box.length())
length += box.length() + 1;
result.reserveCapacity(length);
if (windRule == RULE_EVENODD)
result.appendLiteral(evenOddOpening);
else
result.appendLiteral(nonZeroOpening);
for (size_t i = 0; i < points.size(); i += 2) {
if (i)
result.appendLiteral(commaSeparator);
result.append(points[i]);
result.append(' ');
result.append(points[i + 1]);
}
result.append(')');
if (box.length()) {
result.append(' ');
result.append(box);
}
return result.toString();
}