Exemplo n.º 1
0
Arquivo: ls.c Projeto: abzde/dock9
string arrange_string(string str, int width)
{
   int i, j, maxi, len;
   string stripped_colours;

   if (!width) return "";

   len = strlen(stripped_colours = strip_colours(str));

   if (len < width)
       return str + repeat_string(" ", width - len);
   if (len == width) return str;

   /* Full str indexed by i. Visible chars in stripped_colours indexed by j */
   j = 0;
   maxi = strlen(str);

   for (i = 0 ; i < maxi ; i++)
   {
       if (str[i] == stripped_colours[j])
       {
           j++;
           if(j >= width) break;
       }
   }

   return str[0..i];
}
Exemplo n.º 2
0
varargs string center(string str, int x) {
    int y;

    if(!x) x= 80;
    x--;
    if((y = strlen(strip_colours(str))) >= x) return str;
    x = x + strlen(str) - y;
    return sprintf(sprintf("%%|%ds", x), str);
}