本文整理汇总了C++中StringBuffer::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ StringBuffer::empty方法的具体用法?C++ StringBuffer::empty怎么用?C++ StringBuffer::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuffer
的用法示例。
在下文中一共展示了StringBuffer::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
static bool
EscapeNakedForwardSlashes(StringBuffer &sb, const CharT *oldChars, size_t oldLen)
{
for (const CharT *it = oldChars; it < oldChars + oldLen; ++it) {
if (*it == '/' && (it == oldChars || it[-1] != '\\')) {
/* There's a forward slash that needs escaping. */
if (sb.empty()) {
/* This is the first one we've seen, copy everything up to this point. */
if (mozilla::IsSame<CharT, jschar>::value && !sb.ensureTwoByteChars())
return false;
if (!sb.reserve(oldLen + 1))
return false;
sb.infallibleAppend(oldChars, size_t(it - oldChars));
}
if (!sb.append('\\'))
return false;
}
if (!sb.empty() && !sb.append(*it))
return false;
}
return true;
}
示例2: testEmpty
//////////////////////////////////////////////////////// Test /////
// Test null() and empty() behavior
void testEmpty() {
StringBuffer s;
CPPUNIT_ASSERT(s.empty());
CPPUNIT_ASSERT(s.null());
s = "";
CPPUNIT_ASSERT( s.empty() );
CPPUNIT_ASSERT( !s.null() );
}
示例3: if
static bool
EscapeRegExpPattern(StringBuffer& sb, const CharT* oldChars, size_t oldLen)
{
bool inBrackets = false;
bool previousCharacterWasBackslash = false;
for (const CharT* it = oldChars; it < oldChars + oldLen; ++it) {
CharT ch = *it;
if (!previousCharacterWasBackslash) {
if (inBrackets) {
if (ch == ']')
inBrackets = false;
} else if (ch == '/') {
// There's a forward slash that needs escaping.
if (sb.empty()) {
// This is the first char we've seen that needs escaping,
// copy everything up to this point.
if (!SetupBuffer(sb, oldChars, oldLen, it))
return false;
}
if (!sb.append('\\'))
return false;
} else if (ch == '[') {
inBrackets = true;
}
}
if (IsLineTerminator(ch)) {
// There's LineTerminator that needs escaping.
if (sb.empty()) {
// This is the first char we've seen that needs escaping,
// copy everything up to this point.
if (!SetupBuffer(sb, oldChars, oldLen, it))
return false;
}
if (!previousCharacterWasBackslash) {
if (!sb.append('\\'))
return false;
}
if (!AppendEscapedLineTerminator(sb, ch))
return false;
} else if (!sb.empty()) {
if (!sb.append(ch))
return false;
}
if (previousCharacterWasBackslash)
previousCharacterWasBackslash = false;
else if (ch == '\\')
previousCharacterWasBackslash = true;
}
return true;
}
示例4: if
void
calculateRuleForName(
const Configuration * cfg,
const char * name,
const char * uName,
const StringVector & wildcardedNamesAndTypes,
StringBuffer & rule)
{
int i;
int len;
const char * str;
const char * keyword;
const char * wildcardedName;
const char * type;
rule.empty();
len = wildcardedNamesAndTypes.length();
for (i = 0; i < len; i+=3) {
keyword = wildcardedNamesAndTypes[i+0]; // @optional or @required
wildcardedName = wildcardedNamesAndTypes[i+1];
type = wildcardedNamesAndTypes[i+2];
if (Configuration::patternMatch(uName, wildcardedName)) {
rule << keyword << " " << uName << " = " << type;
return;
}
}
//--------
// We couldn's determine the type from the wildcarded_names_and_types
// table. So we fall back to using heuristics to guess a good type.
//--------
if (cfg->type("", name) == Configuration::CFG_SCOPE) {
rule << uName << " = scope";
} else if (cfg->type("", name) == Configuration::CFG_LIST) {
rule << uName << " = list[string]";
} else {
str = cfg->lookupString("", name);
if (cfg->isBoolean(str)) {
rule << uName << " = boolean";
} else if (cfg->isInt(str)) {
rule << uName << " = int";
} else if (cfg->isFloat(str)) {
rule << uName << " = float";
} else if (cfg->isDurationSeconds(str)) {
rule << uName << " = durationSeconds";
} else if (cfg->isDurationMilliseconds(str)) {
rule << uName << " = durationMilliseconds";
} else if (cfg->isDurationMicroseconds(str)) {
rule << uName << " = durationMicroseconds";
} else if (cfg->isMemorySizeBytes(str)) {
rule << uName << " = memorySizeBytes";
} else if (cfg->isMemorySizeKB(str)) {
rule << uName << " = memorySizeKB";
} else if (cfg->isMemorySizeMB(str)) {
rule << uName << " = memorySizeMB";
} else {
rule << uName << " = string";
}
}
}
示例5: setExportedServicesFromString
void MHSyncItemInfo::setExportedServicesFromString(const char* servicesList)
{
StringBuffer services(servicesList);
if (services.empty() == false) {
ArrayList servicesParam;
int servicesNum = 0;
services.split(servicesParam, ",");
servicesNum = servicesParam.size();
for (int i = 0; i < servicesNum; i++) {
StringBuffer* serviceParamStr = static_cast<StringBuffer *>(servicesParam.get(i));
if ((serviceParamStr) && (serviceParamStr->empty() == false)) {
ArrayList serviceParam;
serviceParamStr->split(serviceParam, ":");
if (serviceParam.size() == 2) {
StringBuffer* serviceName = static_cast<StringBuffer *>(serviceParam.get(0));
StringBuffer* serviceExportTime = static_cast<StringBuffer *>(serviceParam.get(1));
exportedServices.put(serviceName->c_str(), serviceExportTime->c_str());
}
}
}
}
}
示例6: formatExportedServices
StringBuffer MHSyncItemInfo::formatExportedServices()
{
StringBuffer formattedExportedServices("");
KeyValuePair kvp = exportedServices.front();
while (kvp.null() == false) {
StringBuffer serviceName = kvp.getKey();
StringBuffer serviceExportTime = kvp.getValue();
if (serviceName.empty() == false) {
StringBuffer formattedService;
formattedService.sprintf("%s:%s", serviceName.c_str(),
serviceExportTime.c_str());
if (formattedExportedServices.empty() == false) {
formattedExportedServices.append(",");
}
formattedExportedServices.append(formattedService.c_str());
}
kvp = exportedServices.next();
}
return formattedExportedServices;
}
示例7: testRemoveProperty
void testRemoveProperty() {
// Write a value into the property file
propFile->setPropertyValue("property4", "value4");
propFile->setPropertyValue(" space ", " val space ");
propFile->close();
// Remove it
int success = propFile->removeProperty("property4");
CPPUNIT_ASSERT(success == 0);
// Now read back
StringBuffer value = propFile->readPropertyValue("property4");
CPPUNIT_ASSERT(value.empty());
StringBuffer valueS = propFile->readPropertyValue("space");
CPPUNIT_ASSERT(value.empty());
}
示例8: url_encode_array
static void url_encode_array(StringBuffer &ret, CVarRef varr,
std::set<void*> &seen_arrs,
CStrRef num_prefix, CStrRef key_prefix,
CStrRef key_suffix, CStrRef arg_sep) {
void *id = varr.is(KindOfArray) ?
(void*)varr.getArrayData() : (void*)varr.getObjectData();
if (!seen_arrs.insert(id).second) {
return; // recursive
}
Array arr = varr.toArray();
for (ArrayIter iter(arr); iter; ++iter) {
Variant data = iter.second();
if (data.isNull() || data.isResource()) continue;
String key = iter.first();
bool numeric = key.isNumeric();
if (data.is(KindOfArray) || data.is(KindOfObject)) {
String encoded;
if (numeric) {
encoded = key;
} else {
encoded = StringUtil::UrlEncode(key);
}
StringBuffer new_prefix(key_prefix.size() + num_prefix.size() +
encoded.size() + key_suffix.size() + 4);
new_prefix += key_prefix;
if (numeric) new_prefix += num_prefix;
new_prefix += encoded;
new_prefix += key_suffix;
new_prefix += "%5B";
url_encode_array(ret, data, seen_arrs, String(),
new_prefix.detach(), String("%5D", AttachLiteral),
arg_sep);
} else {
if (!ret.empty()) {
ret += arg_sep;
}
ret += key_prefix;
if (numeric) {
ret += num_prefix;
ret += key;
} else {
ret += StringUtil::UrlEncode(key);
}
ret += key_suffix;
ret += "=";
if (data.isInteger() || data.is(KindOfBoolean)) {
ret += String(data.toInt64());
} else if (data.is(KindOfDouble)) {
ret += String(data.toDouble());
} else {
ret += StringUtil::UrlEncode(data.toString());
}
}
}
}
示例9: flush
void flush()
{
if(!m_buffer.empty())
{
m_tool.push_back(new VariableString(m_buffer.c_str()));
m_buffer.clear();
}
}
示例10: append_line_no
static void append_line_no(StringBuffer &sb, const char *text,
int &line, const char *color, const char *end,
int lineFocus0, int charFocus0, int lineFocus1,
int charFocus1, const char **palette =
DebuggerClient::DefaultCodeColors) {
TRACE(7, "debugger_base:append_line_no\n");
const char *colorLineNo = palette[CodeColorLineNo * 2];
const char *endLineNo = palette[CodeColorLineNo * 2 + 1];
// beginning
if (line && sb.empty()) {
if (colorLineNo) color_line_no(sb, line, lineFocus0, lineFocus1,
colorLineNo);
sb.printf(DebuggerClient::LineNoFormat, line);
if (endLineNo) sb.append(endLineNo);
}
// ending
if (text == nullptr) {
if (line) {
if (colorLineNo) color_line_no(sb, line, lineFocus0, lineFocus1,
colorLineNo);
sb.append("(END)\n");
if (endLineNo) sb.append(endLineNo);
}
return;
}
if (color) sb.append(color);
if (line == 0) {
sb.append(text);
} else {
const char *begin = text;
const char *p = begin;
for (; *p; p++) {
if (*p == '\n') {
++line;
sb.append(begin, p - begin);
if (color) sb.append(ANSI_COLOR_END);
sb.append('\n');
if (colorLineNo) color_line_no(sb, line, lineFocus0, lineFocus1,
colorLineNo);
sb.printf(DebuggerClient::LineNoFormat, line);
if (endLineNo) sb.append(endLineNo);
if (color) sb.append(color);
begin = p + 1;
}
}
if (p - begin > 0) {
sb.append(begin, p - begin);
}
}
if (end) sb.append(end);
}
示例11: upload
int HttpUploader::upload(const StringBuffer& luid, InputStream* inputStream)
{
int status = 0;
// safe checks
if (!inputStream || !inputStream->getTotalSize()) {
LOG.error("upload error: no data to transfer");
return 1;
}
if (luid.empty() || syncUrl.empty() || sourceURI.empty()) {
LOG.error("upload error: some params are not set");
return 2;
}
StringBuffer fullUrl = composeURL();
URL url(fullUrl.c_str());
HttpConnection* httpConnection = getHttpConnection();
httpConnection->setCompression(false);
status = httpConnection->open(url, HttpConnection::MethodPost);
if (status) {
delete httpConnection;
return status;
}
httpConnection->setKeepAlive(keepalive);
httpConnection->setRequestChunkSize(maxRequestChunkSize);
// Set headers (use basic auth)
HttpAuthentication* auth = new BasicAuthentication(username, password);
httpConnection->setAuthentication(auth);
setRequestHeaders(luid, *httpConnection, *inputStream);
// Send the HTTP request
StringOutputStream response;
status = httpConnection->request(*inputStream, response);
LOG.debug("response returned = %s", response.getString().c_str());
// Manage response headers
if (useSessionID) {
// Server returns the jsessionId in the Set-Cookie header, can be used for
// the subsequent calls of upload().
StringBuffer hdr = httpConnection->getResponseHeader(HTTP_HEADER_SET_COOKIE);
sessionID = httpConnection->parseJSessionId(hdr);
}
httpConnection->close();
delete auth;
delete httpConnection;
return status;
}
示例12: readResponseHeaders
void HttpConnection::readResponseHeaders()
{
WCHAR *wbuffer = new WCHAR[1024];
DWORD ddsize = 1024;
StringBuffer headerString;
responseHeaders.clear();
BOOL reqDone = HttpQueryInfo(req, HTTP_QUERY_RAW_HEADERS_CRLF ,(LPVOID)wbuffer, &ddsize, NULL);
if (reqDone == false) {
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
// Allocate the necessary buffer.
delete [] wbuffer;
wbuffer = new WCHAR[ddsize];
reqDone = HttpQueryInfo(req, HTTP_QUERY_RAW_HEADERS_CRLF ,(LPVOID)wbuffer, &ddsize, NULL);
}
}
if (reqDone) {
headerString.convert(wbuffer);
LOG.debug("Response Headers:", headerString.c_str());
ArrayList headers;
headerString.split(headers, "\r\n");
StringBuffer *prop;
for(ArrayElement* e=headers.front(); e; e=headers.next()) {
prop = dynamic_cast<StringBuffer *>(e);
if(prop->empty()) continue;
size_t colon = prop->find(":");
if (colon != StringBuffer::npos) {
StringBuffer key = prop->substr(0, colon);
StringBuffer value = prop->substr(colon+1);
responseHeaders.put(key.trim(),value.trim());
if (canBeLogged(key)) {
LOG.debug("\t%s : %s", key.c_str(), value.c_str());
} else {
LOG.debug("\t%s : *****", key.c_str());
}
}
else {
LOG.debug("\t%s", prop->c_str());
}
}
} else {
DWORD err = GetLastError();
const char* msg = createHttpErrorMessage(err);
LOG.error("[HttpConnection] Error reading response headers - code %d: %s", err, msg);
delete [] msg;
}
}
示例13: getExportTimeForService
time_t MHSyncItemInfo::getExportTimeForService(const char* serviceName)
{
time_t serviceExportTime = -1;
if (serviceName) {
StringBuffer exportTimeStr = exportedServices.get(serviceName);
if (exportTimeStr.empty() == false) {
serviceExportTime = atol(exportTimeStr.c_str());
}
}
return serviceExportTime;
}
示例14: format
char* FolderData::format() {
StringBuffer out;
out.reserve(150);
out = "<Folder>\n";
if (name.length() > 0)
out += XMLProcessor::makeElement(FOLDER_NAME, name);
if (created.length() > 0)
out += XMLProcessor::makeElement(FOLDER_CREATED, created);
if (modified.length() > 0)
out += XMLProcessor::makeElement(FOLDER_MODIFIED, modified);
if (accessed.length() > 0)
out += XMLProcessor::makeElement(FOLDER_ACCESSED, accessed);
StringBuffer attributes;
if (isHiddenPresent)
attributes += XMLProcessor::makeElement(FOLDER_HIDDEN, hidden);
if (isSystemPresent)
attributes += XMLProcessor::makeElement(FOLDER_SYSTEM, system);
if (isArchivedPresent)
attributes += XMLProcessor::makeElement(FOLDER_ARCHIVED, archived);
if (isDeletedPresent)
attributes += XMLProcessor::makeElement(FOLDER_DELETE, deleted);
if (isWritablePresent)
attributes += XMLProcessor::makeElement(FOLDER_WRITABLE, writable);
if (isReadablePresent)
attributes += XMLProcessor::makeElement(FOLDER_READABLE, readable);
if (isExecutablePresent)
attributes += XMLProcessor::makeElement(FOLDER_EXECUTABLE, executable);
if (!attributes.empty())
out += XMLProcessor::makeElement(FOLDER_ATTRIBUTES, attributes);
if (role.length() > 0)
out += XMLProcessor::makeElement(FOLDER_ROLE, role);
if (!(extended.isEmpty())){
for(int i=0; i < extended.size(); i++){
const char* temp = ((FolderExt*)extended.get(i))->format();
out += temp;
delete [] temp;
}
}
out += "</Folder>\n";
return stringdup(out.c_str());
}
示例15: append_line_no
static void append_line_no(StringBuffer &sb, const char *text,
int &line, const char *color, const char *end,
const char **palette =
DebuggerClient::DefaultCodeColors) {
const char *colorLineNo = palette[CodeColorLineNo * 2];
const char *endLineNo = palette[CodeColorLineNo * 2 + 1];
// beginning
if (line && sb.empty()) {
if (colorLineNo) sb.append(colorLineNo);
sb.printf(DebuggerClient::LineNoFormat, line);
if (endLineNo) sb.append(endLineNo);
}
// ending
if (text == NULL) {
if (line) {
if (colorLineNo) sb.append(colorLineNo);
sb.append("(END)\n");
if (endLineNo) sb.append(endLineNo);
}
return;
}
if (color) sb.append(color);
if (line == 0) {
sb.append(text);
} else {
const char *begin = text;
const char *p = begin;
for (; *p; p++) {
if (*p == '\n') {
sb.append(begin, p - begin);
if (end) sb.append(end);
sb.append('\n');
if (colorLineNo) sb.append(colorLineNo);
sb.printf(DebuggerClient::LineNoFormat, ++line);
if (endLineNo) sb.append(endLineNo);
if (color) sb.append(color);
begin = p + 1;
}
}
if (p - begin > 0) {
sb.append(begin, p - begin);
}
}
if (end) sb.append(end);
}