Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/utils.c @ 727:1c3620668857
Expand tabs when reading history files
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 05 Mar 2006 22:29:14 +0100 |
parents | ee03b56b93ee |
children | 2f027806cd48 |
comparison
equal
deleted
inserted
replaced
726:51be2bc1a820 | 727:1c3620668857 |
---|---|
457 else | 457 else |
458 *p = 0; | 458 *p = 0; |
459 } | 459 } |
460 } | 460 } |
461 | 461 |
462 // ut_expand_tabs(text) | |
463 // Expand tabs in string text. | |
464 // If there is no tab in the string, a pointer to text is returned (be | |
465 // careful _not_ to free the pointer in this case). | |
466 // If there are some tabs, a new string with expanded chars is returned; this | |
467 // is up to the caller to free this string after use. | |
468 char *ut_expand_tabs(const char *text) | |
469 { | |
470 char *xtext; | |
471 char *p, *q; | |
472 guint8 n=0; | |
473 | |
474 xtext = (char*)text; | |
475 for (p=xtext; *p; p++) | |
476 if (*p == '\t') n++; | |
477 | |
478 if (!n) | |
479 return (char*)text; | |
480 | |
481 xtext = g_new(char, strlen(text) + 1 + 8*n); | |
482 p = (char*)text; | |
483 q = xtext; | |
484 do { | |
485 if (*p == '\t') { | |
486 do { *q++ = ' '; } while ((q-xtext)%8); | |
487 } else { | |
488 *q++ = *p; | |
489 } | |
490 } while (*p++); | |
491 | |
492 return xtext; | |
493 } | |
494 | |
495 | |
462 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ | 496 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |