Changes in lib/misc.c [fca4683:47ab9a9]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/misc.c
rfca4683 r47ab9a9 549 549 } 550 550 551 /* Word wrapping. Yes, I know this isn't UTF-8 clean. I'm willing to take the risk. */ 551 552 char *word_wrap(const char *msg, int line_len) 552 553 { … … 581 582 } 582 583 if (i == 0) { 583 const char *end; 584 size_t len; 585 586 g_utf8_validate(msg, line_len, &end); 587 588 len = (end != msg) ? end - msg : line_len; 589 590 g_string_append_len(ret, msg, len); 584 g_string_append_len(ret, msg, line_len); 591 585 g_string_append_c(ret, '\n'); 592 msg += l en;586 msg += line_len; 593 587 } 594 588 } … … 793 787 return string; 794 788 } 795 796 /* Returns a string that is exactly 'char_len' utf8 characters long (not bytes),797 * padded to the right with spaces or truncated with the 'ellipsis' parameter798 * if specified (can be NULL).799 * Returns a newly allocated string, or NULL on invalid parameters. */800 char *str_pad_and_truncate(const char *string, long char_len, const char *ellipsis)801 {802 size_t string_len = strlen(string);803 size_t ellipsis_len = (ellipsis) ? strlen(ellipsis) : 0;804 long orig_len = g_utf8_strlen(string, -1);805 806 g_return_val_if_fail(char_len > ellipsis_len, NULL);807 808 if (orig_len > char_len) {809 char *ret = g_malloc(string_len + 1);810 g_utf8_strncpy(ret, string, char_len - ellipsis_len);811 if (ellipsis) {812 g_strlcat(ret, ellipsis, string_len);813 }814 return ret;815 } else if (orig_len < char_len) {816 return g_strdup_printf("%s%*s", string, (int) (char_len - orig_len), "");817 } else {818 return g_strdup(string);819 }820 }
Note: See TracChangeset
for help on using the changeset viewer.