本文整理汇总了C++中StringBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ StringBuffer类的具体用法?C++ StringBuffer怎么用?C++ StringBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printf
bool ViewHelper::doit(FILE * fp)
{
if (globals->hasProp("WUID"))
{
const char* wuid = globals->queryProp("WUID");
Owned<IClientWUInfoRequest> req = wuclient->createWUInfoRequest();
req->setWuid(wuid);
Owned<IClientWUInfoResponse> resp = wuclient->WUInfo(req);
if(!resp)
return false;
const IMultiException* excep = &resp->getExceptions();
if(excep != NULL && excep->ordinality() > 0)
{
StringBuffer msg;
excep->errorMessage(msg);
printf("%s\n", msg.str());
return false;
}
IConstECLWorkunit* w = &resp->getWorkunit();
if (w && fp)
{
bool xml = true;
const char* fmt = globals->queryProp("format");
if(fmt && (stricmp(fmt, "bin") == 0 || stricmp(fmt, "binary") == 0))
xml = false;
IArrayOf<IConstECLException>& exceptions = w->getExceptions();
ForEachItemIn(ind, exceptions)
{
IConstECLException* excep = &exceptions.item(ind);
if(!excep)
continue;
bool skip = false;
const char* severity = excep->getSeverity();
if (severity != NULL && stricmp(severity, "Warning") == 0 && globals->getPropBool("noWarnings", false))
skip = true;
if (severity != NULL && stricmp(severity, "Info") == 0 && globals->getPropBool("noInfo", false))
skip = true;
if (severity != NULL && stricmp(severity, "Error") == 0 && globals->getPropBool("noErrors", false))
skip = true;
if (!skip)
{
int lineno = excep->getLineNo();
const char* source = excep->getSource();
const char* msg = excep->getMessage();
unsigned code = excep->getCode();
if (lineno && source != NULL)
{
if (xml)
fprintf(fp, "<%s><source>%s</source><line>%d</line><code>%d</code><message>%s</message></%s>\n", severity, source, lineno, code, msg, severity);
else
fprintf(fp, "%s: %s(%d) %s\n", severity, source, lineno, msg);
}
else if(source != NULL)
{
if (xml)
fprintf(fp, "<%s><source>%s</source><code>%d</code><message>%s</message></%s>\n", severity, source, code, msg, severity);
else
fprintf(fp, "%s: %s %s\n", severity, source, msg);
}
else
{
if (xml)
fprintf(fp, "<%s><code>%d</code><message>%s</message></%s>\n", severity, code, msg, severity);
else
fprintf(fp, "%s: %s\n", severity, msg);
}
}
}
if (w->getStateID() == WUStateAborted)
{
fprintf(fp, "Aborted\n");
return true;
}
if (w->getStateID() == WUStateFailed)
return false;
int queryid = 0;
IArrayOf<IConstECLResult>& results = w->getResults();
ForEachItemIn(res_ind, results)
{
IConstECLResult* result = &results.item(res_ind);
if(!result)
continue;
const char* value = result->getValue();
if(value != NULL && stricmp(value, "[undefined]") == 0)
continue;
if(format)
format->printHeader(fp, result->getName());
const char* rfname = result->getFileName();
if(!(rfname && *rfname && (globals->getPropInt("viewFileResults") ==0)))
//.........这里部分代码省略.........
示例2:
char *CThorCodeContextBase::getJobOwner()
{
StringBuffer out;
out.append(job.queryUser());
return out.detach();
}
示例3: format
String DateInterval::format(const String& format_spec) {
StringBuffer s;
for(int i = 0; i < format_spec.length(); i++) {
const int MAXLEN = 22; // 64bit signed int string length, plus terminating \0
char buf[MAXLEN];
int l;
char c = format_spec.charAt(i);
if (c != '%') {
s.append(c);
continue;
}
i++;
if (i == format_spec.length()) {
// End of format, use literal % and finish
s.append(c);
break;
}
c = format_spec.charAt(i);
switch(c) {
case 'Y': l = snprintf(buf, MAXLEN, "%02" PRId64, getYears()); break;
case 'y': l = snprintf(buf, MAXLEN, "%" PRId64, getYears()); break;
case 'M': l = snprintf(buf, MAXLEN, "%02" PRId64, getMonths()); break;
case 'm': l = snprintf(buf, MAXLEN, "%" PRId64, getMonths()); break;
case 'D': l = snprintf(buf, MAXLEN, "%02" PRId64, getDays()); break;
case 'd': l = snprintf(buf, MAXLEN, "%" PRId64, getDays()); break;
case 'H': l = snprintf(buf, MAXLEN, "%02" PRId64, getHours()); break;
case 'h': l = snprintf(buf, MAXLEN, "%" PRId64, getHours()); break;
case 'I': l = snprintf(buf, MAXLEN, "%02" PRId64, getMinutes()); break;
case 'i': l = snprintf(buf, MAXLEN, "%" PRId64, getMinutes()); break;
case 'S': l = snprintf(buf, MAXLEN, "%02" PRId64, getSeconds()); break;
case 's': l = snprintf(buf, MAXLEN, "%" PRId64, getSeconds()); break;
case 'a':
if (haveTotalDays()) {
l = snprintf(buf, MAXLEN, "%" PRId64, getTotalDays());
} else {
l = snprintf(buf, MAXLEN, "(unknown)");
}
break;
case 'R':
l = snprintf(buf, MAXLEN, "%c", isInverted() ? '-' : '+'); break;
case 'r':
l = snprintf(buf, MAXLEN, "%s", isInverted() ? "-" : ""); break;
case '%':
default:
l = 0;
s.append('%');
break;
}
if (l > 0) {
s.append(buf, l);
}
}
return s.detach();
}
示例4:
TCHAR * CTaskModel::toXMLNoKids()
{
StringBuffer sb;
toXMLString(sb, false);
return sb.toString();
}
示例5: expandLogicalName
char *CThorCodeContextBase::getExpandLogicalName(const char * logicalName)
{
StringBuffer lfn;
expandLogicalName(lfn, logicalName);
return lfn.detach();
}
示例6: stringify
result_t querystring_base::stringify(v8::Local<v8::Object> obj, exlib::string sep,
exlib::string eq, v8::Local<v8::Object> opt,
exlib::string& retVal)
{
StringBuffer bufs;
v8::Local<v8::Array> ks = obj->GetPropertyNames();
int32_t len = ks->Length();
int32_t i;
result_t hr;
for (i = 0; i < len; i++) {
exlib::string strKey, strValue, str;
v8::Local<v8::Array> vs;
v8::Local<v8::Value> k = ks->Get(i);
v8::Local<v8::Value> v = obj->Get(k);
GetArgumentValue(k, strKey);
encoding_base::encodeURIComponent(strKey, strKey);
hr = GetArgumentValue(v, vs, true);
if (hr >= 0) {
int32_t len1 = vs->Length();
int32_t i1;
for (i1 = 0; i1 < len1; i1++) {
hr = GetArgumentValue(vs->Get(i1), strValue);
if (hr < 0)
return hr;
encoding_base::encodeURIComponent(strValue, strValue);
if (bufs.size() > 0)
bufs.append(sep);
bufs.append(strKey);
bufs.append(eq);
bufs.append(strValue);
}
} else {
hr = GetArgumentValue(v, strValue);
if (hr < 0)
return hr;
encoding_base::encodeURIComponent(strValue, strValue);
if (bufs.size() > 0)
bufs.append(sep);
bufs.append(strKey);
bufs.append(eq);
bufs.append(strValue);
}
}
retVal = bufs.str();
return 0;
}
示例7: HHVM_FUNCTION
String HHVM_FUNCTION(serialize, const Variant& value) {
switch (value.getType()) {
case KindOfUninit:
case KindOfNull:
return "N;";
case KindOfBoolean:
return value.getBoolean() ? "b:1;" : "b:0;";
case KindOfInt64: {
StringBuffer sb;
sb.append("i:");
sb.append(value.getInt64());
sb.append(';');
return sb.detach();
}
case KindOfStaticString:
case KindOfString: {
StringData *str = value.getStringData();
StringBuffer sb;
sb.append("s:");
sb.append(str->size());
sb.append(":\"");
sb.append(str->data(), str->size());
sb.append("\";");
return sb.detach();
}
case KindOfArray: {
ArrayData *arr = value.getArrayData();
if (arr->empty()) return "a:0:{}";
// fall-through
}
case KindOfDouble:
case KindOfObject:
case KindOfResource: {
VariableSerializer vs(VariableSerializer::Type::Serialize);
return vs.serialize(value, true);
}
case KindOfRef:
case KindOfClass:
break;
}
not_reached();
}
示例8: SuiMessageBox
int ForceShrineMenuComponent::handleObjectMenuSelect(SceneObject* sceneObject, CreatureObject* creature, byte selectedID) {
if (selectedID != 213)
return 0;
if (creature->getPosture() != CreaturePosture::CROUCHED){
creature->sendSystemMessage("@jedi_trials:show_respect"); // Must show respect
return 0;
}
ManagedReference<PlayerObject*> ghost = creature->getPlayerObject();
if (ghost == NULL)
return 0;
if (creature->getScreenPlayState("VillageJediProgression") && !creature->hasSkill("force_title_jedi_rank_02")){
ManagedReference<SuiMessageBox*> box = new SuiMessageBox(creature, SuiWindowType::NONE);
box->setPromptTitle("@jedi_trials:padawan_trials_title"); // Jedi Trials
box->setPromptText("@jedi_trials:padawan_trials_completed");
ghost->addSuiBox(box);
creature->sendMessage(box->generateMessage());
SkillManager::instance()->awardSkill("force_title_jedi_rank_02", creature, true, true, true);
creature->playEffect("clienteffect/entertainer_dazzle_level_3.cef", ""); // Not sure if it's the right one for this.
PlayMusicMessage* pmm = new PlayMusicMessage("sound/intro.snd");
creature->sendMessage(pmm);
ghost->setJediState(2);
// Trainer number. Pick a random trainer, there are at least 600 in the galaxy.
ZoneServer* zoneServer = ghost->getZoneServer();
int randomZone = System::random(zoneServer->getZoneCount() - 1);
ManagedReference<Zone*> zone = zoneServer->getZone(randomZone);
Vector3 randomTrainer = zone->getCreatureManager()->getRandomJediTrainer();
if ((randomTrainer.getX() == 0) && (randomTrainer.getY() == 0)) { // No trainers on the zone.
ManagedReference<Zone*> zone = zoneServer->getZone(0);
Vector3 randomTrainer = zone->getCreatureManager()->getRandomJediTrainer();
}
Vector3 trainerPositionFinal(randomTrainer.getX(), randomTrainer.getY(), 0);
String zoneName = zone->getZoneName();
ghost->setTrainerCoordinates(trainerPositionFinal);
ghost->setTrainerZoneName(zoneName); // For the Waypoint.
ManagedReference<SceneObject*> inventory = creature->getSlottedObject("inventory");
//Check if inventory is full.
if (inventory->hasFullContainerObjects()) {
creature->sendSystemMessage("@jedi_spam:inventory_full_jedi_robe"); // You have too many items in your inventory. In order to get your Padawan Robe you must clear out at least one free slot.
return 0;
}
ZoneServer* zserv = creature->getZoneServer();
String PadawanRobe = "object/tangible/wearables/robe/robe_jedi_padawan.iff";
ManagedReference<SceneObject*> padawanRobe = zserv->createObject(PadawanRobe.hashCode(), 1);
if (inventory->transferObject(padawanRobe, -1)) {
inventory->broadcastObject(padawanRobe, true);
} else {
padawanRobe->destroyObjectFromDatabase(true);
}
}
else if (!creature->hasSkill("force_title_jedi_novice")){
int rand = System::random(14) + 1;
StringBuffer sysmsg;
sysmsg << "@jedi_trials:force_shrine_wisdom_" << rand;
creature->sendSystemMessage(sysmsg.toString());
}
else if (creature->hasSkill("force_title_jedi_rank_02")){
ManagedReference<SceneObject*> inventory = creature->getSlottedObject("inventory");
//Check if inventory is full.
if (inventory->hasFullContainerObjects()) {
creature->sendSystemMessage("@jedi_spam:inventory_full_jedi_robe"); // You have too many items in your inventory. In order to get your Padawan Robe you must clear out at least one free slot.
return 0;
}
ZoneServer* zserv = creature->getZoneServer();
String PadawanRobe = "object/tangible/wearables/robe/robe_jedi_padawan.iff";
ManagedReference<SceneObject*> padawanRobe = zserv->createObject(PadawanRobe.hashCode(), 1);
if (inventory->transferObject(padawanRobe, -1)) {
inventory->broadcastObject(padawanRobe, true);
} else {
//.........这里部分代码省略.........
示例9: fileExists
inline bool fileExists(StringBuffer &filename)
{
return (checkFileExists(filename.str()) || checkFileExists(filename.toUpperCase().str()) || checkFileExists(filename.toLowerCase().str()));
}
示例10: ProxyRequest
bool HttpProtocol::ProxyRequest(Transport *transport, bool force,
const std::string &url,
int &code, std::string &error,
StringBuffer &response,
HeaderMap *extraHeaders /* = NULL */) {
assert(transport);
if (transport->headersSent()) {
raise_warning("Cannot proxy request - headers already sent");
return false;
}
HeaderMap requestHeaders;
transport->getHeaders(requestHeaders);
if (extraHeaders) {
for (HeaderMap::const_iterator iter = extraHeaders->begin();
iter != extraHeaders->end(); ++iter) {
std::vector<std::string> &values = requestHeaders[iter->first];
values.insert(values.end(), iter->second.begin(), iter->second.end());
}
}
int size = 0;
const char *data = nullptr;
if (transport->getMethod() == Transport::Method::POST) {
data = (const char *)transport->getPostData(size);
}
code = 0; // HTTP status of curl or 0 for "no server response code"
std::vector<String> responseHeaders;
HttpClient http;
if (data && size) {
code = http.post(url.c_str(), data, size, response, &requestHeaders,
&responseHeaders);
} else {
code = http.get(url.c_str(), response, &requestHeaders, &responseHeaders);
}
if (code == 0) {
if (!force) return false; // so we can retry
Logger::Error("Unable to proxy %s: %s", url.c_str(),
http.getLastError().c_str());
error = http.getLastError();
return true;
}
for (unsigned int i = 0; i < responseHeaders.size(); i++) {
String &header = responseHeaders[i];
if (header.find(":") != String::npos &&
header.find("Content-Length: ") != 0 &&
header.find("Client-Transfer-Encoding: ") != 0 &&
header.find("Transfer-Encoding: ") != 0 &&
header.find("Connection: ") != 0) {
transport->addHeader(header.data());
}
}
const char* respData = response.data();
if (!respData) {
respData = "";
}
Logger::Verbose("Response code was %d when proxying %s", code, url.c_str());
return true;
}
示例11: loadBuiltIns
CEspConfig::CEspConfig(IProperties* inputs, IPropertyTree* envpt, IPropertyTree* procpt, bool isDali)
{
hsami_=0;
serverstatus=NULL;
useDali=false;
if(inputs)
m_inputs.setown(inputs);
if(!envpt || !procpt)
return;
m_envpt.setown(envpt);
m_cfg.setown(procpt);
loadBuiltIns();
// load options
const char* level = m_cfg->queryProp("@logLevel");
m_options.logLevel = level ? atoi(level) : LogMin;
m_options.logReq = m_cfg->getPropBool("@logRequests", false);
m_options.logResp = m_cfg->getPropBool("@logResponses", false);
m_options.frameTitle.set(m_cfg->queryProp("@name"));
m_options.slowProcessingTime = m_cfg->getPropInt("@slowProcessingTime", 30) * 1000; //in msec
#ifdef USE_ENV_CONF_FILE
// load environment parameters
StringBuffer envConfFile, envXMLFile;
const char* configFile = m_cfg->queryProp("EnvironmentConfFile");
if (configFile && *configFile)
{
envConfFile.append(configFile);
}
else
{
envConfFile.append("/etc/LexisNexis/environment.conf");
}
const char* envFromDali = m_cfg->queryProp("@environmentNotFromDali");
if (envFromDali && !stricmp(envFromDali, "true"))
{
const char* envXML = m_cfg->queryProp("EnvironmentXMLFile");
if (envXML && *envXML)
{
envXMLFile.append(envXML);
}
else
{
envXMLFile.append("environment.xml");
}
}
Owned<IEnvironmentFactory> factory = getEnvironmentFactory();
factory->createEnvironmentByFile(envConfFile.str(), envXMLFile.str());
#endif
if (!m_cfg->getProp("@name", m_process))
{
ERRLOG("EspProcess name not found");
}
else
{
DBGLOG("ESP process name [%s]", m_process.str());
IPropertyTreeIterator *pt_iter = NULL;
StringBuffer daliservers;
if (m_cfg->getProp("@daliServers", daliservers))
initDali(daliservers.str());
#ifndef _DEBUG
startPerformanceMonitor(m_cfg->getPropInt("@perfReportDelay", 60)*1000);
#endif
//get the local computer name:
m_cfg->getProp("@computer", m_computer);
//get the local computer information:
StringBuffer xpath;
xpath.appendf("Hardware/Computer[@name=\"%s\"]", m_computer.str());
IPropertyTree *computer = m_envpt->queryPropTree(xpath.str());
if (computer)
{
StringBuffer address;
computer->getProp("@netAddress", address);
int port = m_cfg->getPropInt("@port", 1500);
if(strcmp(address.str(), ".") == 0)
{
GetHostName(address.clear());
}
m_address.set(address.str(), (unsigned short) port);
}
xpath.clear();
xpath.append("EspService");
pt_iter = m_cfg->getElements(xpath.str());
if (pt_iter!=NULL)
{
//.........这里部分代码省略.........
示例12: formIPList
//-----------------------------------------------------------------------
// SetEnvironment
//-----------------------------------------------------------------------
void CWizardInputs::setEnvironment()
{
StringBuffer xpath;
if(m_pXml->hasProp("@ipList"))
formIPList(m_pXml->queryProp("@ipList"), m_ipaddress);
if(m_pXml->hasProp("@supportNodes"))
{
m_supportNodes = atoi(m_pXml->queryProp("@supportNodes"));
if (m_supportNodes)
{
if (m_ipaddress.length() > 0 && m_ipaddress.length() > m_supportNodes)
{
for(unsigned i = 0; i < m_supportNodes; i++)
m_ipaddressSupport.append(m_ipaddress.item(i));
m_ipaddress.removen(0, m_supportNodes);
}
else
m_supportNodes = 0;
}
}
if(m_pXml->hasProp("@roxieNodes"))
m_roxieNodes = atoi(m_pXml->queryProp("@roxieNodes"));
if(m_pXml->hasProp("@thorNodes"))
m_thorNodes = atoi(m_pXml->queryProp("@thorNodes"));
if(m_pXml->hasProp("@dbuser"))
m_dbuser = m_pXml->queryProp("@dbuser");
if(m_pXml->hasProp("@dbpassword"))
m_dbpassword = m_pXml->queryProp("@dbpassword");
m_thorSlavesPerNode = 1;
if(m_pXml->hasProp("@slavesPerNode"))
m_thorSlavesPerNode = atoi( m_pXml->queryProp("@slavesPerNode"));
if (m_thorSlavesPerNode < 1)
m_thorSlavesPerNode = 1;
m_roxieOnDemand = m_pXml->getPropBool("@roxieOnDemand", true);
xpath.clear().appendf("Software/EspProcess/EspService[@name='%s']/LocalConfFile", m_service.str());
const char* pConfFile = m_cfg->queryProp(xpath.str());
xpath.clear().appendf("Software/EspProcess/EspService[@name='%s']/LocalEnvConfFile", m_service.str());
const char* pEnvConfFile = m_cfg->queryProp(xpath.str());
if (pConfFile && *pConfFile && pEnvConfFile && *pEnvConfFile)
{
Owned<IProperties> pParams = createProperties(pConfFile);
Owned<IProperties> pEnvParams = createProperties(pEnvConfFile);
StringBuffer sb, fileName;
fileName.append((pEnvParams->queryProp("path")!= NULL ? (sb.clear().append(pEnvParams->queryProp("path")).append("/componentfiles/configxml/")) : STANDARD_CONFIGXMLDIR));
fileName.append((pParams->queryProp("buildset") != NULL ? (sb.clear().append(pParams->queryProp("buildset"))) : STANDARD_CONFIG_BUILDSETFILE));
if(fileName.length() && checkFileExists(fileName.str()))
m_buildSetTree.setown(createPTreeFromXMLFile(fileName.str()));
else
throw MakeStringException( -1 , "The buildSetFile %s does not exists", fileName.str());
fileName.clear().append((pEnvParams->queryProp("configs") != NULL ? (sb.clear().append(pEnvParams->queryProp("configs")).append("/")): STANDARD_CONFIG_DIR));
fileName.append((pParams->queryProp("wizardalgorithm") != NULL ? (sb.clear().append(pParams->queryProp("wizardalgorithm"))) : STANDARD_CONFIG_ALGORITHMFILE));
if(fileName.length() && checkFileExists(fileName.str()))
m_algProp.setown(createProperties(fileName.str()));
else
throw MakeStringException( -1 , "The algorithm file %s does not exists", fileName.str());
}
setWizardRules();
setTopologyParam();
}
示例13: f_icu_match
Variant f_icu_match(CStrRef pattern, CStrRef subject,
VRefParam matches /* = null */, int64_t flags /* = 0 */) {
UErrorCode status = U_ZERO_ERROR;
if (matches.isReferenced()) {
matches = Array();
}
// Create hash map key by concatenating pattern and flags.
StringBuffer bpattern;
bpattern.append(pattern);
bpattern.append(':');
bpattern.append(flags);
String spattern = bpattern.detach();
// Find compiled pattern matcher in hash map or add it.
PatternStringMap::accessor accessor;
const RegexPattern* rpattern;
if (s_patternCacheMap.find(accessor, spattern.get())) {
rpattern = accessor->second;
} else {
// First 32 bits are reserved for ICU-specific flags.
rpattern = RegexPattern::compile(
UnicodeString::fromUTF8(pattern.data()), (flags & 0xFFFFFFFF), status);
if (U_FAILURE(status)) {
return false;
}
if (s_patternCacheMap.insert(
accessor, makeStaticString(spattern.get()))) {
accessor->second = rpattern;
} else {
delete rpattern;
rpattern = accessor->second;
}
}
// Build regex matcher from compiled pattern and passed-in subject.
UnicodeString usubject = UnicodeString::fromUTF8(subject.data());
boost::scoped_ptr<RegexMatcher> matcher(rpattern->matcher(usubject, status));
if (U_FAILURE(status)) {
return false;
}
// Return 0 or 1 depending on whether or not a match was found and
// (optionally), set matched (sub-)patterns for passed-in reference.
int matched = 0;
if (matcher->find()) {
matched = 1;
if (matches.isReferenced()) {
int32_t count = matcher->groupCount();
for (int32_t i = 0; i <= count; i++) {
UnicodeString ustring = matcher->group(i, status);
if (U_FAILURE(status)) {
return false;
}
// Convert UnicodeString back to UTF-8.
std::string string;
ustring.toUTF8String(string);
String match = String(string);
if (flags & k_UREGEX_OFFSET_CAPTURE) {
// start() returns the index in UnicodeString, which
// normally means the index into an array of 16-bit
// code "units" (not "points").
int32_t start = matcher->start(i, status);
if (U_FAILURE(status)) {
return false;
}
start = usubject.countChar32(0, start);
matches->append(make_packed_array(match, start));
} else {
matches->append(match);
}
}
}
}
return matched;
}
示例14: string
std::string CmdPrint::FormatResult(const char *format, CVarRef ret) {
if (format == NULL) {
String sret = DebuggerClient::FormatVariable(ret, -1);
return string(sret.data(), sret.size());
}
if (strcmp(format, "v") == 0) {
String sret = DebuggerClient::FormatVariable(ret, -1, true);
return string(sret.data(), sret.size());
}
if (strcmp(format, "dec") == 0 ||
strcmp(format, "unsigned") == 0 ||
ret.isInteger()) {
int64 nret = ret.toInt64();
char buf[64];
if (strcmp(format, "hex") == 0 || strcmp(format, "x") == 0) {
snprintf(buf, sizeof(buf), "%llx", nret);
return buf;
}
if (strcmp(format, "oct") == 0) {
snprintf(buf, sizeof(buf), "%llo", nret);
return buf;
}
if (strcmp(format, "dec") == 0) {
snprintf(buf, sizeof(buf), "%lld", nret);
return buf;
}
if (strcmp(format, "unsigned") == 0) {
snprintf(buf, sizeof(buf), "%llu", (unsigned long long)nret);
return buf;
}
if (strcmp(format, "time") == 0) {
StringBuffer sb;
DateTime dt(nret);
sb.append("RFC822: ");
sb.append(dt.toString(DateTime::RFC822));
sb.append("\nRFC850: ");
sb.append(dt.toString(DateTime::RFC850));
sb.append("\nRFC1036: ");
sb.append(dt.toString(DateTime::RFC1036));
sb.append("\nRFC1123/RSS: ");
sb.append(dt.toString(DateTime::RFC1123));
sb.append("\nRFC2822: ");
sb.append(dt.toString(DateTime::RFC2822));
sb.append("\nRFC3339/ATOM/W3C: ");
sb.append(dt.toString(DateTime::RFC3339));
sb.append("\nISO8601: ");
sb.append(dt.toString(DateTime::ISO8601));
sb.append("\nCookie: ");
sb.append(dt.toString(DateTime::Cookie));
sb.append("\nHttpHeader: ");
sb.append(dt.toString(DateTime::HttpHeader));
return sb.data();
}
ASSERT(false);
}
String sret = DebuggerClient::FormatVariable(ret, -1);
if (strcmp(format, "hex") == 0 || strcmp(format, "x") == 0 ||
strcmp(format, "oct") == 0) {
StringBuffer sb;
for (int i = 0; i < sret.size(); i++) {
char ch = sret[i];
if (isprint(ch)) {
sb.append(ch);
} else {
char buf[6];
if (strcmp(format, "oct") == 0) {
snprintf(buf, sizeof(buf), "\\%03o", ch);
} else {
snprintf(buf, sizeof(buf), "\\x%02x", ch);
}
sb.append(buf);
}
}
return sb.data();
}
if (strcmp(format, "time") == 0) {
DateTime dt;
int64 ts = -1;
if (dt.fromString(ret.toString(), SmartObject<TimeZone>())) {
bool err;
ts = dt.toTimeStamp(err);
}
return String(ts).data();
}
ASSERT(false);
return "";
}
示例15: HHVM_FUNCTION
//.........这里部分代码省略.........
if (suppress_errors) {
SetErrorMode(old_error_mode);
}
if (newprocok == FALSE) {
DWORD dw = GetLastError();
char* msg;
FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&msg,
0,
nullptr);
/* clean up all the descriptors */
for (size_t i = 0; i < items.size(); i++) {
CloseHandle(items[i].childend);
if (items[i].parentend) {
CloseHandle(items[i].parentend);
}
}
raise_warning("CreateProcess failed, error code - %u: %s", dw, msg);
LocalFree(msg);
return false;
}
childHandle = pi.hProcess;
DWORD child = pi.dwProcessId;
CloseHandle(pi.hThread);
return post_proc_open(cmd, pipes, enva, items, (pid_t)child, childHandle);
#else
pid_t child;
if (LightProcess::Available()) {
// light process available
// there is no need to do any locking, because the forking is delegated
// to the light process
if (!pre_proc_open(descriptorspec, items)) return false;
const int item_size = items.size();
std::vector<int> created;
created.reserve(item_size);
std::vector<int> intended;
intended.reserve(item_size);
for (int i = 0; i < item_size; i++) {
const auto& item = items[i];
created.push_back(item.childend);
intended.push_back(item.index);
}
std::vector<std::string> envs;
for (ArrayIter iter(enva); iter; ++iter) {
StringBuffer nvpair;
nvpair.append(iter.first().toString());
nvpair.append('=');
nvpair.append(iter.second().toString());
std::string tmp = nvpair.detach().c_str();
if (tmp.find('\n') == std::string::npos) {
envs.push_back(tmp);
}
}
child = LightProcess::proc_open(cmd.c_str(), created, intended,
scwd.c_str(), envs);
assert(child);
return post_proc_open(cmd, pipes, enva, items, child);
} else {
/* the unix way */
Lock lock(DescriptorItem::s_mutex);
if (!pre_proc_open(descriptorspec, items)) return false;
child = fork();
if (child) {
// the parent process
return post_proc_open(cmd, pipes, enva, items, child);
}
}
assert(child == 0);
/* this is the child process */
/* close those descriptors that we just opened for the parent stuff,
* dup new descriptors into required descriptors and close the original
* cruft */
for (auto& item : items) {
item.dupChild();
}
if (scwd.length() > 0 && chdir(scwd.c_str())) {
// chdir failed, the working directory remains unchanged
}
std::vector<String> senvs; // holding those char *
char **envp = build_envp(enva, senvs);
execle("/bin/sh", "sh", "-c", cmd.data(), nullptr, envp);
free(envp);
_exit(127);
#endif
}