Home | History | Annotate | Line # | Download | only in common
      1  1.1  joerg ///////////////////////////////////////////////////////////////////////////////
      2  1.1  joerg //
      3  1.1  joerg /// \file       tuklib_mstr_fw.c
      4  1.1  joerg /// \brief      Get the field width for printf() e.g. to align table columns
      5  1.1  joerg //
      6  1.1  joerg //  Author:     Lasse Collin
      7  1.1  joerg //
      8  1.1  joerg //  This file has been put into the public domain.
      9  1.1  joerg //  You can do whatever you want with this file.
     10  1.1  joerg //
     11  1.1  joerg ///////////////////////////////////////////////////////////////////////////////
     12  1.1  joerg 
     13  1.1  joerg #include "tuklib_mbstr.h"
     14  1.1  joerg 
     15  1.1  joerg 
     16  1.1  joerg extern int
     17  1.1  joerg tuklib_mbstr_fw(const char *str, int columns_min)
     18  1.1  joerg {
     19  1.1  joerg 	size_t len;
     20  1.1  joerg 	const size_t width = tuklib_mbstr_width(str, &len);
     21  1.1  joerg 	if (width == (size_t)-1)
     22  1.1  joerg 		return -1;
     23  1.1  joerg 
     24  1.1  joerg 	if (width > (size_t)columns_min)
     25  1.1  joerg 		return 0;
     26  1.1  joerg 
     27  1.1  joerg 	if (width < (size_t)columns_min)
     28  1.1  joerg 		len += (size_t)columns_min - width;
     29  1.1  joerg 
     30  1.1  joerg 	return len;
     31  1.1  joerg }
     32