mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
fmt: add fmt_char
This commit is contained in:
parent
db4ce5eff2
commit
8c5ffa0a8d
@ -415,7 +415,15 @@ size_t fmt_lpad(char *out, size_t in_len, size_t pad_len, char pad_char)
|
||||
return pad_len;
|
||||
}
|
||||
|
||||
size_t fmt_char(char *out, char c)
|
||||
{
|
||||
if (out) {
|
||||
*out = c;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t fmt_to_lower(char *out, const char *str)
|
||||
{
|
||||
size_t len = 0;
|
||||
|
@ -310,6 +310,19 @@ size_t fmt_s32_dfp(char *out, int32_t val, int fp_digits);
|
||||
*/
|
||||
size_t fmt_float(char *out, float f, unsigned precision);
|
||||
|
||||
/**
|
||||
* @brief Copy @p in char to string (without terminating '\0')
|
||||
*
|
||||
* If @p out is NULL, will only return the number of bytes that would have
|
||||
* been written.
|
||||
*
|
||||
* @param[out] out string to write to (or NULL)
|
||||
* @param[in] c char value to append
|
||||
*
|
||||
* @return nr of bytes the function did or would write to out
|
||||
*/
|
||||
size_t fmt_char(char *out, char c);
|
||||
|
||||
/**
|
||||
* @brief Count characters until '\0' (exclusive) in @p str
|
||||
*
|
||||
|
@ -749,6 +749,16 @@ static void test_fmt_str(void)
|
||||
TEST_ASSERT_EQUAL_STRING(string1, &string2[0]);
|
||||
}
|
||||
|
||||
static void test_fmt_char(void)
|
||||
{
|
||||
char string[] = "zzzzzzzzz";
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(1, fmt_char(NULL, 'c'));
|
||||
TEST_ASSERT_EQUAL_INT(1, fmt_char(string, 'c'));
|
||||
string[1] = '\0';
|
||||
TEST_ASSERT_EQUAL_STRING("c", &string[0]);
|
||||
}
|
||||
|
||||
static void test_fmt_to_lower(void)
|
||||
{
|
||||
const char string_up[] = "AbCdeFGHijkLM";
|
||||
@ -827,6 +837,7 @@ Test *tests_fmt_tests(void)
|
||||
new_TestFixture(test_fmt_strlen),
|
||||
new_TestFixture(test_fmt_strnlen),
|
||||
new_TestFixture(test_fmt_str),
|
||||
new_TestFixture(test_fmt_char),
|
||||
new_TestFixture(test_fmt_to_lower),
|
||||
new_TestFixture(test_scn_u32_dec),
|
||||
new_TestFixture(test_fmt_lpad),
|
||||
|
Loading…
Reference in New Issue
Block a user