Esempio n. 1
0
double VariantToMilliseconds(CVarRef arg) {
  if (arg.isNumeric(true)) {
    return U_MILLIS_PER_SECOND * arg.toDouble();
  }
  // TODO: Handle object IntlCalendar and DateTime
  return NAN;
}
Esempio n. 2
0
String static memcache_prepare_for_storage(CVarRef var, int &flag) {
  if (var.isString()) {
    return var.toString();
  } else if (var.isNumeric() || var.isBoolean()) {
    return var.toString();
  } else {
    flag |= MMC_SERIALIZED;
    return f_serialize(var);
  }
}
Esempio n. 3
0
void f_mt_srand(CVarRef seed /* = null_variant */) {
  if (seed.isNull()) {
    return math_mt_srand(math_generate_seed());
  }
  if (seed.isNumeric(true)) {
    math_mt_srand(seed.toInt32());
  } else {
    raise_warning("mt_srand() expects parameter 1 to be long");
  }
}
Esempio n. 4
0
static Variant HHVM_STATIC_METHOD(IntlTimeZone, createEnumeration,
                                  CVarRef countryRawOffset) {
  icu::StringEnumeration *se = nullptr;

  if (countryRawOffset.isNull()) {
    se = icu::TimeZone::createEnumeration();
  } else if (countryRawOffset.isNumeric(true)) {
    se = icu::TimeZone::createEnumeration((int32_t)countryRawOffset.toInt64());
  } else if (countryRawOffset.isString() || countryRawOffset.isObject()) {
    se = icu::TimeZone::createEnumeration(countryRawOffset.toString().c_str());
  } else {
    s_intl_error->set(U_ILLEGAL_ARGUMENT_ERROR,
                      "intltz_create_enumeration: invalid argument type");
    return false;
  }
  return IntlIterator::newInstance(se);
}
Esempio n. 5
0
void MapVariant::merge(const MapVariant *srcMap, ArrayOp op) {
    const HphpVector<Variant*> &elems = srcMap->m_elems;
    const std::vector<Variant> &keys = srcMap->getKeyVector();
    unsigned int size = keys.size();
    if (op == Plus) {
        m_elems.reserve(m_elems.size() + elems.size());
        for (unsigned int i = 0; i < size; i++) {
            CVarRef key = keys[i];
            int index = getIndex(key);
            if (index < 0) {
                insertKey(key);
                Variant * elem;
                ArrayFuncs::element(elem, elems[i]);
                m_elems.push_back(elem);
            }
        }
    } else {
        ASSERT(op == Merge);
        for (unsigned int i = 0; i < size; i++) {
            CVarRef key = keys[i];
            Variant * elem;
            ArrayFuncs::element(elem, elems[i]);
            if (key.isNumeric()) {
                appendKey();
                m_elems.push_back(elem);
            } else {
                int index = getIndex(key);
                if (index < 0) {
                    insertKey(key);
                    m_elems.push_back(elem);
                } else {
                    ArrayFuncs::set(m_elems, index, elem);
                }
            }
        }
    }
}
Esempio n. 6
0
bool f_is_numeric(CVarRef v) {
  return v.isNumeric(true);
}