Changeset eda54e4 for lib/misc.c
- Timestamp:
- 2007-10-12T00:08:58Z (17 years ago)
- Branches:
- master
- Children:
- a6df0b5
- Parents:
- 82135c7 (diff), d444c09 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/misc.c
r82135c7 reda54e4 545 545 return reply; 546 546 } 547 548 /* Word wrapping. Yes, I know this isn't UTF-8 clean. I'm willing to take the risk. */ 549 char *word_wrap( char *msg, int line_len ) 550 { 551 GString *ret = g_string_sized_new( strlen( msg ) + 16 ); 552 553 while( strlen( msg ) > line_len ) 554 { 555 int i; 556 557 /* First try to find out if there's a newline already. Don't 558 want to add more splits than necessary. */ 559 for( i = line_len; i > 0 && msg[i] != '\n'; i -- ); 560 if( msg[i] == '\n' ) 561 { 562 g_string_append_len( ret, msg, i + 1 ); 563 msg += i + 1; 564 continue; 565 } 566 567 for( i = line_len; i > 0; i -- ) 568 { 569 if( msg[i] == '-' ) 570 { 571 g_string_append_len( ret, msg, i + 1 ); 572 g_string_append_c( ret, '\n' ); 573 msg += i + 1; 574 break; 575 } 576 else if( msg[i] == ' ' ) 577 { 578 g_string_append_len( ret, msg, i ); 579 g_string_append_c( ret, '\n' ); 580 msg += i + 1; 581 break; 582 } 583 } 584 if( i == 0 ) 585 { 586 g_string_append_len( ret, msg, line_len ); 587 g_string_append_c( ret, '\n' ); 588 msg += line_len; 589 } 590 } 591 g_string_append( ret, msg ); 592 593 return g_string_free( ret, FALSE ); 594 }
Note: See TracChangeset
for help on using the changeset viewer.