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


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

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


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

示例1: t_compare

Variant c_Collator::t_compare(CStrRef str1, CStrRef str2) {
  INSTANCE_METHOD_INJECTION_BUILTIN(Collator, Collator::compare);
  if (!m_ucoll) {
    raise_warning("compare called on uninitialized Collator object");
    return 0;
  }
  UChar* ustr1 = NULL;
  UChar* ustr2 = NULL;
  int ustr1_len = 0;
  int ustr2_len = 0;
  m_errcode.clear();
  intl_convert_utf8_to_utf16(&ustr1, &ustr1_len,
                             str1.data(), str1.length(),
                             &(m_errcode.code));
  if (U_FAILURE(m_errcode.code)) {
    free(ustr1);
    return false;
  }
  intl_convert_utf8_to_utf16(&ustr2, &ustr2_len,
                             str2.data(), str2.length(),
                             &(m_errcode.code));
  if (U_FAILURE(m_errcode.code)) {
    free(ustr1);
    free(ustr2);
    return false;
  }
  int64 ret = ucol_strcoll(m_ucoll, ustr1, ustr1_len, ustr2, ustr2_len);
  free(ustr1);
  free(ustr2);
  return ret;
}
开发者ID:cdnewbee,项目名称:hiphop-php,代码行数:31,代码来源:ext_intl.cpp

示例2: f_bzcompress

Variant f_bzcompress(CStrRef source, int blocksize /* = 4 */,
                     int workfactor /* = 0 */) {
  char *dest = NULL;
  int error;
  unsigned int source_len, dest_len;

  source_len = source.length();
  dest_len = source.length() + (0.01*source.length()) + 600;

  if (!(dest = (char *)malloc(dest_len + 1))) {
    return BZ_MEM_ERROR;
  }

  error = BZ2_bzBuffToBuffCompress(dest, &dest_len, (char *) source.c_str(),
                                   source_len, blocksize, 0, workfactor);
  if (error != BZ_OK) {
    free(dest);
    return error;
  } else {
    // this is to shrink the allocation, since we probably over allocated
    dest = (char *)realloc(dest, dest_len + 1);
    dest[dest_len] = '\0';
    String ret = String(dest, dest_len, AttachString);
    return ret;
  }
}
开发者ID:AviMoto,项目名称:hiphop-php,代码行数:26,代码来源:ext_bzip2.cpp

示例3: f_icu_transliterate

String f_icu_transliterate(CStrRef str, bool remove_accents) {
#if HAVE_OLD_LIBICU
  // inspired by the UnicodeString::setToUTF8 implementation
  int32_t length = str.length();
  int32_t bytesWritten=0;
  UnicodeString u_str;
  u_strFromUTF8WithSub(u_str.getBuffer(length+1), length+1, &bytesWritten,
      str.data(), length, 0xfffd, NULL, NULL);
  u_str.releaseBuffer(bytesWritten);
#else
  UnicodeString u_str = UnicodeString::fromUTF8(str.data());
#endif
  if (remove_accents) {
    s_transliterator->transliterate(u_str);
  } else {
    s_transliterator->transliterate_with_accents(u_str);
  }

  // Convert the UnicodeString back into a UTF8 String.
#if HAVE_OLD_LIBICU
  return icuStringToUTF8(u_str);
#else
  int32_t capacity = u_str.countChar32() * sizeof(UChar) + 1;
  char* out = (char *)malloc(capacity);
  CheckedArrayByteSink bs(out, capacity);
  u_str.toUTF8(bs);

  return String(out, AttachString);
#endif
}
开发者ID:d1saster,项目名称:hiphop-php,代码行数:30,代码来源:ext_icu.cpp

示例4: f_defined

bool f_defined(CStrRef name, bool autoload /* = true */) {
  if (!name.get()) return false;
  const char *data = name.data();
  int len = name.length();

  // slice off starting backslash
  bool hadInitialBackslash = false;
  if (len > 0 && data[0] == '\\') {
    data += 1;
    len -= 1;
    hadInitialBackslash = true;
  }

  char *colon;
  if ((colon = (char*)memchr(data, ':', len)) && colon[1] == ':') {
    // class constant
    int classNameLen = colon - data;
    char *constantName = colon + 2;
    Class* cls = getClassByName(data, classNameLen);
    if (cls) {
      String cnsName(constantName, data + len - constantName, CopyString);
      return cls->clsCnsGet(cnsName.get());
    }
    return false;
  } else {
    auto* cb = autoload ? Unit::loadCns : Unit::lookupCns;
    if (hadInitialBackslash) {
      String s(data, len, CopyString);
      return cb(s.get());
    } else {
      return cb(name.get());
    }
  }
}
开发者ID:TingoZhou,项目名称:hiphop-php,代码行数:34,代码来源:ext_misc.cpp

示例5: f_constant

Variant f_constant(CStrRef name) {
  if (!name.get()) return uninit_null();
  const char *data = name.data();
  int len = name.length();
  char *colon;
  if ((colon = (char*)memchr(data, ':', len)) && colon[1] == ':') {
    // class constant
    int classNameLen = colon - data;
    char *constantName = colon + 2;
    VM::Class* cls = getClassByName(data, classNameLen);
    if (cls) {
      String cnsName(constantName, data + len - constantName, CopyString);
      TypedValue* tv = cls->clsCnsGet(cnsName.get());
      if (tv) {
        return tvAsCVarRef(tv);
      }
    }
    raise_warning("Couldn't find constant %s", data);
    return uninit_null();
  } else {
    TypedValue* cns = VM::Unit::loadCns(name.get());
    if (cns) return tvAsVariant(cns);
    return uninit_null();
  }
}
开发者ID:jobin-sun,项目名称:hiphop-php,代码行数:25,代码来源:ext_misc.cpp

示例6: getMultiImpl

bool c_Memcached::getMultiImpl(CStrRef server_key, CArrRef keys,
                               bool enableCas, Array *returnValue) {
  vector<const char*> keysCopy;
  keysCopy.reserve(keys.size());
  vector<size_t> keysLengthCopy;
  keysLengthCopy.reserve(keys.size());
  for (ArrayIter iter(keys); iter; ++iter) {
    Variant vKey = iter.second();
    if (!vKey.isString()) continue;
    StringData *key = vKey.getStringData();
    if (key->empty()) continue;
    keysCopy.push_back(key->data());
    keysLengthCopy.push_back(key->size());
    if (returnValue) returnValue->set(String(key), null_variant, true);
  }
  if (keysCopy.size() == 0) {
    m_impl->rescode = q_Memcached_RES_BAD_KEY_PROVIDED;
    return false;
  }

  memcached_behavior_set(&m_impl->memcached, MEMCACHED_BEHAVIOR_SUPPORT_CAS,
                         enableCas ? 1 : 0);
  const char *myServerKey = server_key.empty() ? NULL : server_key.c_str();
  size_t myServerKeyLen = server_key.length();
  return handleError(memcached_mget_by_key(&m_impl->memcached,
      myServerKey, myServerKeyLen, keysCopy.data(), keysLengthCopy.data(),
      keysCopy.size()));
}
开发者ID:HyeongKyu,项目名称:hiphop-php,代码行数:28,代码来源:ext_memcached.cpp

示例7: virtualFileExists

bool RequestURI::virtualFileExists(const VirtualHost *vhost,
                                   const string &sourceRoot,
                                   const string &pathTranslation,
                                   CStrRef filename) {
  if (filename.empty() || filename.charAt(filename.length() - 1) == '/') {
    return false;
  }
  if (!vhost->getDocumentRoot().empty()) {
    string fullname = filename.data();
    if (fullname[0] == '/') {
      fullname = fullname.substr(1);
    } else {
      fullname = pathTranslation + fullname;
    }
    m_path = fullname;
    m_absolutePath = String(sourceRoot) + m_path;

    if (StaticContentCache::TheFileCache && !fullname.empty() &&
        StaticContentCache::TheFileCache->fileExists(fullname.c_str())) {
      return true;
    }

    struct stat st;
    return RuntimeOption::AllowedFiles.find(fullname.c_str()) !=
      RuntimeOption::AllowedFiles.end() ||
      (stat(m_absolutePath.c_str(), &st) == 0 &&
       (st.st_mode & S_IFMT) == S_IFREG);
  }
  m_path = filename;
  m_absolutePath = String(sourceRoot) + filename;
  return true;
}
开发者ID:dipjyotighosh,项目名称:hiphop-php,代码行数:32,代码来源:request_uri.cpp

示例8: f_constant

Variant f_constant(CStrRef name) {
  if (!name.get()) return null;
  const char *data = name.data();
  int len = name.length();
  char *colon;
  if ((colon = (char*)memchr(data, ':', len)) && colon[1] == ':') {
    // class constant
    int classNameLen = colon - data;
    char *constantName = colon + 2;
    String className(data, classNameLen, CopyString);

    // translate "self" or "parent"
    if (className == "self") {
      String this_class = hhvm
        ? g_vmContext->getContextClassName()
        : FrameInjection::GetClassName(true);
      if (this_class.empty()) {
        throw FatalErrorException("Cannot access self:: "
                                  "when no class scope is active");
      } else {
        className = this_class;
      }
    } else if (className == "parent") {
      String parent_class = hhvm
        ? g_vmContext->getParentContextClassName()
        : FrameInjection::GetParentClassName(true);
      if (parent_class.empty()) {
        throw FatalErrorException("Cannot access parent");
      } else {
        className = parent_class;
      }
    }
    // taking care of volatile class
    if (class_exists(className)) {
      return get_class_constant(className, constantName, false);
    } else {
      return null;
    }
  } else {
    if (hhvm) {
      TypedValue* cns = g_vmContext->getCns(name.get());
      if (cns == NULL) {
        if (AutoloadHandler::s_instance->autoloadConstant(name)) {
          cns = g_vmContext->getCns(name.get());
        }
      }
      if (cns) return tvAsVariant(cns);
      return null;
    } else {
      const ClassInfo::ConstantInfo *cinfo = ClassInfo::FindConstant(name);
      // system/uniquely defined scalar constant (must be valid)
      if (cinfo) return cinfo->getValue();
      if (!((Globals*)get_global_variables())->defined(name)) {
        AutoloadHandler::s_instance->autoloadConstant(name);
      }
      // dynamic/redeclared constant
      return ((Globals*)get_global_variables())->getConstant(name.data());
    }
  }
}
开发者ID:Chuwiey,项目名称:hiphop-php,代码行数:60,代码来源:ext_misc.cpp

示例9: Trim

String StringUtil::Trim(CStrRef input, TrimType type  /* = TrimBoth */,
                        CStrRef charlist /* = k_HPHP_TRIM_CHARLIST */) {
  if (input.empty()) return input;
  int len = input.size();
  char *ret = string_trim(input.data(), len,
                          charlist.data(), charlist.length(), type);
  return String(ret, len, AttachString);
}
开发者ID:HyeongKyu,项目名称:hiphop-php,代码行数:8,代码来源:string_util.cpp

示例10: t_casbykey

bool c_Memcached::t_casbykey(double cas_token, CStrRef server_key, CStrRef key,
                             CVarRef value, int expiration /*= 0*/) {
  INSTANCE_METHOD_INJECTION_BUILTIN(Memcached, Memcached::casbykey);
  m_impl->rescode = q_Memcached_RES_SUCCESS;
  if (key.empty()) {
    m_impl->rescode = q_Memcached_RES_BAD_KEY_PROVIDED;
    return false;
  }

  vector<char> payload; uint32 flags;
  toPayload(value, payload, flags);

  CStrRef myServerKey = server_key.empty() ? key : server_key;
  return handleError(memcached_cas_by_key(&m_impl->memcached,
      myServerKey.c_str(), myServerKey.length(), key.c_str(), key.length(),
      payload.data(), payload.size(), expiration, flags, (uint64)cas_token));
}
开发者ID:HyeongKyu,项目名称:hiphop-php,代码行数:17,代码来源:ext_memcached.cpp

示例11: setOperationImpl

bool c_Memcached::setOperationImpl(SetOperation op, CStrRef server_key,
                                   CStrRef key, CVarRef value,
                                   int expiration) {
  m_impl->rescode = q_Memcached_RES_SUCCESS;
  if (key.empty()) {
    m_impl->rescode = q_Memcached_RES_BAD_KEY_PROVIDED;
    return false;
  }

  vector<char> payload; uint32 flags;
  toPayload(value, payload, flags);

  CStrRef myServerKey = server_key.empty() ? key : server_key;
  return handleError(op(&m_impl->memcached, myServerKey.c_str(),
                        myServerKey.length(), key.c_str(), key.length(),
                        payload.data(), payload.size(), expiration, flags));
}
开发者ID:HyeongKyu,项目名称:hiphop-php,代码行数:17,代码来源:ext_memcached.cpp

示例12: t_format

String c_DateInterval::t_format(CStrRef format) {
  INSTANCE_METHOD_INJECTION_BUILTIN(DateInterval, DateInterval::format);
  StringBuffer s;
  const int LENGTH = 33;
  char buf[LENGTH];
  int l;
  bool hasFormatSpec = false;
  for (int i = 0; i < format.length(); ++i) {
    char c = format.charAt(i);
    if (!hasFormatSpec) {
      if (c == '%') {
        hasFormatSpec = true;
      } else {
        s.append(c);
      }
    } else {
      switch (c) {
      case 'Y': l = snprintf(buf, LENGTH, "%02lld", m_y); break;
      case 'y': l = snprintf(buf, LENGTH, "%lld", m_y); break;

      case 'M': l = snprintf(buf, LENGTH, "%02lld", m_m); break;
      case 'm': l = snprintf(buf, LENGTH, "%lld", m_m); break;

      case 'D': l = snprintf(buf, LENGTH, "%02lld", m_d); break;
      case 'd': l = snprintf(buf, LENGTH, "%lld", m_d); break;

      case 'H': l = snprintf(buf, LENGTH, "%02lld", m_h); break;
      case 'h': l = snprintf(buf, LENGTH, "%lld", m_h); break;

      case 'I': l = snprintf(buf, LENGTH, "%02lld", m_i); break;
      case 'i': l = snprintf(buf, LENGTH, "%lld", m_i); break;

      case 'S': l = snprintf(buf, LENGTH, "%02lld", m_s); break;
      case 's': l = snprintf(buf, LENGTH, "%lld", m_s); break;

      case 'a': {
        if (m_days.isInteger()) {
          l = snprintf(buf, LENGTH, "%lld", m_days.toInt64());
        } else {
          l = snprintf(buf, LENGTH, "(unknown)");
        }
        break;
      }

      case 'r': l = snprintf(buf, LENGTH, "%s", m_invert ? "-" : ""); break;
      case 'R': l = snprintf(buf, LENGTH, "%c", m_invert ? '-' : '+'); break;

      case '%': l = snprintf(buf, 32, "%%"); break;
      default: buf[0] = '%'; buf[1] = c; buf[2] = '\0'; l = 2; break;
      }

      s.append(buf, std::min(l, LENGTH - 1));
      hasFormatSpec = false;
    }
  }
  return s.detach();
}
开发者ID:lcastelli,项目名称:hiphop-php,代码行数:57,代码来源:ext_datetime.cpp

示例13: t_getbykey

Variant c_Memcached::t_getbykey(CStrRef server_key, CStrRef key,
                                CVarRef cache_cb /*= null_variant*/,
                                VRefParam cas_token /*= null_variant*/) {
  INSTANCE_METHOD_INJECTION_BUILTIN(Memcached, Memcached::getbykey);
  m_impl->rescode = q_Memcached_RES_SUCCESS;
  if (key.empty()) {
    m_impl->rescode = q_Memcached_RES_BAD_KEY_PROVIDED;
    return false;
  }

  memcached_behavior_set(&m_impl->memcached, MEMCACHED_BEHAVIOR_SUPPORT_CAS,
                         cas_token.isReferenced() ? 1 : 0);
  const char *myServerKey = server_key.empty() ? NULL : server_key.c_str();
  size_t myServerKeyLen = server_key.length();
  const char *myKey = key.c_str();
  size_t myKeyLen = key.length();
  memcached_return status = memcached_mget_by_key(&m_impl->memcached,
      myServerKey, myServerKeyLen, &myKey, &myKeyLen, 1);
  if (!handleError(status)) return false;

  Variant returnValue;
  MemcachedResultWrapper result(&m_impl->memcached);
  if (!memcached_fetch_result(&m_impl->memcached, &result.value, &status)) {
    if (status == MEMCACHED_END) status = MEMCACHED_NOTFOUND;
    if (status == MEMCACHED_NOTFOUND && !cache_cb.isNull()) {
      status = doCacheCallback(cache_cb, key, returnValue);
      if (!handleError(status)) return false;
      if (cas_token.isReferenced()) cas_token = 0.0;
      return returnValue;
    }
    handleError(status);
    return false;
  }

  if (!toObject(returnValue, result.value)) {
    m_impl->rescode = q_Memcached_RES_PAYLOAD_FAILURE;
    return false;
  }
  if (cas_token.isReferenced()) {
    cas_token = (double) memcached_result_cas(&result.value);
  }
  return returnValue;
}
开发者ID:HyeongKyu,项目名称:hiphop-php,代码行数:43,代码来源:ext_memcached.cpp

示例14: f_defined

bool f_defined(CStrRef name, bool autoload /* = true */) {
  if (!name.get()) return false;
  const char *data = name.data();
  int len = name.length();
  char *colon;
  if ((colon = (char*)memchr(data, ':', len)) && colon[1] == ':') {
    // class constant
    int classNameLen = colon - data;
    char *constantName = colon + 2;
    String className(data, classNameLen, CopyString);

    // translate "self" or "parent"
    if (className == "self") {
      String this_class = g_vmContext->getContextClassName();
      if (this_class.empty()) {
        throw FatalErrorException("Cannot access self:: "
          "when no class scope is active");
      } else {
        className = this_class;
      }
    } else if (className == "parent") {
      String parent_class = g_vmContext->getParentContextClassName();
      if (parent_class.empty()) {
        throw FatalErrorException("Cannot access parent");
      } else {
        className = parent_class;
      }
    }
    if (class_exists(className)) { // taking care of volatile class
      const ClassInfo *info;
      for (String parentClass = className;
           !parentClass.empty();
           parentClass = info->getParentClass()) {
        info = ClassInfo::FindClass(parentClass);
        if (!info) {
          assert(false);
        }
        if (info->hasConstant(constantName)) return true;
      }
      return false;
    } else {
      return false;
    }
  } else {
    // system/uniquely defined scalar constant
    if (ClassInfo::FindConstant(name)) return true;
    if (g_vmContext->defined(name)) {
      return true;
    }
    if (!autoload || !AutoloadHandler::s_instance->autoloadConstant(name)) {
      return false;
    }
    return g_vmContext->defined(name);
  }
}
开发者ID:sclin,项目名称:hiphop-php,代码行数:55,代码来源:ext_misc.cpp

示例15: t_delete

bool c_Memcache::t_delete(CStrRef key, int expire /*= 0*/) {
  if (key.empty()) {
    raise_warning("Key cannot be empty");
    return false;
  }

  memcached_return_t ret = memcached_delete(&m_memcache,
                                            key.c_str(), key.length(),
                                            expire);
  return (ret == MEMCACHED_SUCCESS);
}
开发者ID:CyaLiven,项目名称:hiphop-php,代码行数:11,代码来源:ext_memcache.cpp


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