2024-02-12 15:09:10 +00:00
|
|
|
// SPDX-License-Identifier: 0BSD
|
|
|
|
|
2010-09-10 07:30:33 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-07-12 15:57:43 +00:00
|
|
|
/// \file tuklib_mbstr_fw.c
|
2010-09-10 07:30:33 +00:00
|
|
|
/// \brief Get the field width for printf() e.g. to align table columns
|
|
|
|
//
|
|
|
|
// Author: Lasse Collin
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "tuklib_mbstr.h"
|
|
|
|
|
|
|
|
|
|
|
|
extern int
|
|
|
|
tuklib_mbstr_fw(const char *str, int columns_min)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
const size_t width = tuklib_mbstr_width(str, &len);
|
|
|
|
if (width == (size_t)-1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (width > (size_t)columns_min)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (width < (size_t)columns_min)
|
|
|
|
len += (size_t)columns_min - width;
|
|
|
|
|
2023-01-12 04:01:12 +00:00
|
|
|
return (int)len;
|
2010-09-10 07:30:33 +00:00
|
|
|
}
|