本文整理汇总了C++中StringBuffer::detach方法的典型用法代码示例。如果您正苦于以下问题:C++ StringBuffer::detach方法的具体用法?C++ StringBuffer::detach怎么用?C++ StringBuffer::detach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuffer
的用法示例。
在下文中一共展示了StringBuffer::detach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: debug_string_backtrace
String debug_string_backtrace(bool skip, bool ignore_args /* = false */,
int64_t limit /* = 0 */) {
Array bt;
StringBuffer buf;
bt = createBacktrace(BacktraceArgs()
.skipTop(skip)
.ignoreArgs(ignore_args)
.setLimit(limit));
int i = 0;
for (ArrayIter it = bt.begin(); !it.end(); it.next(), i++) {
Array frame = it.second().toArray();
buf.append('#');
buf.append(i);
if (i < 10) buf.append(' ');
buf.append(' ');
if (frame.exists(s_class)) {
buf.append(frame->get(s_class).toString());
buf.append(frame->get(s_type).toString());
}
buf.append(frame->get(s_function).toString());
buf.append("(");
if (!ignore_args) {
bool first = true;
for (ArrayIter argsIt(frame->get(s_args).toArray());
!argsIt.end();
argsIt.next()) {
if (!first) {
buf.append(", ");
} else {
first = false;
}
try {
buf.append(argsIt.second().toString());
} catch (FatalErrorException& fe) {
buf.append(fe.getMessage());
}
}
}
buf.append(")");
if (frame.exists(s_file)) {
buf.append(" called at [");
buf.append(frame->get(s_file).toString());
buf.append(':');
buf.append(frame->get(s_line).toString());
buf.append(']');
}
buf.append('\n');
}
return buf.detach();
}
示例2: HHVM_FUNCTION
Variant HHVM_FUNCTION(shell_exec,
const String& cmd) {
ShellExecContext ctx;
FILE *fp = ctx.exec(cmd);
if (!fp) return init_null();
StringBuffer sbuf;
sbuf.read(fp);
auto ret = sbuf.detach();
if (ret.empty() && !RuntimeOption::EnableHipHopSyntax) {
// Match php5
return init_null();
}
return ret;
}
示例3: open
bool UrlFile::open(CStrRef url, CStrRef mode) {
if (strchr(mode, '+') || strchr(mode, 'a') || strchr(mode, 'w')) {
std::string msg = "cannot open a url stream for write/append operation: ";
msg += url.c_str();
m_error = msg;
return false;
}
HttpClient http(m_timeout, m_maxRedirect);
StringBuffer response;
HeaderMap *pHeaders = NULL;
HeaderMap requestHeaders;
if (!m_headers.empty()) {
pHeaders = &requestHeaders;
for (ArrayIter iter(m_headers); iter; ++iter) {
requestHeaders[string(iter.first().toString().data())].
push_back(iter.second().toString().data());
}
}
int code;
vector<String> responseHeaders;
if (m_get) {
code = http.get(url.c_str(), response, pHeaders, &responseHeaders);
} else {
code = http.post(url.c_str(), m_postData.data(), m_postData.size(),
response, pHeaders, &responseHeaders);
}
SystemGlobals *g = (SystemGlobals*)get_global_variables();
Variant &r = g->GV(http_response_header);
r = Array::Create();
for (unsigned int i = 0; i < responseHeaders.size(); i++) {
r.append(responseHeaders[i]);
}
if (code == 200) {
int len = m_len;
m_name = url;
m_data = response.detach(len);
m_len = len;
m_malloced = true;
return true;
} else {
m_error = http.getLastError().c_str();
return false;
}
}
示例4: queryCoven
char *CThorCodeContextBase::getDaliServers()
{
StringBuffer dali;
IGroup &group = queryCoven().queryComm().queryGroup();
Owned<INodeIterator> coven = group.getIterator();
bool first = true;
ForEach(*coven)
{
if (first)
first = false;
else
dali.append(',');
coven->query().endpoint().getUrlStr(dali);
}
return dali.detach();
}
示例5: normalize_variable_name
static String normalize_variable_name(const String& name) {
StringBuffer sb;
for (int i = 0; i < name.size(); i++) {
char ch = name.charAt(i);
if ((i > 0 && ch >= '0' && ch <= '9') ||
(ch >= 'a' && ch <= 'z') ||
(ch == '_')) {
sb.append(ch);
} else if (ch >= 'A' && ch <= 'Z') {
sb.append((char)(ch + 'a' - 'A'));
} else {
sb.append('_');
}
}
return sb.detach();
}
示例6: debug_string_backtrace
String debug_string_backtrace(bool skip, bool ignore_args /* = false */,
int limit /* = 0 */) {
if (RuntimeOption::InjectedStackTrace) {
Array bt;
StringBuffer buf;
bt = g_vmContext->debugBacktrace(skip, false, false, nullptr,
ignore_args, limit);
int i = 0;
for (ArrayIter it = bt.begin(); !it.end(); it.next(), i++) {
Array frame = it.second().toArray();
buf.append('#');
buf.append(i);
if (i < 10) buf.append(' ');
buf.append(' ');
if (frame.exists(s_class)) {
buf.append(frame->get(s_class).toString());
buf.append(frame->get(s_type).toString());
}
buf.append(frame->get(s_function).toString());
buf.append("(");
if (!ignore_args) {
bool first = true;
for (ArrayIter it = frame->get(s_args).begin(); !it.end(); it.next()) {
if (!first) {
buf.append(", ");
} else {
first = false;
}
buf.append(it.second().toString());
}
}
buf.append(")");
if (frame.exists(s_file)) {
buf.append(" called at [");
buf.append(frame->get(s_file).toString());
buf.append(':');
buf.append(frame->get(s_line).toString());
buf.append(']');
}
buf.append('\n');
}
return buf.detach();
} else {
StackTrace st;
return String(st.toString());
}
}
示例7: stdout_hook
std::pair<bool,Variant>
DebuggerProxy::ExecutePHP(const std::string &php, String &output,
int frame, int flags) {
TRACE(2, "DebuggerProxy::ExecutePHP\n");
// Wire up stdout and stderr to our own string buffer so we can pass
// any output back to the client.
StringBuffer sb;
StringBuffer *save = g_context->swapOutputBuffer(nullptr);
DebuggerStdoutHook stdout_hook(sb);
DebuggerLoggerHook stderr_hook(sb);
g_context->setStdout(&stdout_hook);
if (flags & ExecutePHPFlagsLog) {
Logger::SetThreadHook(&stderr_hook);
}
SCOPE_EXIT {
g_context->setStdout(nullptr);
g_context->swapOutputBuffer(save);
if (flags & ExecutePHPFlagsLog) {
Logger::SetThreadHook(nullptr);
}
};
String code(php.c_str(), php.size(), CopyString);
// We're about to start executing more PHP. This is typically done
// in response to commands from the client, and the client expects
// those commands to send more interrupts since, of course, the
// user might want to debug the code we're about to run. If we're
// already processing an interrupt, enable signal polling around
// the execution of the new PHP to ensure that we can handle
// signals while doing so.
//
// Note: we must switch the thread mode to Sticky so we block
// other threads which may hit interrupts while we're running,
// since nested processInterrupt() calls would normally release
// other threads on the way out.
assertx(m_thread == (int64_t)Process::GetThreadId());
ThreadMode origThreadMode = m_threadMode;
switchThreadMode(Sticky, m_thread);
if (flags & ExecutePHPFlagsAtInterrupt) enableSignalPolling();
SCOPE_EXIT {
if (flags & ExecutePHPFlagsAtInterrupt) disableSignalPolling();
switchThreadMode(origThreadMode, m_thread);
};
auto const ret = g_context->evalPHPDebugger(code.get(), frame);
output = sb.detach();
return {ret.failed, ret.result};
}
示例8: xdebug_xmlize
/* Xml encode the passed string. */
String xdebug_xmlize(const char* string, size_t len) {
StringBuffer out;
for (size_t i = 0; i < len; ++i) {
switch (string[i]) {
case '&': out.append("&"); break;
case '>': out.append(">"); break;
case '<': out.append("<"); break;
case '"': out.append("""); break;
case '\'': out.append("'"); break;
case '\n': out.append(" "); break;
case '\r': out.append(" "); break;
case '\0': out.append("�"); break;
default: out.append(string[i]); break;
}
}
return out.detach();
}
示例9: json_create_zval
static void json_create_zval(Variant &z, StringBuffer &buf, int type) {
switch (type) {
case KindOfInt64:
{
const char *p = buf.data();
ASSERT(p);
if (p == NULL) {
z = 0LL;
return;
}
bool neg = (buf.charAt(0) == '-');
int len = buf.size();
if (neg) len--;
if (len >= MAX_LENGTH_OF_LONG - 1) {
if (len == MAX_LENGTH_OF_LONG - 1) {
int cmp = strcmp(p + (neg ? 1 : 0), long_min_digits);
if (!(cmp < 0 || (cmp == 0 && neg))) {
z = strtod(p, NULL);
return;
}
} else {
z = strtod(p, NULL);
return;
}
}
z = strtoll(buf.data(), NULL, 10);
}
break;
case KindOfDouble:
z = buf.data() ? strtod(buf.data(), NULL) : 0.0;
break;
case KindOfString:
z = buf.detach();
buf.reset();
break;
case KindOfBoolean:
z = (buf.data() && (*buf.data() == 't'));
break;
default:
z = null;
break;
}
}
示例10: getResults
String PageletTransport::getResults(
Array &headers,
int &code,
int64_t timeout_ms
) {
{
Lock lock(this);
while (!m_done && m_pipeline.empty()) {
if (timeout_ms > 0) {
long seconds = timeout_ms / 1000;
long long nanosecs = (timeout_ms % 1000) * 1000000;
if (!wait(seconds, nanosecs)) {
code = -1;
return empty_string();
}
} else {
wait();
}
}
if (!m_pipeline.empty()) {
// intermediate results do not have headers and code
std::string ret = m_pipeline.front();
m_pipeline.pop_front();
code = 0;
return ret;
}
}
String response(m_response.c_str(), m_response.size(), CopyString);
headers = Array::Create();
for (HeaderMap::const_iterator iter = m_responseHeaders.begin();
iter != m_responseHeaders.end(); ++iter) {
for (unsigned int i = 0; i < iter->second.size(); i++) {
StringBuffer sb;
sb.append(iter->first);
sb.append(": ");
sb.append(iter->second[i]);
headers.append(sb.detach());
}
}
code = m_code;
return response;
}
示例11: absorb
void StringBuffer::absorb(StringBuffer &buf) {
if (empty()) {
char *buffer = m_buffer;
int size = m_size;
m_buffer = buf.m_buffer;
m_size = buf.m_size;
m_pos = buf.m_pos;
#ifdef TAINTED
propagate_tainting1_bufbuf( buf, *this );
#endif
buf.m_buffer = buffer;
buf.m_size = size;
buf.reset();
} else {
append(buf.detach());
}
}
示例12: absorb
void StringBuffer::absorb(StringBuffer &buf) {
if (empty()) {
TAINT_OBSERVER_REGISTER_ACCESSED(buf.getTaintDataRefConst());
TAINT_OBSERVER_REGISTER_MUTATED(m_taint_data);
char *buffer = m_buffer;
int size = m_size;
m_buffer = buf.m_buffer;
m_size = buf.m_size;
m_pos = buf.m_pos;
buf.m_buffer = buffer;
buf.m_size = size;
buf.reset();
} else {
append(buf.detach());
}
}
示例13: createUnitFromUrl
CachedUnit createUnitFromUrl(const StringData* const requestedPath,
const Native::FuncTable& nativeFuncs,
FileLoadFlags& flags) {
auto const w = Stream::getWrapperFromURI(StrNR(requestedPath));
StringBuffer sb;
{
// Stream wrappers can reenter PHP via user defined callbacks. Roll this
// operation into a single event
rqtrace::EventGuard trace{"STREAM_WRAPPER_OPEN"};
rqtrace::DisableTracing disable;
if (!w) return CachedUnit{};
auto const f = w->open(StrNR(requestedPath), "r", 0, nullptr);
if (!f) return CachedUnit{};
sb.read(f.get());
}
OptLog ent;
return createUnitFromString(requestedPath->data(), sb.detach(), nullptr, ent,
nativeFuncs, RepoOptions::defaults(), flags);
}
示例14: getResults
String getResults(Array &headers, int &code) {
{
Lock lock(this);
while (!m_done) wait();
}
String response(m_response.c_str(), m_response.size(), CopyString);
headers = Array::Create();
for (HeaderMap::const_iterator iter = m_responseHeaders.begin();
iter != m_responseHeaders.end(); ++iter) {
for (unsigned int i = 0; i < iter->second.size(); i++) {
StringBuffer sb;
sb.append(iter->first);
sb.append(": ");
sb.append(iter->second[i]);
headers.append(sb.detach());
}
}
code = m_code;
return response;
}
示例15: f_stream_get_contents
Variant f_stream_get_contents(CResRef handle, int maxlen /* = -1 */,
int offset /* = -1 */) {
if (maxlen < -1) {
throw_invalid_argument("maxlen: %d", maxlen);
return false;
}
if (maxlen == 0) {
return String();
}
File *file = handle.getTyped<File>(false /* nullOkay */,
true /* badTypeOkay */);
if (!file) {
throw_invalid_argument(
"stream_get_contents() expects parameter 1 to be a resource");
return false;
}
if (offset >= 0 && !file->seek(offset, SEEK_SET) ) {
raise_warning("Failed to seek to position %d in the stream", offset);
return false;
}
String ret;
if (maxlen != -1) {
ret = String(maxlen, ReserveString);
char *buf = ret.bufferSlice().ptr;
maxlen = file->readImpl(buf, maxlen);
if (maxlen < 0) {
return false;
}
ret.setSize(maxlen);
} else {
StringBuffer sb;
sb.read(file);
ret = sb.detach();
}
return ret;
}