Permalink
Browse files

cherokee_buffer_split() accepts a new extra parameter 'indent' now.

git-svn-id: svn://cherokee-project.com/cherokee/trunk@6151 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information...
alobbs committed Jan 20, 2011
1 parent fcce76c commit 599566362ca025c444a94b8c566efbf73c869e6b
Showing with 27 additions and 7 deletions.
  1. +25 −5 cherokee/buffer.c
  2. +1 −1 cherokee/buffer.h
  3. +1 −1 cherokee/server.c
View
@@ -2245,14 +2245,20 @@ cherokee_buffer_insert_buffer (cherokee_buffer_t *buf,
ret_t
cherokee_buffer_split_lines (cherokee_buffer_t *buf,
- int columns)
+ int columns,
+ const char *indent)
{
char *p;
- char *end = buf->buf + buf->len;
- char *prev_space = NULL;
- int since_prev = 0;
+ char *prev_space = NULL;
+ char *latest_newline = NULL;
+ int since_prev = 0;
+ int indent_len = 0;
- for (p = buf->buf; p < end; p++) {
+ if (indent) {
+ indent_len = strlen(indent);
+ }
+
+ for (p = buf->buf; p < buf->buf + buf->len; p++) {
since_prev += 1;
if (*p != ' ') {
@@ -2271,11 +2277,25 @@ cherokee_buffer_split_lines (cherokee_buffer_t *buf,
/* Reset */
since_prev = (p - prev_space);
+ latest_newline = prev_space;
prev_space = NULL;
} else {
/* len(word) > columns */
*p = '\n';
since_prev = 0;
+ latest_newline = p;
+ }
+
+ /* Line just split */
+ if (indent) {
+ int offset = p - buf->buf;
+
+ cherokee_buffer_insert (buf, (char *)indent, indent_len,
+ (latest_newline - buf->buf)+1);
+
+ since_prev += indent_len;
+ p = buf->buf + offset + indent_len;
+ latest_newline = NULL;
}
}
}
View
@@ -133,7 +133,7 @@ ret_t cherokee_buffer_escape_html (cherokee_buffer_t *buf, cherokee_buff
ret_t cherokee_buffer_add_comma_marks (cherokee_buffer_t *buf);
ret_t cherokee_buffer_to_lowcase (cherokee_buffer_t *buf);
-ret_t cherokee_buffer_split_lines (cherokee_buffer_t *buf, int columns);
+ret_t cherokee_buffer_split_lines (cherokee_buffer_t *buf, int columns, const char *indent);
ret_t cherokee_buffer_print_debug (cherokee_buffer_t *buf, int length);
View
@@ -510,7 +510,7 @@ print_banner (cherokee_server_t *srv)
/* Print it to stdout
*/
- cherokee_buffer_split_lines (&n, TERMINAL_WIDTH);
+ cherokee_buffer_split_lines (&n, TERMINAL_WIDTH, NULL);
fprintf (stdout, "%s\n", n.buf);
fflush (stdout);

0 comments on commit 5995663

Please sign in to comment.