Ejemplo n.º 1
0
int
main (int argc, const char *argv[])
{
  if (argc < 2)
    return -1;

  str parent, filename;

  parentpath (parent, filename, str (argv[1]));

    warn << parent << "\n";
    warn << filename << "\n";

  return 0;

  vec<str> out;
  splitpath (out, argv[1]);
  str foo;

  while (out.size () > 0 && (foo = out.pop_front ()))
    warn << foo << "\n";
  return 0;

  str path (argv[1]);
  
  //  vec<str> out;
  static rxx r ("^(.*)/([^/]+)$");
  //  static rxx r ("^/*([^/]+)(/.*)?$");

  //  static rxx r ("^s%/[^/]*$%%");
  //   static rxx pathsplit ("^/*([^/]+)(/.*)?$");

  warn << "path: " << path << "\n";

  // path = path/r;


  if (r.search (path))
    {

      if (r.len(1) != -1)
	warn << r[1] << " -> ";
      if (r.len(2) != -1)
	warn << r[2] << "\n";
      warn << "r[0]: " << r[0] << "\n";
    }

  warn << split (&out, "/", path) << "\n";  
  for (unsigned int i=0; i< out.size(); i++)
    warn << out[i] << "\n";

  return 0;

}
Ejemplo n.º 2
0
Archivo: rxx.C Proyecto: aosmith/okws
// A lot of this is taken from async/rxx.C in sfslite, but with some
// modifications for returning the matched pattern.
//
int
split2 (vec<str> *out, rxx pat, str expr, size_t lim, bool emptylast)
{
  const char *p = expr;
  const char *const e = p + expr.len ();
  size_t n;
  if (out)
    out->clear ();

  // check p < e to see that we're not dealing with an empty
  // string (especially since x? matches "").
  for (n = 0; p < e && n + 1 < lim; n++) {
    if (!pat._exec (p, e - p, 0)) {
      return 0;
    }
    if (!pat.success ())
      break;
    if (out) {
      out->push_back (str (p, pat.start (0)));
      str sep (p + pat.start (0), pat.len (0));
      out->push_back (sep);
    }
    p += max (pat.end (0), 1);
  }

  if (lim && (p < e || emptylast)) {
    n++;
    if (out) {
      out->push_back (str (p, e - p));
    }
  }
  return n;
}
Ejemplo n.º 3
0
Archivo: rxx.C Proyecto: aosmith/okws
void
repl_el_capture_t::output (strbuf &out, const char *s, rxx &x)
{
  int start = x.start (_i);
  int ln = x.len (_i);

  if (start >= 0 && ln > 0) {
    str repl = str (s + start, ln);
    strbuf_output (out, repl); 
  }
}
Ejemplo n.º 4
0
Archivo: rxx.C Proyecto: aosmith/okws
static void
extract_matches (vec<str> *out, const char *base, rxx &x)
{
  bool go = true;
  for (int i = 0; go; i++) {

    int ln = x.len (i);
    int start = x.start (i);

    if (ln < 0 || start < 0) { go = false; }
    else if (ln > 0) { out->push_back (str (base + start, ln)); }
  }
}