Ejemplo n.º 1
0
static int u_basename(struct Ustr **ps1)
{
  size_t off  = 0;
  size_t len  = ustr_len(*ps1);
  size_t llen = 0;

  if (!len)
    return (ustr_set(ps1, USTR("")));

  llen = ustr_cspn_chr_rev(*ps1, 0, '/');
  if (!llen)
  {
    off  = ustr_spn_chr_rev(*ps1, off, '/');
    llen = u_cspn_chr_rev(*ps1, off, '/');
  }

  if (!llen)
    return (ustr_set(ps1, USTR1(\1, "/")));
  
  return (ustr_set_subustr(ps1, *ps1, (len - (off + llen)) + 1, llen));
}
Ejemplo n.º 2
0
static struct Ustr *u_dirname(const struct Ustr *s2)
{
  size_t off  = 0;
  size_t len  = ustr_len(s2);

  if (!len)
    return (USTR1(\1, "."));

  off = ustr_spn_chr_rev(s2, off, '/');
  if (len == off)
    return (USTR1(\1, "/"));

  off += ustr_cspn_chr_rev(s2, off, '/');
  if (len == off)
    return (USTR1(\1, "."));

  off += ustr_spn_chr_rev(s2, off, '/');
  if (len == off)
    return (USTR1(\1, "/"));

  return (ustr_dup_subustr(s2, 1, (len - off)));
}