comparison console/libgnt/gntutils.c @ 14423:cfd5bcc06a7e

[gaim-migrate @ 17131] Try to make sure the strings are not too long to get out of the range of the screen. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 02 Sep 2006 23:06:25 +0000
parents c4a32405af68
children c374f45f4c94
comparison
equal deleted inserted replaced
14422:84a480acb6ad 14423:cfd5bcc06a7e
66 if (w) 66 if (w)
67 *w = width; 67 *w = width;
68 return str; 68 return str;
69 } 69 }
70 70
71 char *gnt_util_onscreen_fit_string(const char *string, int maxw)
72 {
73 const char *start, *end;
74 GString *str;
75
76 if (maxw <= 0)
77 maxw = getmaxx(stdscr) - 4;
78
79 start = string;
80 str = g_string_new(NULL);
81
82 while (*start) {
83 if ((end = strchr(start, '\n')) != NULL ||
84 (end = strchr(start, '\r')) != NULL) {
85 if (gnt_util_onscreen_width(start, end) <= maxw) {
86 ++end;
87 } else
88 end = NULL;
89 }
90 if (end == NULL)
91 end = gnt_util_onscreen_width_to_pointer(start, maxw, NULL);
92 str = g_string_append_len(str, start, end - start);
93 start = end;
94 if (*end && *end != '\n' && *end != '\r')
95 str = g_string_append_c(str, '\n');
96 }
97 return g_string_free(str, FALSE);
98 }
99