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


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

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


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

示例1: CDecode

String StringUtil::CDecode(CStrRef input) {
  if (input.empty()) return input;
  int len = input.size();
  char *ret = string_stripcslashes(input, len);
  return String(ret, len, AttachString);
}
开发者ID:HyeongKyu,项目名称:hiphop-php,代码行数:6,代码来源:string_util.cpp

示例2: Explode

Variant StringUtil::Explode(CStrRef input, CStrRef delimiter,
                            int limit /* = 0x7FFFFFFF */) {
  if (delimiter.empty()) {
    throw_invalid_argument("delimiter: (empty)");
    return false;
  }

  Array ret(Array::Create());

  if (input.empty()) {
    if (limit >= 0) {
      ret.append("");
    }
    return ret;
  }

  if (limit > 1) {
    int pos = input.find(delimiter);
    if (pos < 0) {
      ret.append(input);
    } else {
      int len = delimiter.size();
      int pos0 = 0;
      do {
        ret.append(input.substr(pos0, pos - pos0));
        pos += len;
        pos0 = pos;
      } while ((pos = input.find(delimiter, pos)) >= 0 && --limit > 1);

      if (pos0 <= input.size()) {
        ret.append(input.substr(pos0));
      }
    }
  } else if (limit < 0) {
    int pos = input.find(delimiter);
    if (pos >= 0) {
      vector<int> positions;
      int len = delimiter.size();
      int pos0 = 0;
      int found = 0;
      do {
        positions.push_back(pos0);
        positions.push_back(pos - pos0);
        pos += len;
        pos0 = pos;
        found++;
      } while ((pos = input.find(delimiter, pos)) >= 0);

      if (pos0 <= input.size()) {
        positions.push_back(pos0);
        positions.push_back(input.size() - pos0);
        found++;
      }
      int iMax = (found + limit) << 1;
      for (int i = 0; i < iMax; i += 2) {
        ret.append(input.substr(positions[i], positions[i+1]));
      }
    } // else we have negative limit and delimiter not found
  } else {
    ret.append(input);
  }

  return ret;
}
开发者ID:mariusz-szydzik,项目名称:hiphop-php,代码行数:64,代码来源:string_util.cpp

示例3: f_strtr

Variant f_strtr(CStrRef str, CVarRef from, CVarRef to /* = null_variant */) {
  if (str.empty()) {
    return str;
  }

  if (!to.isNull()) {
    TAINT_OBSERVER(TAINT_BIT_MUTATED, TAINT_BIT_NONE);
    return StringUtil::Translate(str, from.toString(), to.toString());
  }

  if (!from.is(KindOfArray)) {
    throw_invalid_argument("2nd argument: (not array)");
    return false;
  }

  int maxlen = 0;
  int minlen = -1;
  Array arr = from.toArray();

  if (arr.empty()) {
    // Nothing to translate
    return str;
  }

  for (ArrayIter iter(arr); iter; ++iter) {
    String search = iter.first();
    int len = search.size();
    if (len < 1) return false;
    if (maxlen < len) maxlen = len;
    if (minlen == -1 || minlen > len) minlen = len;
  }

  TAINT_OBSERVER(TAINT_BIT_MUTATED, TAINT_BIT_NONE);
  const char *s = str.data();
  int slen = str.size();
  char *key = (char *)malloc(maxlen+1);

  StringBuffer result(slen);
  for (int pos = 0; pos < slen; ) {
    if ((pos + maxlen) > slen) {
      maxlen = slen - pos;
    }
    bool found = false;
    memcpy(key, s + pos, maxlen);
    for (int len = maxlen; len >= minlen; len--) {
      key[len] = 0;
      if (arr.exists(key)) {
        String replace = arr[key].toString();
        if (!replace.empty()) {
          result += replace;
        }
        pos += len;
        found = true;
        break;
      }
    }
    if (!found) {
      result += s[pos++];
    }
  }
  free(key);

  return result.detach();
}
开发者ID:ArPharazon,项目名称:hiphop-php,代码行数:64,代码来源:ext_string.cpp

示例4: QuotedPrintableDecode

String StringUtil::QuotedPrintableDecode(CStrRef input) {
    if (input.empty()) return input;
    int len = input.size();
    char *ret = string_quoted_printable_decode(input.data(), len, false);
    return String(ret, len, AttachString);
}
开发者ID:CyaLiven,项目名称:hiphop-php,代码行数:6,代码来源:string_util.cpp

示例5: String

String StringUtil::ROT13(CStrRef input) {
    if (input.empty()) return input;
    return String(string_rot13(input.data(), input.size()),
                  input.size(), AttachString);
}
开发者ID:CyaLiven,项目名称:hiphop-php,代码行数:5,代码来源:string_util.cpp

示例6: HexEncode

String StringUtil::HexEncode(CStrRef input) {
  if (input.empty()) return input;
  int len = input.size();
  char *ret = string_bin2hex(input, len);
  return String(ret, len, AttachString);
}
开发者ID:HyeongKyu,项目名称:hiphop-php,代码行数:6,代码来源:string_util.cpp

示例7: RegExEncode

String StringUtil::RegExEncode(CStrRef input) {
    if (input.empty()) return input;
    int len = input.size();
    char *ret = string_quotemeta(input.c_str(), len);
    return String(ret, len, AttachString);
}
开发者ID:CyaLiven,项目名称:hiphop-php,代码行数:6,代码来源:string_util.cpp

示例8: f_mcrypt_module_self_test

bool f_mcrypt_module_self_test(CStrRef algorithm,
                               CStrRef lib_dir /* = null_string */) {
  String dir = lib_dir.empty() ? MCG(algorithms_dir) : lib_dir;
  return mcrypt_module_self_test((char*)algorithm.data(),
                                 (char*)dir.data()) == 0;
}
开发者ID:scottmac,项目名称:hiphop-dev,代码行数:6,代码来源:ext_mcrypt.cpp

示例9: php_mcrypt_do_crypt

static Variant php_mcrypt_do_crypt(CStrRef cipher, CStrRef key, CStrRef data,
                                   CStrRef mode, CStrRef iv, bool dencrypt) {
  MCRYPT td = mcrypt_module_open((char*)cipher.data(),
                                 (char*)MCG(algorithms_dir).data(),
                                 (char*)mode.data(),
                                 (char*)MCG(modes_dir).data());
  if (td == MCRYPT_FAILED) {
    raise_warning(MCRYPT_OPEN_MODULE_FAILED);
    return false;
  }

  /* Checking for key-length */
  int max_key_length = mcrypt_enc_get_key_size(td);
  if (key.size() > max_key_length) {
    raise_warning("Size of key is too large for this algorithm");
  }
  int count;
  int *key_length_sizes = mcrypt_enc_get_supported_key_sizes(td, &count);
  int use_key_length;
  char *key_s = NULL;
  if (count == 0 && key_length_sizes == NULL) { // all lengths 1 - k_l_s = OK
    use_key_length = key.size();
    key_s = (char*)malloc(use_key_length);
    memcpy(key_s, key.data(), use_key_length);
  } else if (count == 1) {  /* only m_k_l = OK */
    key_s = (char*)malloc(key_length_sizes[0]);
    memset(key_s, 0, key_length_sizes[0]);
    memcpy(key_s, key.data(), MIN(key.size(), key_length_sizes[0]));
    use_key_length = key_length_sizes[0];
  } else { /* dertermine smallest supported key > length of requested key */
    use_key_length = max_key_length; /* start with max key length */
    for (int i = 0; i < count; i++) {
      if (key_length_sizes[i] >= key.size() &&
          key_length_sizes[i] < use_key_length) {
        use_key_length = key_length_sizes[i];
      }
    }
    key_s = (char*)malloc(use_key_length);
    memset(key_s, 0, use_key_length);
    memcpy(key_s, key.data(), MIN(key.size(), use_key_length));
  }
  mcrypt_free(key_length_sizes);

  /* Check IV */
  char *iv_s = NULL;
  int iv_size = mcrypt_enc_get_iv_size(td);
  if (!iv.empty()) {
    if (iv_size != iv.size()) {
      raise_warning("The IV parameter must be as long as the blocksize");
    } else {
      iv_s = (char*)malloc(iv_size + 1);
      memcpy(iv_s, iv.data(), iv_size);
    }
  } else if (iv_size != 0) {
    raise_warning("Attempt to use an empty IV, which is NOT recommended");
    iv_s = (char*)malloc(iv_size + 1);
    memset(iv_s, 0, iv_size + 1);
  }

  int block_size;
  unsigned long int data_size;
  char *data_s;
  /* Check blocksize */
  if (mcrypt_enc_is_block_mode(td) == 1) { /* It's a block algorithm */
    block_size = mcrypt_enc_get_block_size(td);
    data_size = (((data.size() - 1) / block_size) + 1) * block_size;
    data_s = (char*)malloc(data_size + 1);
    memset(data_s, 0, data_size);
    memcpy(data_s, data.data(), data.size());
  } else { /* It's not a block algorithm */
    data_size = data.size();
    data_s = (char*)malloc(data_size + 1);
    memcpy(data_s, data.data(), data.size());
  }

  if (mcrypt_generic_init(td, key_s, use_key_length, iv_s) < 0) {
    raise_warning("Mcrypt initialisation failed");
    return false;
  }
  if (dencrypt) {
    mdecrypt_generic(td, data_s, data_size);
  } else {
    mcrypt_generic(td, data_s, data_size);
  }
  data_s[data_size] = '\0';

  String ret(data_s, data_size, AttachString);

  /* freeing vars */
  mcrypt_generic_end(td);
  if (key_s != NULL) {
    free(key_s);
  }
  if (iv_s != NULL) {
    free(iv_s);
  }
  return ret;
}
开发者ID:scottmac,项目名称:hiphop-dev,代码行数:98,代码来源:ext_mcrypt.cpp

示例10: f_mcrypt_module_is_block_algorithm

bool f_mcrypt_module_is_block_algorithm(CStrRef algorithm,
                                        CStrRef lib_dir /* = null_string */) {
  String dir = lib_dir.empty() ? MCG(algorithms_dir) : lib_dir;
  return mcrypt_module_is_block_algorithm((char*)algorithm.data(),
                                          (char*)dir.data()) == 1;
}
开发者ID:scottmac,项目名称:hiphop-dev,代码行数:6,代码来源:ext_mcrypt.cpp

示例11: f_mcrypt_module_is_block_mode

bool f_mcrypt_module_is_block_mode(CStrRef mode,
                                   CStrRef lib_dir /* = null_string */) {
  String dir = lib_dir.empty() ? MCG(modes_dir) : lib_dir;
  return mcrypt_module_is_block_mode((char*)mode.data(),
                                     (char*)dir.data()) == 1;
}
开发者ID:scottmac,项目名称:hiphop-dev,代码行数:6,代码来源:ext_mcrypt.cpp

示例12: f_mcrypt_module_get_algo_key_size

int f_mcrypt_module_get_algo_key_size(CStrRef algorithm,
                                      CStrRef lib_dir /* = null_string */) {
  String dir = lib_dir.empty() ? MCG(algorithms_dir) : lib_dir;
  return mcrypt_module_get_algo_key_size((char*)algorithm.data(),
                                         (char*)dir.data());
}
开发者ID:scottmac,项目名称:hiphop-dev,代码行数:6,代码来源:ext_mcrypt.cpp

示例13: NEW

HOT_FUNC
String String::operator+(CStrRef str) const {
  if (empty()) return str;
  if (str.empty()) return *this;
  return NEW(StringData)(slice(), str.slice());
}
开发者ID:BauerBox,项目名称:hiphop-php,代码行数:6,代码来源:type_string.cpp

示例14: f_posix_initgroups

bool f_posix_initgroups(CStrRef name, int base_group_id) {
  if (name.empty()) return false;
  return !initgroups(name.data(), base_group_id);
}
开发者ID:CyaLiven,项目名称:hiphop-php,代码行数:4,代码来源:ext_posix.cpp

示例15: ToLower

String StringUtil::ToLower(CStrRef input) {
  if (input.empty()) return input;
  int len = input.size();
  char *ret = string_to_lower(input.data(), len);
  return String(ret, len, AttachString);
}
开发者ID:HyeongKyu,项目名称:hiphop-php,代码行数:6,代码来源:string_util.cpp


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