CContentInstance* CContentFieldSvnPresentProps::getInstance(const char* pchPath) { CSvnPool oPool; apr_hash_t* pProps = getParent().getPropsForPath(pchPath, oPool); if (!pProps) { return new CContentInstanceEmpty(*this, pchPath); } svn_stringbuf_t* pBuf = svn_stringbuf_create("", oPool); svn_stringbuf_ensure(pBuf, apr_hash_count(pProps) * 16); for (apr_hash_index_t* pIdx = apr_hash_first(oPool, pProps); pIdx; pIdx = apr_hash_next(pIdx)) { const char* pchPropName; int iSize = 0; apr_hash_this(pIdx, reinterpret_cast<const void**>(&pchPropName), &iSize, NULL); svn_stringbuf_appendcstr(pBuf, pchPropName); svn_stringbuf_appendcstr(pBuf, " "); } svn_stringbuf_chop(pBuf, 1); return new CContentInstanceString(*this, pchPath, pBuf->data, pBuf->len); }
static svn_error_t * test7(const char **msg, svn_boolean_t msg_only, svn_test_opts_t *opts, apr_pool_t *pool) { char *tmp; size_t tmp_len; *msg = "chopping a string"; if (msg_only) return SVN_NO_ERROR; c = svn_stringbuf_create(phrase_2, pool); tmp_len = c->len; tmp = apr_palloc(pool, c->len + 1); strcpy(tmp, c->data); svn_stringbuf_chop(c, 11); if ((c->len == (tmp_len - 11)) && (strncmp(tmp, c->data, c->len) == 0) && (c->data[c->len] == '\0')) return SVN_NO_ERROR; else return fail(pool, "test failed"); }
/* Guts of svn_stream_readline(). * Returns the line read from STREAM in *STRINGBUF, and indicates * end-of-file in *EOF. If DETECT_EOL is TRUE, the end-of-line indicator * is detected automatically and returned in *EOL. * If DETECT_EOL is FALSE, *EOL must point to the desired end-of-line * indicator. STRINGBUF is allocated in POOL. */ static svn_error_t * stream_readline_bytewise(svn_stringbuf_t **stringbuf, svn_boolean_t *eof, const char *eol, svn_stream_t *stream, apr_pool_t *pool) { svn_stringbuf_t *str; apr_size_t numbytes; const char *match; char c; /* Since we're reading one character at a time, let's at least optimize for the 90% case. 90% of the time, we can avoid the stringbuf ever having to realloc() itself if we start it out at 80 chars. */ str = svn_stringbuf_create_ensure(LINE_CHUNK_SIZE, pool); /* Read into STR up to and including the next EOL sequence. */ match = eol; while (*match) { numbytes = 1; SVN_ERR(svn_stream_read(stream, &c, &numbytes)); if (numbytes != 1) { /* a 'short' read means the stream has run out. */ *eof = TRUE; *stringbuf = str; return SVN_NO_ERROR; } if (c == *match) match++; else match = eol; svn_stringbuf_appendbyte(str, c); } *eof = FALSE; svn_stringbuf_chop(str, match - eol); *stringbuf = str; return SVN_NO_ERROR; }
/* Prepare LINE for display, pruning or extending it to an appropriate * display width, and stripping the EOL marker, if any. * This function assumes that the data in LINE is encoded in UTF-8. */ static const char * prepare_line_for_display(const char *line, apr_pool_t *pool) { svn_stringbuf_t *buf = svn_stringbuf_create(line, pool); size_t width; size_t line_width = LINE_DISPLAY_WIDTH; apr_pool_t *iterpool; /* Trim EOL. */ if (buf->len >= 2 && buf->data[buf->len - 2] == '\r' && buf->data[buf->len - 1] == '\n') svn_stringbuf_chop(buf, 2); else if (buf->len >= 1 && (buf->data[buf->len - 1] == '\n' || buf->data[buf->len - 1] == '\r')) svn_stringbuf_chop(buf, 1); /* Determine the on-screen width of the line. */ width = svn_utf_cstring_utf8_width(buf->data); if (width == -1) { /* Determining the width failed. Try to get rid of unprintable * characters in the line buffer. */ buf = svn_stringbuf_create(svn_xml_fuzzy_escape(buf->data, pool), pool); width = svn_utf_cstring_utf8_width(buf->data); if (width == -1) width = buf->len; /* fallback: buffer length */ } /* Trim further in case line is still too long, or add padding in case * it is too short. */ iterpool = svn_pool_create(pool); while (width > line_width) { const char *last_valid; svn_pool_clear(iterpool); svn_stringbuf_chop(buf, 1); /* Be careful not to invalidate the UTF-8 string by trimming * just part of a character. */ last_valid = svn_utf__last_valid(buf->data, buf->len); if (last_valid < buf->data + buf->len) svn_stringbuf_chop(buf, (buf->data + buf->len) - last_valid); width = svn_utf_cstring_utf8_width(buf->data); if (width == -1) width = buf->len; /* fallback: buffer length */ } svn_pool_destroy(iterpool); while (width == 0 || width < line_width) { svn_stringbuf_appendbyte(buf, ' '); width++; } SVN_ERR_ASSERT_NO_RETURN(width == line_width); return buf->data; }