bool TestExtPreg::test_split() { { String mb = "\xe4\xbf\xa1\xe6\x81\xaf\x01 2366797"; Array ret = f_split("\x01", mb); VS(ret[0], "\xe4\xbf\xa1\xe6\x81\xaf"); VS(ret[1], " 2366797"); } String date = "04/30/1973"; Array ret = f_split("[/.-]", date); VS(ret[0], "04"); VS(ret[1], "30"); VS(ret[2], "1973"); return Count(true); }
static std::string getSandboxHostFormat() { // Assume dev servers host name are in following format: // <host>.<cluster>.<domain>.com // and we need to change to the following to match sandbox format: // www.<sandbox>.<host>.<domain>.com String hostName = f_php_uname("n"); Array fields = f_split("\\.", hostName); if (fields.size() != 4) { return ""; } String host = fields.rvalAt(0).toString(); String domain = fields.rvalAt(1).toString() + "." + fields.rvalAt(2).toString(); String suffix = fields.rvalAt(3).toString(); string sandboxHost = "hphpd.debugger_tests." + host->toCPPString() + "." + domain->toCPPString() + "." + suffix->toCPPString(); return sandboxHost; }
static VALUE string_to_r_internal(VALUE self) { VALUE s, m; s = self; if (RSTRING_LEN(s) == 0) return rb_assoc_new(Qnil, self); m = f_match(rat_pat, s); if (!NIL_P(m)) { VALUE v, ifp, exp, ip, fp; VALUE si = f_aref(m, INT2FIX(1)); VALUE nu = f_aref(m, INT2FIX(2)); VALUE de = f_aref(m, INT2FIX(3)); VALUE re = f_post_match(m); { VALUE a; a = f_split(nu, an_e_pat); ifp = RARRAY_PTR(a)[0]; if (RARRAY_LEN(a) != 2) exp = Qnil; else exp = RARRAY_PTR(a)[1]; a = f_split(ifp, a_dot_pat); ip = RARRAY_PTR(a)[0]; if (RARRAY_LEN(a) != 2) fp = Qnil; else fp = RARRAY_PTR(a)[1]; } v = rb_rational_new1(f_to_i(ip)); if (!NIL_P(fp)) { char *p = StringValuePtr(fp); long count = 0; VALUE l; while (*p) { if (rb_isdigit(*p)) count++; p++; } l = f_expt(INT2FIX(10), LONG2NUM(count)); v = f_mul(v, l); v = f_add(v, f_to_i(fp)); v = f_div(v, l); } if (!NIL_P(si) && *StringValuePtr(si) == '-') v = f_negate(v); if (!NIL_P(exp)) v = f_mul(v, f_expt(INT2FIX(10), f_to_i(exp))); #if 0 if (!NIL_P(de) && (!NIL_P(fp) || !NIL_P(exp))) return rb_assoc_new(v, rb_usascii_str_new2("dummy")); #endif if (!NIL_P(de)) v = f_div(v, f_to_i(de)); return rb_assoc_new(v, re); } return rb_assoc_new(Qnil, self); }