Exemplo n.º 1
0
hashmap<string,string>
persistent_read_map (url file) {
  string s;
  load_string (file, s, false);
  hashmap<string,string> map;
  int i=0, n= N(s);
  while (i<n) {
    string key= read_escaped (s, i);
    string val= read_escaped (s, i);
    map (key)= val;
  }
  return map;
}
Exemplo n.º 2
0
/* Read a field, possibly with escaped bytes, from [*BUF, END),
   stopping at the terminator.  Place the read string in *RESULT, or set
   *RESULT to NULL if it is the empty string.  Allocate the returned string
   in POOL.  Advance *BUF to point after the terminator. */
static svn_error_t *
read_str(const char **result,
         char **buf, const char *end,
         apr_pool_t *pool)
{
    svn_stringbuf_t *s = NULL;
    const char *start;
    if (*buf == end)
        return svn_error_create(SVN_ERR_WC_CORRUPT, NULL,
                                _("Unexpected end of entry"));
    if (**buf == '\n')
    {
        *result = NULL;
        (*buf)++;
        return SVN_NO_ERROR;
    }

    start = *buf;
    while (*buf != end && **buf != '\n')
    {
        if (**buf == '\\')
        {
            char c;
            if (! s)
                s = svn_stringbuf_ncreate(start, *buf - start, pool);
            else
                svn_stringbuf_appendbytes(s, start, *buf - start);
            (*buf)++;
            SVN_ERR(read_escaped(&c, buf, end));
            svn_stringbuf_appendbyte(s, c);
            start = *buf;
        }
        else
            (*buf)++;
    }

    if (*buf == end)
        return svn_error_create(SVN_ERR_WC_CORRUPT, NULL,
                                _("Unexpected end of entry"));

    if (s)
    {
        svn_stringbuf_appendbytes(s, start, *buf - start);
        *result = s->data;
    }
    else
        *result = apr_pstrndup(pool, start, *buf - start);
    (*buf)++;
    return SVN_NO_ERROR;
}