Esempio n. 1
0
static String locale_suffix_strip(const String& locale) {
  for (int i = locale.size(); i >= 0; --i) {
    if (isIDSeparator(locale[i])) {
      if ((i>=2) && isIDSeparator(locale[i-2])) {
        return f_substr(locale, 0, i - 2);
      } else {
        return f_substr(locale, 0, i);
      }
    }
  }
  return null_string;
}
Esempio n. 2
0
bool TestExtMcrypt::test_mcrypt_ecb() {
  String key = "123456789012345678901234567890123456789012345678901234567890";
  String CC = "4007000000027";
  Variant encrypted =
    f_mcrypt_ecb(k_MCRYPT_RIJNDAEL_128, f_substr(key,0,32),
                 CC, k_MCRYPT_ENCRYPT, f_substr(key,32,16));
  Variant decrypted =
    f_mcrypt_ecb(k_MCRYPT_RIJNDAEL_128, f_substr(key,0,32),
                 encrypted, k_MCRYPT_DECRYPT, f_substr(key,32,16));
  VERIFY(!same(encrypted, decrypted));
  VS(decrypted.toString().data(), CC);
  return Count(true);
}
Esempio n. 3
0
static Variant get_private_subtags(const String& locname) {
  if (locname.empty()) return uninit_null();
  String locale(locname);
  int pos;
  while ((pos = singleton_pos(locale)) >= 0) {
    if ((locale[pos] == 'x') || (locale[pos] == 'X')) {
      if ((pos + 2) == locale.size()) {
        /* loc_name ends with '-x-' */
        return uninit_null();
      }
      return f_substr(locale, pos);
    }
    if ((pos + 1) >= locale.size()) {
      return uninit_null();
    }
    locale = f_substr(locale, pos + 1);
  }
  return uninit_null();
}
Esempio n. 4
0
bool TestExtString::test_substr() {
  VS(f_substr("abcdef", 1), "bcdef");
  VS(f_substr("abcdef", 1, 3), "bcd");
  VS(f_substr("abcdef", 0, 4), "abcd");
  VS(f_substr("abcdef", 0, 8), "abcdef");
  VS(f_substr("abcdef", -1, 1), "f");
  VS(f_substr("abcdef", 6), false);
  VS(f_substr("abcdef", 3, 0), "");
  return Count(true);
}
Esempio n. 5
0
bool TestExtMailparse::test_mailparse_rfc822_parse_addresses() {
    static const StaticString
    s_display("display"),
              s_address("address"),
              s_is_group("is_group");
    Array addresses =
        CREATE_VECTOR2("\":sysmail\"@ Some-Group. Some-Org, Muhammed."
                       "(I am the greatest) Ali @(the)Vegas.WBA",
                       "\"strange\":\":sysmail\"@ Some-Group. Some-Org, Muhammed."
                       "(I am the greatest) Ali @(the)Vegas.WBA;");

    f_ob_start();

    for (ArrayIter iter(addresses); iter; ++iter) {
        Variant parsed = f_mailparse_rfc822_parse_addresses(iter.second());
        for (ArrayIter iter2(parsed); iter2; ++iter2) {
            Variant pair = iter2.second();
            echo(pair[s_display]);
            echo("\n");
            echo(pair[s_address]);
            echo("\n");
            if (pair[s_is_group].toBoolean()) {
                Variant sub = f_mailparse_rfc822_parse_addresses
                              (f_substr(pair[s_address], 1, f_strlen(pair[s_address]) - 2));
                for (ArrayIter iter3(sub); iter3; ++iter3) {
                    echo("   ");
                    echo(iter3.second()[s_address]);
                    echo("\n");
                }
            }
        }
        echo("...\n");
    }

    String output = f_ob_get_contents();
    f_ob_end_clean();
    VS(output,
       ":[email protected]\n"
       "\":sysmail\"@Some-Group.Some-Org\n"
       "I am the greatest the\n"
       "[email protected]\n"
       "...\n"
       "strange\n"
       ":\":sysmail\"@Some-Group.Some-Org,[email protected];\n"
       "   \":sysmail\"@Some-Group.Some-Org\n"
       "   [email protected]\n"
       "...\n");

    return Count(true);
}
Esempio n. 6
0
bool TestExtMcrypt::test_mcrypt_module_open() {
  Variant td = f_mcrypt_module_open("rijndael-256", "", "ofb", "");
  Variant iv = f_mcrypt_create_iv(f_mcrypt_enc_get_iv_size(td),
                                  k_MCRYPT_DEV_RANDOM);
  Variant ks = f_mcrypt_enc_get_key_size(td);
  Variant key = f_substr(f_md5("very secret key"), 0, ks);
  f_mcrypt_generic_init(td, key, iv);
  Variant encrypted = f_mcrypt_generic(td, "This is very important data");
  VERIFY(!same(encrypted, "This is very important data"));
  f_mcrypt_generic_deinit(td);
  f_mcrypt_generic_init(td, key, iv);
  Variant decrypted = f_mdecrypt_generic(td, encrypted);
  f_mcrypt_generic_end(td);
  f_mcrypt_module_close(td);

  VS(decrypted, "This is very important data");
  return Count(true);
}
Esempio n. 7
0
static Variant get_icu_value(const String &locale, LocaleTag tag,
                             bool fromParseLocale = false) {
  String locale_name(locale);
  if (tag != LOC_CANONICALIZE) {
    if (getGrandfatheredOffset(locale) >= 0) {
      if (tag == LOC_LANG) {
        return locale;
      }
      return false;
    }
    if (fromParseLocale) {
      auto localecstr = locale.c_str();
      if (tag == LOC_LANG && locale.size() > 1 && isIDPrefix(localecstr)) {
        return locale;
      }
      int pos = singleton_pos(locale);
      if (pos == 0) {
        return null_string;
      } else if (pos > 0) {
        locale_name = f_substr(locale, 0, pos - 1);
      }
    }
  }

  int32_t (*ulocfunc)(const char *loc, char *val, int32_t len, UErrorCode *err);
  switch (tag) {
    case LOC_SCRIPT:       ulocfunc = uloc_getScript;    break;
    case LOC_LANG:         ulocfunc = uloc_getLanguage;  break;
    case LOC_REGION:       ulocfunc = uloc_getCountry;   break;
    case LOC_VARIANT:      ulocfunc = uloc_getVariant;   break;
    case LOC_CANONICALIZE: ulocfunc = uloc_canonicalize; break;
    default:
      assert(false);
      return false;
  }

  String buf(64, ReserveString);
  do {
    UErrorCode error = U_ZERO_ERROR;
    int32_t len = ulocfunc(locale_name.c_str(),
                           buf->mutableData(), buf->capacity(), &error);
    if (error != U_BUFFER_OVERFLOW_ERROR &&
        error != U_STRING_NOT_TERMINATED_WARNING) {
      if (U_FAILURE(error)) {
        s_intl_error->setError(error, "unable to get locale info");
        return false;
      }
      buf.setSize(len);
      return buf;
    }
    if (len <= buf->capacity()) {
      // Avoid infinite loop
      s_intl_error->setError(U_INTERNAL_PROGRAM_ERROR,
                             "Got invalid response from ICU");
      return false;
    }
    buf = String(len, ReserveString);
  } while (true);

  not_reached();
  return false;
}