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


C++ CStrRef::size方法代码示例

本文整理汇总了C++中CStrRef::size方法的典型用法代码示例。如果您正苦于以下问题:C++ CStrRef::size方法的具体用法?C++ CStrRef::size怎么用?C++ CStrRef::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CStrRef的用法示例。


在下文中一共展示了CStrRef::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: HtmlEncode

String StringUtil::HtmlEncode(CStrRef input, QuoteStyle quoteStyle,
                              const char *charset, bool nbsp) {
  if (input.empty()) return input;

  assert(charset);
  bool utf8 = true;
  if (strcasecmp(charset, "ISO-8859-1") == 0) {
    utf8 = false;
  } else if (strcasecmp(charset, "UTF-8")) {
    throw NotImplementedException(charset);
  }

  int len = input.size();
  char *ret = string_html_encode(input.data(), len,
                                 quoteStyle != QuoteStyle::No,
                                 quoteStyle == QuoteStyle::Both,
                                 utf8, nbsp);
  if (!ret) {
    raise_error("HtmlEncode called on too large input (%d)", len);
  }
  return String(ret, len, AttachString);
}
开发者ID:Tlamelo,项目名称:hiphop-php,代码行数:22,代码来源:string-util.cpp

示例2: ToUpper

String StringUtil::ToUpper(CStrRef input,
                           ToUpperType type /*= ToUpperType::All */) {
  if (input.empty()) return input;

  int len = input.size();
  char *ret = nullptr;
  switch (type) {
  case ToUpperType::All:
    ret = string_to_upper(input.data(), len);
    break;
  case ToUpperType::First:
    ret = string_to_upper_first(input.data(), len);
    break;
  case ToUpperType::Words:
    ret = string_to_upper_words(input.data(), len);
    break;
  default:
    assert(false);
    break;
  }
  return String(ret, len, AttachString);
}
开发者ID:Tlamelo,项目名称:hiphop-php,代码行数:22,代码来源:string-util.cpp

示例3: f_xml_parse_into_struct

int f_xml_parse_into_struct(CObjRef parser, CStrRef data, Variant values,
                            Variant index /* = null */) {
  int ret;
  XmlParser * p = parser.getTyped<XmlParser>();
  values = Array::Create();
  p->data = ref(values);
  index = Array::Create();
  p->info = ref(index);
  p->level = 0;
  p->ltags = (char**)malloc(XML_MAXLEVEL * sizeof(char*));

  XML_SetDefaultHandler(p->parser, _xml_defaultHandler);
  XML_SetElementHandler(p->parser, _xml_startElementHandler,
                        _xml_endElementHandler);
  XML_SetCharacterDataHandler(p->parser, _xml_characterDataHandler);

  p->isparsing = 1;
  ret = XML_Parse(p->parser, (const XML_Char*)data.data(), data.size(), 1);
  p->isparsing = 0;

  return ret;
}
开发者ID:diegoIta,项目名称:hiphop-php,代码行数:22,代码来源:ext_xml.cpp

示例4: PostMessage

bool XboxServer::PostMessage(CStrRef message,
                             CStrRef host /* = "localhost" */) {
  if (isLocalHost(host)) {
    Lock l(s_dispatchMutex);
    if (!s_dispatcher) {
      return false;
    }

    XboxTransport *job = new XboxTransport(message);
    job->incRefCount(); // paired with worker's decRefCount()
    assert(s_dispatcher);
    s_dispatcher->enqueue(job);
    return true;

  } else { // remote

    string url = "http://";
    url += host.data();
    url += "/xbox_post_message";

    vector<string> headers;
    string hostStr(host.data());
    LibEventHttpClientPtr http =
      LibEventHttpClient::Get(hostStr, RuntimeOption::XboxServerPort);
    if (http->send(url, headers, 0, false, message.data(), message.size())) {
      int code = http->getCode();
      if (code > 0) {
        int len = 0;
        char *response = http->recv(len);
        String sresponse(response, len, AttachString);
        if (code == 200 && same(unserialize_from_string(sresponse), true)) {
          return true;
        }
      }
    }
  }

  return false;
}
开发者ID:HendrikGrunstra,项目名称:hiphop-php,代码行数:39,代码来源:xbox_server.cpp

示例5: open

  virtual File* open(CStrRef filename, CStrRef mode,
                     int options, CVarRef context) {
    static const char cz[] = "phar://";
    if (strncmp(filename.data(), cz, sizeof(cz) - 1)) {
      return nullptr;
    }

    static Func* f = SystemLib::s_PharClass->lookupMethod(s_openPhar.get());

    Variant ret;
    g_vmContext->invokeFunc(
      ret.asTypedValue(),
      f,
      CREATE_VECTOR1(filename),
      nullptr,
      SystemLib::s_PharClass
    );
    CStrRef contents = ret.toString();

    MemFile* file = NEWOBJ(MemFile)(contents.data(), contents.size());
    return file;
  }
开发者ID:MarcReis,项目名称:hiphop-php,代码行数:22,代码来源:ext_phar.cpp

示例6: preparer

bool PDOSqliteConnection::preparer(CStrRef sql, sp_PDOStatement *stmt,
                                   CVarRef options) {
  if (options.toArray().exists(PDO_ATTR_CURSOR) &&
      options[PDO_ATTR_CURSOR].toInt64() != PDO_CURSOR_FWDONLY) {
    m_einfo.errcode = SQLITE_ERROR;
    handleError(__FILE__, __LINE__);
    return false;
  }

  const char *tail;
  sqlite3_stmt *rawstmt = NULL;
  if (sqlite3_prepare(m_db, sql.data(), sql.size(), &rawstmt, &tail)
      == SQLITE_OK) {

    PDOSqliteStatement *s = new PDOSqliteStatement(m_db, rawstmt);
    *stmt = s;
    return true;
  }

  handleError(__FILE__, __LINE__);
  return false;
}
开发者ID:MarkTseng,项目名称:hiphop-php,代码行数:22,代码来源:pdo_sqlite.cpp

示例7: php_hash_do_hash

static Variant php_hash_do_hash(CStrRef algo, CStrRef data, bool isfilename,
                                bool raw_output) {
  HashEnginePtr ops = php_hash_fetch_ops(algo);
  if (!ops) {
    raise_warning("Unknown hashing algorithm: %s", algo.data());
    return false;
  }
  Variant f;
  if (isfilename) {
    f = f_fopen(data, "rb");
    if (same(f, false)) {
      return false;
    }
  }

  void *context = malloc(ops->context_size);
  ops->hash_init(context);

  if (isfilename) {
    for (Variant chunk = f_fread(f, 1024); !is_empty_string(chunk);
         chunk = f_fread(f, 1024)) {
      String schunk = chunk.toString();
      ops->hash_update(context, (unsigned char *)schunk.data(), schunk.size());
    }
  } else {
    ops->hash_update(context, (unsigned char *)data.data(), data.size());
  }

  String raw = String(ops->digest_size, ReserveString);
  char *digest = raw.mutableSlice().ptr;
  ops->hash_final((unsigned char *)digest, context);
  free(context);

  raw.setSize(ops->digest_size);
  if (raw_output) {
    return raw;
  }
  return StringUtil::HexEncode(raw);
}
开发者ID:MarkTseng,项目名称:hiphop-php,代码行数:39,代码来源:ext_hash.cpp

示例8: Implode

String StringUtil::Implode(CArrRef items, CStrRef delim) {
  int size = items.size();
  if (size == 0) return "";

  String* sitems = (String*)smart_malloc(size * sizeof(String));
  int len = 0;
  int lenDelim = delim.size();
  int i = 0;
  for (ArrayIter iter(items); iter; ++iter) {
    new (&sitems[i]) String(iter.second().toString());
    len += sitems[i].size() + lenDelim;
    i++;
  }
  len -= lenDelim; // always one delimiter less than count of items
  assert(i == size);

  String s = String(len, ReserveString);
  char *buffer = s.mutableSlice().ptr;
  const char *sdelim = delim.data();
  char *p = buffer;
  for (int i = 0; i < size; i++) {
    String &item = sitems[i];
    if (i && lenDelim) {
      memcpy(p, sdelim, lenDelim);
      p += lenDelim;
    }
    int lenItem = item.size();
    if (lenItem) {
      memcpy(p, item.data(), lenItem);
      p += lenItem;
    }
    sitems[i].~String();
  }
  smart_free(sitems);
  assert(p - buffer == len);
  return s.setSize(len);
}
开发者ID:mariusz-szydzik,项目名称:hiphop-php,代码行数:37,代码来源:string_util.cpp

示例9: Implode

String StringUtil::Implode(CArrRef items, CStrRef delim) {
  int size = items.size();
  if (size == 0) return "";

  vector<String> sitems;
  sitems.reserve(size);
  int len = 0;
  int lenDelim = delim.size();
  for (ArrayIter iter(items); iter; ++iter) {
    String item = iter.second().toString();
    sitems.push_back(item);
    len += lenDelim;
    len += item.size();
  }
  len -= lenDelim; // always one delimiter less than count of items
  ASSERT((int)sitems.size() == size);

  char *buffer = (char *)malloc(len + 1);
  const char *sdelim = delim.data();
  char *p = buffer;
  for (int i = 0; i < size; i++) {
    String &item = sitems[i];
    if (i && lenDelim) {
      memcpy(p, sdelim, lenDelim);
      p += lenDelim;
    }
    int lenItem = item.size();
    if (lenItem) {
      memcpy(p, item.data(), lenItem);
      p += lenItem;
    }
  }
  *p = '\0';
  ASSERT(p - buffer == len);
  return String(buffer, len, AttachString);
}
开发者ID:HyeongKyu,项目名称:hiphop-php,代码行数:36,代码来源:string_util.cpp

示例10: setInterval

bool DateInterval::setInterval(CStrRef date_interval) {
  timelib_rel_time *di = NULL;
  timelib_error_container *errors = NULL;

#ifdef TIMELIB_HAVE_INTERVAL
  timelib_time *start = NULL, *end = NULL;
  int r = 0;

  timelib_strtointerval((char*)date_interval.data(), date_interval.size(),
                        &start, &end, &di, &r, &errors);
#else
  throw NotImplementedException("timelib too old");
#endif

  int error_count  = errors->error_count;
  DateTime::setLastErrors(errors);
  if (error_count > 0) {
    timelib_rel_time_dtor(di);
    return false;
  } else {
    m_di = DateIntervalPtr(di, dateinterval_deleter());
    return true;
  }
}
开发者ID:Bathrisyah,项目名称:hiphop-php,代码行数:24,代码来源:dateinterval.cpp

示例11: f_str_word_count

/**
 * Counts the number of words inside a string. If format of 1 is specified,
 * then the function will return an array containing all the words
 * found inside the string. If format of 2 is specified, then the function
 * will return an associated array where the position of the word is the key
 * and the word itself is the value.
 *
 * For the purpose of this function, 'word' is defined as a locale dependent
 * string containing alphabetic characters, which also may contain, but not
 * start with "'" and "-" characters.
 */
Variant f_str_word_count(CStrRef str, int64 format /* = 0 */,
                         CStrRef charlist /* = "" */) {
  int str_len = str.size();
  switch (format) {
  case 1:
  case 2:
    if (!str_len) {
      return Array::Create();
    }
    break;
  case 0:
    if (!str_len) {
      return 0LL;
    }
    break;
  default:
    throw_invalid_argument("format: %d", format);
    return false;
  }

  char ch[256];
  const char *char_list = charlist;
  if (*char_list) {
    string_charmask(charlist, charlist.size(), ch);
  } else {
    char_list = NULL;
  }

  int word_count = 0;
  const char *s0 = str;
  const char *p = s0;
  const char *e = p + str_len;

  // first character cannot be ' or -, unless explicitly allowed by the user
  if ((*p == '\'' && (!char_list || !ch[(int)'\''])) ||
      (*p == '-' && (!char_list || !ch[(int)'-']))) {
    p++;
  }

  // last character cannot be -, unless explicitly allowed by the user
  if (*(e - 1) == '-' && (!char_list || !ch[(int)'-'])) {
    e--;
  }

  Array ret;
  while (p < e) {
    const char *s = p;
    while (p < e &&
           (isalpha(*p) || (char_list && ch[(unsigned char)*p]) ||
            *p == '\'' || *p == '-')) {
      p++;
    }
    if (p > s) {
      switch (format) {
      case 1:
        ret.append(String(s, p - s, CopyString));
        break;
      case 2:
        ret.set((int)(s - s0), String(s, p - s, CopyString));
        break;
      default:
        word_count++;
        break;
      }
    }
    p++;
  }

  if (!format) {
    return word_count;
  }
  return ret;
}
开发者ID:mukulu,项目名称:hiphop-php,代码行数:84,代码来源:ext_string.cpp

示例12: append

void StringBuffer::append(CStrRef s) {
  append(s.data(), s.size());
  #ifdef TAINTED
  propagate_tainting2_buf(s, *this, *this);
  #endif
}
开发者ID:kreshano,项目名称:hiphop-php,代码行数:6,代码来源:string_buffer.cpp

示例13: store

bool ConcurrentTableSharedStore::store(CStrRef key, CVarRef val, int64 ttl,
                                       bool overwrite /* = true */) {
  bool stats = RuntimeOption::EnableStats && RuntimeOption::EnableAPCStats;
  bool statsDetail = RuntimeOption::EnableAPCSizeStats &&
                     RuntimeOption::EnableAPCSizeGroup;
  StoreValue *sval;
  SharedVariant* var = construct(key, val);
  ReadLock l(m_lock);

  const char *kcp = strdup(key.data());
  bool present;
  time_t expiry;
  {
    Map::accessor acc;
    present = !m_vars.insert(acc, kcp);
    sval = &acc->second;
    if (present) {
      free((void *)kcp);
      if (overwrite || sval->expired()) {
        if (statsDetail) {
          SharedStoreStats::onDelete(key.get(), sval->var, true);
        }
        sval->var->decRef();
        if (RuntimeOption::EnableAPCSizeStats && !check_skip(key.data())) {
          int32 size = var->getSpaceUsage();
          SharedStoreStats::updateDirect(sval->size, size);
          sval->size = size;
        }
      } else {
        var->decRef();
        return false;
      }
    } else {
      if (RuntimeOption::EnableAPCSizeStats) {
        int32 size = var->getSpaceUsage();
        SharedStoreStats::addDirect(key.size(), size);
        sval->size = size;
      }
    }
    sval->set(var, ttl);
    expiry = sval->expiry;
    if (statsDetail) {
      SharedStoreStats::onStore(key.get(), var, ttl, false);
    }
  }
  if (RuntimeOption::ApcExpireOnSets) {
    if (ttl) {
      addToExpirationQueue(key.data(), expiry);
    }
    purgeExpired();
  }
  if (stats) {
    if (present) {
      ServerStats::Log("apc.update", 1);
    } else {
      ServerStats::Log("apc.new", 1);
      if (RuntimeOption::EnableStats && RuntimeOption::EnableAPCKeyStats) {
        string prefix = "apc.new.";
        prefix += GetSkeleton(key);
        ServerStats::Log(prefix, 1);
      }
    }
  }

  return true;
}
开发者ID:Jostein,项目名称:hiphop-php,代码行数:66,代码来源:concurrent_shared_store.cpp

示例14: f_strcspn

Variant f_strcspn(CStrRef str1, CStrRef str2, int start /* = 0 */,
                  int length /* = 0x7FFFFFFF */) {
  String s = str1.substr(start, length);
  if (s.isNull()) return false;
  return string_cspan(s, s.size(), str2, str2.size());
}
开发者ID:mukulu,项目名称:hiphop-php,代码行数:6,代码来源:ext_string.cpp

示例15: f_gzinflate

Variant f_gzinflate(CStrRef data, int limit /* = 0 */) {
  return gzinflate(data.data(), data.size(), limit);
}
开发者ID:vincentbdb,项目名称:hiphop-php,代码行数:3,代码来源:ext_zlib.cpp


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