コード例 #1
0
ファイル: ext_datetime.cpp プロジェクト: lcastelli/hiphop-php
Object c_DateInterval::ti_createfromdatestring(const char* cls , CStrRef time) {
  STATIC_METHOD_INJECTION_BUILTIN(DateInterval, DateInterval::createfromdatestring);
  DateTime datetime;
  datetime.fromString(time, SmartObject<TimeZone>());
  c_DateInterval *interval = NEWOBJ(c_DateInterval);
  rel_time_to_interval(datetime.getRelTime(), interval);
  return interval;
}
コード例 #2
0
ファイル: ext_datetime.cpp プロジェクト: lcastelli/hiphop-php
Object c_DateTime::ti_createfromformat(const char* cls , CStrRef format,
                                       CStrRef time,
                                       CObjRef timezone /*= null_object*/) {
  STATIC_METHOD_INJECTION_BUILTIN(DateTime, DateTime::createfromformat);
  c_DateTime *datetime = NEWOBJ(c_DateTime);
  datetime->m_dt = NEWOBJ(DateTime);
  datetime->m_dt->fromString(time, c_DateTimeZone::unwrap(timezone),
                             format.data());
  return datetime;
}
コード例 #3
0
Object c_StaticExceptionWaitHandle::ti_create(const char* cls, CObjRef exception) {
  if (!exception.instanceof("Exception")) {
    STATIC_METHOD_INJECTION_BUILTIN(StaticExceptionWaitHandle, StaticExceptionWaitHandle::create);
    Object e(SystemLib::AllocInvalidArgumentExceptionObject(
        "Expected exception to be an instance of Exception"));
    throw e;
  }

  p_StaticExceptionWaitHandle wh = NEWOBJ(c_StaticExceptionWaitHandle)();
  tvWriteObject(exception.get(), &wh->m_resultOrException);
  return wh;
}
コード例 #4
0
ファイル: ext_intl.cpp プロジェクト: cdnewbee/hiphop-php
Variant c_Normalizer::ti_isnormalized(const char* cls , CStrRef input,
                                      int64 form /* = q_Normalizer___FORM_C */) {
  STATIC_METHOD_INJECTION_BUILTIN(Normalizer, Normalizer::isnormalized);
  s_intl_error->m_error.clear();

  switch (form) {
  case UNORM_NFD:
  case UNORM_NFKD:
  case UNORM_NFC:
  case UNORM_NFKC:
    break;
  default:
    s_intl_error->m_error.code = U_ILLEGAL_ARGUMENT_ERROR;
    s_intl_error->m_error.custom_error_message =
      "normalizer_isnormalized: illegal normalization form";
    return null;
  }

  /* First convert the string to UTF-16. */
  UChar* uinput = NULL; int uinput_len = 0;
  UErrorCode status = U_ZERO_ERROR;
  intl_convert_utf8_to_utf16(&uinput, &uinput_len, input.data(), input.size(),
                             &status);

  if (U_FAILURE(status)) {
    s_intl_error->m_error.code = status;
    s_intl_error->m_error.custom_error_message = "Error converting string to UTF-16.";
    free(uinput);
    return false;
  }

  /* test string */
  UBool uret = unorm_isNormalizedWithOptions(uinput, uinput_len,
                                             (UNormalizationMode)form,
                                             (int32_t)0, &status);
  free(uinput);

  /* Bail out if an unexpected error occured. */
  if (U_FAILURE(status)) {
    s_intl_error->m_error.code = status;
    s_intl_error->m_error.custom_error_message =
      "Error testing if string is the given normalization form.";
    return false;
  }

  return uret;
}
コード例 #5
0
ファイル: ext_intl.cpp プロジェクト: cdnewbee/hiphop-php
Variant c_Normalizer::ti_normalize(const char* cls , CStrRef input,
                                   int64 form /* = q_Normalizer___FORM_C */) {
  STATIC_METHOD_INJECTION_BUILTIN(Normalizer, Normalizer::normalize);
  s_intl_error->m_error.clear();

  int expansion_factor = 1;
  switch(form) {
  case UNORM_NONE:
  case UNORM_NFC:
  case UNORM_NFKC:
    break;
  case UNORM_NFD:
  case UNORM_NFKD:
    expansion_factor = 3;
    break;
  default:
    s_intl_error->m_error.code = U_ILLEGAL_ARGUMENT_ERROR;
    s_intl_error->m_error.custom_error_message =
      "normalizer_normalize: illegal normalization form";
    return null;
  }

  /* First convert the string to UTF-16. */
  UChar* uinput = NULL; int uinput_len = 0;
  UErrorCode status = U_ZERO_ERROR;
  intl_convert_utf8_to_utf16(&uinput, &uinput_len, input.data(), input.size(),
                             &status);

  if (U_FAILURE(status)) {
    s_intl_error->m_error.code = status;
    s_intl_error->m_error.custom_error_message =
        "Error converting string to UTF-16.";
    free(uinput);
    return null;
  }

  /* Allocate memory for the destination buffer for normalization */
  int uret_len = uinput_len * expansion_factor;
  UChar *uret_buf = (UChar*)malloc((uret_len + 1) * sizeof(UChar));

  /* normalize */
  int size_needed = unorm_normalize(uinput, uinput_len,
                                    (UNormalizationMode)form, (int32_t) 0,
                                    uret_buf, uret_len, &status);

  /* Bail out if an unexpected error occured.
   * (U_BUFFER_OVERFLOW_ERROR means that *target buffer is not large enough).
   * (U_STRING_NOT_TERMINATED_WARNING usually means that the input string
   * is empty).
   */
  if (U_FAILURE(status) &&
      status != U_BUFFER_OVERFLOW_ERROR &&
      status != U_STRING_NOT_TERMINATED_WARNING) {
    free(uret_buf);
    free(uinput);
    return null;
  }

  if (size_needed > uret_len) {
    /* realloc does not seem to work properly - memory is corrupted
     * uret_buf =  eurealloc(uret_buf, size_needed + 1); */
    free(uret_buf);
    uret_buf = (UChar*)malloc((size_needed + 1) * sizeof(UChar));
    uret_len = size_needed;

    status = U_ZERO_ERROR;

    /* try normalize again */
    size_needed = unorm_normalize( uinput, uinput_len,
                                   (UNormalizationMode)form, (int32_t) 0,
                                   uret_buf, uret_len, &status);

    /* Bail out if an unexpected error occured. */
    if (U_FAILURE(status)) {
      /* Set error messages. */
      s_intl_error->m_error.code = status;
      s_intl_error->m_error.custom_error_message = "Error normalizing string";
      free(uret_buf);
      free(uinput);
      return null;
    }
  }

  free(uinput);

  /* the buffer we actually used */
  uret_len = size_needed;

  /* Convert normalized string from UTF-16 to UTF-8. */
  char* ret_buf = NULL; int ret_len = 0;
  intl_convert_utf16_to_utf8(&ret_buf, &ret_len, uret_buf, uret_len, &status);
  free(uret_buf);
  if (U_FAILURE(status)) {
    s_intl_error->m_error.code = status;
    s_intl_error->m_error.custom_error_message =
      "normalizer_normalize: error converting normalized text UTF-8";
    return null;
  }

  return String(ret_buf, ret_len, AttachString);
}
コード例 #6
0
ファイル: ext_intl.cpp プロジェクト: cdnewbee/hiphop-php
Variant c_Collator::ti_create(const char* cls, CStrRef locale) {
  STATIC_METHOD_INJECTION_BUILTIN(Collator, Collator::create);
  return (NEWOBJ(c_Collator)())->create(locale);
}
コード例 #7
0
ファイル: exception.cpp プロジェクト: KWMalik/hiphop-php
/* SRC: classes/exception.php line 174 */
void c_Exception::t_settraceoptions(CVarRef v_opts) {
  STATIC_METHOD_INJECTION_BUILTIN(Exception, Exception::setTraceOptions);
  g->s_Exception$$traceOpts.assignVal(v_opts);
}
コード例 #8
0
ファイル: exception.cpp プロジェクト: KWMalik/hiphop-php
/* SRC: classes/exception.php line 170 */
Variant c_Exception::t_gettraceoptions() {
  STATIC_METHOD_INJECTION_BUILTIN(Exception, Exception::getTraceOptions);
  return g->s_Exception$$traceOpts;
}
コード例 #9
0
ファイル: ext_datetime.cpp プロジェクト: hashaash/hiphop-php
Array c_DateTimeZone::ti_listidentifiers(const char* cls) {
  STATIC_METHOD_INJECTION_BUILTIN(DateTimeZone, DateTimeZone::listidentifiers);
  return TimeZone::GetNames();
}
コード例 #10
0
ファイル: ext_datetime.cpp プロジェクト: hashaash/hiphop-php
Array c_DateTimeZone::ti_listabbreviations(const char* cls) {
  STATIC_METHOD_INJECTION_BUILTIN(DateTimeZone, DateTimeZone::listabbreviations);
  return TimeZone::GetAbbreviations();
}
コード例 #11
0
ファイル: ext_datetime.cpp プロジェクト: lcastelli/hiphop-php
Array c_DateTimeZone::ti_listidentifiers(const char* cls, int64 what /*= 2047*/,
                                         CStrRef country /*= null_string*/) {
  STATIC_METHOD_INJECTION_BUILTIN(DateTimeZone, DateTimeZone::listidentifiers);
  return TimeZone::GetNames(what, country);
}
コード例 #12
0
ファイル: ext_datetime.cpp プロジェクト: lcastelli/hiphop-php
Variant c_DateTime::ti_getlasterrors(const char* cls) {
  STATIC_METHOD_INJECTION_BUILTIN(DateTime, DateTime::getlasterrors);
  return DateTime::s_last_errors->get();
}