1213688Smm/////////////////////////////////////////////////////////////////////////////// 2213688Smm// 3213688Smm/// \file tuklib_mstr_fw.c 4213688Smm/// \brief Get the field width for printf() e.g. to align table columns 5213688Smm// 6213688Smm// Author: Lasse Collin 7213688Smm// 8213688Smm// This file has been put into the public domain. 9213688Smm// You can do whatever you want with this file. 10213688Smm// 11213688Smm/////////////////////////////////////////////////////////////////////////////// 12213688Smm 13213688Smm#include "tuklib_mbstr.h" 14213688Smm 15213688Smm 16213688Smmextern int 17213688Smmtuklib_mbstr_fw(const char *str, int columns_min) 18213688Smm{ 19213688Smm size_t len; 20213688Smm const size_t width = tuklib_mbstr_width(str, &len); 21213688Smm if (width == (size_t)-1) 22213688Smm return -1; 23213688Smm 24213688Smm if (width > (size_t)columns_min) 25213688Smm return 0; 26213688Smm 27213688Smm if (width < (size_t)columns_min) 28213688Smm len += (size_t)columns_min - width; 29213688Smm 30213688Smm return len; 31213688Smm} 32