Add tests and fix minor problems in specifier parser
This commit is contained in:
@@ -2,16 +2,44 @@
|
||||
#define _SIMPLE_PRINTF_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef SIMPLE_PRINTF_ATTR_FORMAT
|
||||
# if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)))
|
||||
# define SIMPLE_PRINTF_ATTR_FORMAT(fmt, args) __attribute__((__format__(__printf__, fmt, args)))
|
||||
# else
|
||||
# define SIMPLE_PRINTF_ATTR_FORMAT(fmt, args)
|
||||
# endif
|
||||
#if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)))
|
||||
#define SIMPLE_PRINTF_ATTR_FORMAT(fmt, args) __attribute__((__format__(__printf__, fmt, args)))
|
||||
#else
|
||||
# define SIMPLE_PRINTF_ATTR_FORMAT(fmt, args)
|
||||
#define SIMPLE_PRINTF_ATTR_FORMAT(fmt, args)
|
||||
#endif
|
||||
#else
|
||||
#define SIMPLE_PRINTF_ATTR_FORMAT(fmt, args)
|
||||
#endif
|
||||
|
||||
enum format_specifier_type {
|
||||
FMT_INVALID = 0,
|
||||
FMT_INTEGER,
|
||||
FMT_UNSIGNED,
|
||||
FMT_STRING,
|
||||
FMT_HEXUINT_CAPITALIZED,
|
||||
FMT_HEXUINT,
|
||||
FMT_CHAR,
|
||||
FMT_SIZE,
|
||||
FMT_PERCENT,
|
||||
};
|
||||
|
||||
struct format_specifier {
|
||||
enum format_specifier_type specifier;
|
||||
size_t length; /**< @brief lenght of formatted output.*/
|
||||
bool zero_pad;
|
||||
size_t length_of_provided_specifier;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Helper function to parse printf format specifiers
|
||||
*
|
||||
* @param start Start of parsing
|
||||
* @param[out] result Result of format specifier parsing
|
||||
*/
|
||||
void parse_format_specifier(const char *start, struct format_specifier *result);
|
||||
|
||||
/**
|
||||
* @brief Simple implementation of snprintf
|
||||
|
Reference in New Issue
Block a user