Changeset 4d24650 for text.c


Ignore:
Timestamp:
Feb 4, 2011, 3:49:44 PM (10 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
e062f97
Parents:
e3c8332
git-author:
David Benjamin <davidben@mit.edu> (01/25/11 00:18:14)
git-committer:
David Benjamin <davidben@mit.edu> (02/04/11 15:49:44)
Message:
Make owl_text_indent return a new string

You can't really use it correctly as it is.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • text.c

    rd222c44 r4d24650  
    55#include "owl.h"
    66
    7 void owl_text_indent(char *out, const char *in, int n)
     7/* Returns a copy of 'in' with each line indented 'n'
     8 * characters. Result must be freed with owl_free. */
     9char *owl_text_indent(const char *in, int n)
    810{
    911  const char *ptr1, *ptr2, *last;
     12  GString *out = g_string_new("");
    1013  int i;
    11 
    12   strcpy(out, "");
    1314
    1415  last=in+strlen(in)-1;
     
    1617  while (ptr1<=last) {
    1718    for (i=0; i<n; i++) {
    18       strcat(out, " ");
     19      g_string_append_c(out, ' ');
    1920    }
    2021    ptr2=strchr(ptr1, '\n');
    2122    if (!ptr2) {
    22       strcat(out, ptr1);
     23      g_string_append(out, ptr1);
    2324      break;
    2425    } else {
    25       strncat(out, ptr1, ptr2-ptr1+1);
     26      g_string_append_len(out, ptr1, ptr2-ptr1+1);
    2627    }
    2728    ptr1=ptr2+1;
    2829  }
     30  return g_string_free(out, false);
    2931}
    3032
Note: See TracChangeset for help on using the changeset viewer.