console/libgnt/gnttextview.c

changeset 15396
a5938aa3f6c9
parent 15375
42b08c34496b
child 15397
2a5e63b97a2b
equal deleted inserted replaced
15395:ce9f0fe6a77a 15396:a5938aa3f6c9
507 */ 507 */
508 int gnt_text_view_tag_change(GntTextView *view, const char *name, const char *text, gboolean all) 508 int gnt_text_view_tag_change(GntTextView *view, const char *name, const char *text, gboolean all)
509 { 509 {
510 GList *alllines = g_list_first(view->list); 510 GList *alllines = g_list_first(view->list);
511 GList *list, *next, *iter, *inext; 511 GList *list, *next, *iter, *inext;
512 const int text_length = text ? g_utf8_strlen(text, -1) : 0;
512 int count = 0; 513 int count = 0;
513 for (list = view->tags; list; list = next) { 514 for (list = view->tags; list; list = next) {
514 GntTextTag *tag = list->data; 515 GntTextTag *tag = list->data;
515 next = list->next; 516 next = list->next;
516 if (strcmp(tag->name, name) == 0) { 517 if (strcmp(tag->name, name) == 0) {
519 520
520 count++; 521 count++;
521 522
522 before = g_strndup(view->string->str, tag->start); 523 before = g_strndup(view->string->str, tag->start);
523 after = g_strdup(view->string->str + tag->end); 524 after = g_strdup(view->string->str + tag->end);
524 change = (tag->end - tag->start) - (text ? strlen(text) : 0); 525 change = (tag->end - tag->start) - text_length;
525 526
526 g_string_printf(view->string, "%s%s%s", before, text ? text : "", after); 527 g_string_printf(view->string, "%s%s%s", before, text ? text : "", after);
527 g_free(before); 528 g_free(before);
528 g_free(after); 529 g_free(after);
529 530

mercurial