当前位置: 首页>>代码示例>>C++>>正文


C++ StringBuffer::detach方法代码示例

本文整理汇总了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();
}
开发者ID:aloiret,项目名称:hhvm,代码行数:50,代码来源:ext_std_errorfunc.cpp

示例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;
}
开发者ID:DerPapst,项目名称:hhvm,代码行数:14,代码来源:ext_std_process.cpp

示例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;
  }
}
开发者ID:HyeongKyu,项目名称:hiphop-php,代码行数:48,代码来源:url_file.cpp

示例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();
}
开发者ID:bolaria,项目名称:HPCC-Platform,代码行数:16,代码来源:thcodectx.cpp

示例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();
}
开发者ID:carriercomm,项目名称:Teino1978-Corp-hhvm,代码行数:16,代码来源:ext_url.cpp

示例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());
  }
}
开发者ID:joonhochoi,项目名称:hiphop-php,代码行数:47,代码来源:ext_error.cpp

示例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};
}
开发者ID:fredemmott,项目名称:hhvm,代码行数:46,代码来源:debugger_proxy.cpp

示例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("&amp;");   break;
    case '>':  out.append("&gt;");    break;
    case '<':  out.append("&lt;");    break;
    case '"':  out.append("&quot;");  break;
    case '\'': out.append("&#39;");   break;
    case '\n': out.append("&#10;");   break;
    case '\r': out.append("&#13;");   break;
    case '\0': out.append("&#0;");    break;
    default:   out.append(string[i]); break;
    }
  }
  return out.detach();
}
开发者ID:Fermi,项目名称:hhvm,代码行数:18,代码来源:xdebug_xml.cpp

示例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;
  }
}
开发者ID:GunioRobot,项目名称:hiphop-php,代码行数:45,代码来源:JSON_parser.cpp

示例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;
}
开发者ID:DerPapst,项目名称:hhvm,代码行数:44,代码来源:pagelet-server.cpp

示例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());
  }
}
开发者ID:Bittarman,项目名称:hiphop-php,代码行数:19,代码来源:string_buffer.cpp

示例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());
  }
}
开发者ID:SimplProduction,项目名称:hiphop-php,代码行数:19,代码来源:string_buffer.cpp

示例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);
}
开发者ID:facebook,项目名称:hhvm,代码行数:20,代码来源:unit-cache.cpp

示例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;
  }
开发者ID:edv4rd0,项目名称:hiphop-php,代码行数:21,代码来源:pagelet_server.cpp

示例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;
}
开发者ID:JasonGitHub,项目名称:hhvm,代码行数:40,代码来源:ext_stream.cpp


注:本文中的StringBuffer::detach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。