- Timestamp:
- Dec 24, 2007, 2:53:11 AM (17 years ago)
- Branches:
- master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 762512d
- Parents:
- 5bc0f68
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
text.c
r34509d5 r28ee32b 50 50 void owl_text_truncate_cols(char *out, char *in, int acol, int bcol) 51 51 { 52 char *ptr 1, *ptr2, *tmpbuff, *last;53 int len;54 52 char *ptr_s, *ptr_e, *ptr_c, *tmpbuff, *last; 53 int col, cnt; 54 55 55 tmpbuff=owl_malloc(strlen(in)+20); 56 56 57 57 strcpy(tmpbuff, ""); 58 58 last=in+strlen(in)-1; 59 ptr 1=in;60 while (ptr 1<last) {61 ptr 2=strchr(ptr1, '\n');62 if (!ptr 2) {59 ptr_s=in; 60 while (ptr_s<last) { 61 ptr_e=strchr(ptr_s, '\n'); 62 if (!ptr_e) { 63 63 /* but this shouldn't happen if we end in a \n */ 64 64 break; 65 65 } 66 66 67 if (ptr 2==ptr1) {67 if (ptr_e==ptr_s) { 68 68 strcat(tmpbuff, "\n"); 69 ptr1++; 70 continue; 71 } 72 69 ptr_s++; 70 continue; 71 } 72 73 col = 0; 74 cnt = 0; 75 ptr_c = ptr_s; 76 while(col < bcol && ptr_c < ptr_e) { 77 gunichar c = g_utf8_get_char(ptr_c); 78 if (g_unichar_iswide(c)) { 79 if (col + 2 > bcol) break; 80 else col += 2; 81 } 82 else if (g_unichar_type(c) == G_UNICODE_NON_SPACING_MARK) ; /*do nothing*/ 83 /* We may need more special cases here... unicode spacing is hard. */ 84 else { 85 if (col + 1 > bcol) break; 86 else ++col; 87 } 88 ptr_c = g_utf8_next_char(ptr_c); 89 if (col >= acol) ++cnt; 90 if (col <= acol) ptr_s = ptr_c; 91 } 92 strncat(tmpbuff, ptr_s, ptr_c - ptr_s - 1); 93 strcat(tmpbuff, "\n"); 94 ptr_s = ptr_e + 1; 95 #if 0 73 96 /* we need to check that we won't run over here */ 74 if ( (ptr 2-ptr1) < (bcol-acol) ) {75 len=ptr 2-(ptr1+acol);97 if ( (ptr_e-ptr_s) < (bcol-acol) ) { 98 len=ptr_e-(ptr_s+acol); 76 99 } else { 77 100 len=bcol-acol; 78 101 } 79 if ((ptr 1+len)>=last) {80 len-=last-(ptr 1+len);81 } 82 83 strncat(tmpbuff, ptr 1+acol, len);102 if ((ptr_s+len)>=last) { 103 len-=last-(ptr_s+len); 104 } 105 106 strncat(tmpbuff, ptr_s+acol, len); 84 107 strcat(tmpbuff, "\n"); 85 108 86 ptr1=ptr2+1; 109 ptr_s=ptr_e+1; 110 #endif 87 111 } 88 112 strcpy(out, tmpbuff); … … 275 299 char *stristr(char *a, char *b) 276 300 { 277 char *x, *y, *ret; 278 279 if ((x=owl_strdup(a))==NULL) return(NULL); 280 if ((y=owl_strdup(b))==NULL) return(NULL); 281 downstr(x); 282 downstr(y); 283 ret=strstr(x, y); 284 if (ret==NULL) { 285 owl_free(x); 286 owl_free(y); 287 return(NULL); 288 } 289 ret=ret-x+a; 290 owl_free(x); 291 owl_free(y); 301 char *x, *y; 302 char *ret = NULL; 303 if ((x = g_utf8_casefold(a, -1)) != NULL) { 304 if ((y = g_utf8_casefold(b, -1)) != NULL) { 305 ret = strstr(x, y); 306 if (ret != NULL) { 307 ret = ret - x + a; 308 } 309 g_free(y); 310 } 311 g_free(x); 312 } 292 313 return(ret); 293 314 } … … 296 317 int only_whitespace(char *s) 297 318 { 298 int i; 299 for (i=0; s[i]; i++) { 300 if (!isspace((int) s[i])) return(0); 319 if (g_utf8_validate(s,-1,NULL)) { 320 char *p; 321 for(p = s; p[0]; p=g_utf8_next_char(p)) { 322 if (!g_unichar_isspace(g_utf8_get_char(p))) return 0; 323 } 324 } 325 else { 326 int i; 327 for (i=0; s[i]; i++) { 328 if (!isspace((int) s[i])) return(0); 329 } 301 330 } 302 331 return(1);
Note: See TracChangeset
for help on using the changeset viewer.