コード例 #1
0
ファイル: array-util.cpp プロジェクト: RdeWilde/hhvm
Variant ArrayUtil::ChangeKeyCase(CArrRef input, bool lower) {
  Array ret = Array::Create();
  for (ArrayIter iter(input); iter; ++iter) {
    Variant key(iter.first());
    if (key.isString()) {
      if (lower) {
        ret.set(f_strtolower(key.toString()), iter.secondRef());
      } else {
        ret.set(f_strtoupper(key.toString()), iter.secondRef());
      }
    } else {
      ret.set(key, iter.secondRef());
    }
  }
  return ret;
}
コード例 #2
0
ファイル: test_externals.cpp プロジェクト: akia/hiphop-php
// Used by test_ext_preg
static String test_preg_rep(CStrRef a, CStrRef b, CStrRef c) {
  return concat(f_strtoupper(c), a);
}
コード例 #3
0
ファイル: test_externals.cpp プロジェクト: akia/hiphop-php
Variant invokeImpl(void *extra, CArrRef params) {
  const char *function = (const char*)extra;
  // for TestExtFunction
  if (strcasecmp(function, "test") == 0) {
    return params[0];
  }

  // for TestExtPreg::test_preg_replace_callback
  if (strcasecmp(function, "next_year") == 0) {
    Array matches = params[0].toArray();
    return matches[1].toString() + String(matches[2].toInt32() + 1);
  }

  // for TestExtArray::test_array_filter
  if (strcasecmp(function, "odd") == 0) {
    return params[0].toInt32() & 1;
  }
  if (strcasecmp(function, "even") == 0) {
    return !(params[0].toInt32() & 1);
  }

  // for TestExtArray::test_array_map
  if (strcasecmp(function, "cube") == 0) {
    int n = params[0].toInt32();
    return n * n * n;
  }

  // for TestExtArray::test_array_multisort
  if (strcasecmp(function, "strtolower") == 0) {
    return f_strtolower(params[0]);
  }

  // for TestExtArray::test_array_reduce
  if (strcasecmp(function, "rsum") == 0) {
    int v = params[0].toInt32();
    int w = params[1].toInt32();
    v += w;
    return v;
  }
  if (strcasecmp(function, "rmul") == 0) {
    int v = params[0].toInt32();
    int w = params[1].toInt32();
    v *= w;
    return v;
  }

  // for TestExtArray::test_array_walk_recursive
  if (strcasecmp(function, "test_print") == 0) {
    String item = params[0].toString();
    String key = params[1].toString();
    echo(key + ": " + item + "\n");
  }

  // for TestExtArray::test_array_walk
  if (strcasecmp(function, "test_alter") == 0) {
    Variant &item1 = lval(((Array&)params).lvalAt(0));
    String key = params[1];
    String prefix = params[2];
    item1 = prefix + ": " + item1;
  }

  // for TestExtArray::test_array_udiff
  if (strcasecmp(function, "comp_func") == 0) {
    int n1 = params[0].toInt32();
    int n2 = params[1].toInt32();
    if (n1 == n2) return 0;
    return n1 > n2 ? 1 : -1;
  }

  // for TestExtArray::test_usort
  if (strcasecmp(function, "reverse_comp_func") == 0) {
    int n1 = params[0].toInt32();
    int n2 = params[1].toInt32();
    if (n1 == n2) return 0;
    return n1 > n2 ? -1 : 1;
  }

  // for TestExtArray::test_array_uintersect
  if (strcasecmp(function, "strcasecmp") == 0) {
    String s1 = params[0].toString();
    String s2 = params[1].toString();
    return strcasecmp(s1.data(), s2.data());
  }

  // for TestExtArray::test_uasort
  if (strcasecmp(function, "reverse_strcasecmp") == 0) {
    String s1 = params[0].toString();
    String s2 = params[1].toString();
    return strcasecmp(s2.data(), s1.data());
  }

  // for TestExtFbml
  if (strcasecmp(function, "urltr") == 0) {
    String s1 = params[0].toString();
    String s2 = params[1].toString();
    return String("url:") + s1 + "=" + s2;
  }

  // for TestExtCurl::test_curl_exec
  if (strcasecmp(function, "curl_write_func") == 0) {
    print("curl_write_func called with ");
    print(params[1]);
    return params[1].toString().size();
  }

  // for TestExtPreg::test_preg_replace
  if (strcasecmp(function, "strtoupper") == 0) {
    return f_strtoupper(params[0].toString());
  }
  if (strcasecmp(function, "test_preg_rep") == 0) {
    return test_preg_rep(params[0].toString(), params[1].toString(),
                       params[2].toString());
  }
  if (strcasecmp(function, "sprintf") == 0) {
    return f_sprintf(params.size(), params[0],
                     params.slice(1, params.size() - 1, false));
  }

  // for TestExtSqlite3::test_sqlite3
  if (strcasecmp(function, "lower") == 0) {
    return f_strtolower(params[0]);
  }
  if (strcasecmp(function, "sumlen_step") == 0) {
    return params[0].toInt64() + f_strlen(params[2]);
  }
  if (strcasecmp(function, "sumlen_fini") == 0) {
    return params[0].toInt64();
  }

  // for TestExtSoap
  if (strcasecmp(function, "hello") == 0) {
    return "Hello World";
  }
  if (strcasecmp(function, "add") == 0) {
    return params[0].toInt32() + params[1].toInt32();
  }
  if (strcasecmp(function, "sub") == 0) {
    return params[0].toInt32() - params[1].toInt32();
  }
  if (strcasecmp(function, "sum") == 0) {
    int sum = 0;
    for (ArrayIter iter(params[0]); iter; ++iter) {
      sum += iter.second().toInt32();
    }
    return sum;
  }
  if (strcasecmp(function, "strlen") == 0) {
    return f_strlen(params[0]);
  }
  if (strcasecmp(function, "fault") == 0) {
    return Object((NEW(c_SoapFault)())->create("MyFault","My fault string"));
  }

  // for TestExtServer
  if (strcasecmp(function, "xbox_process_message") == 0) {
    return StringUtil::Reverse(params[0]);
  }

  return true;
}
コード例 #4
0
bool TestExtString::test_strtoupper() {
  VS(f_strtoupper("abc"), "ABC");
  return Count(true);
}