I have been trying to make a function in C++ for a gameserver DLL which aligns given text to center before returning the new string to Lua for processing. I have spent quite
std::string center (const std::string& s, unsigned width) { assert (width > 0); if (int padding = width - s.size (), pad = padding >> 1; pad > 0) return std::string (padding, ' ').insert (pad, s); return s; }