whiplk

[CODE] - AddString(format)

Jul 16th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. void AddString(U **buf_p, size_t &maxlen, const cell *string, int width, int prec)
  2. {
  3.     int     size = 0;
  4.     U       *buf;
  5.     static cell nlstr[] = {'(','n','u','l','l',')','\0'};
  6.  
  7.     buf = *buf_p;
  8.  
  9.     if (string == NULL)
  10.     {
  11.         string = nlstr;
  12.         prec = -1;
  13.     }
  14.  
  15.     if (prec >= 0)
  16.     {
  17.         for (size = 0; size < prec; size++)
  18.         {
  19.             if (string[size] == '\0')
  20.                 break;
  21.         }
  22.     } else {
  23.         while (string[size++]) ;
  24.         size--;
  25.     }
  26.  
  27.     if (size > (int)maxlen)
  28.         size = maxlen;
  29.  
  30.     maxlen -= size;
  31.     width -= size;
  32.  
  33.     while (size--)
  34.         *buf++ = static_cast<U>(*string++);
  35.  
  36.     while (width-- > 0 && maxlen)
  37.     {
  38.         *buf++ = ' ';
  39.         maxlen--;
  40.     }
  41.  
  42.     *buf_p = buf;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment