Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
guillermocalvo committed Oct 7, 2017
2 parents e3a8988 + 7e7e4f7 commit 388d626
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ check_PROGRAMS = \
bin/check/ldouble \
bin/check/long \
bin/check/longlong \
bin/check/meta \
bin/check/month \
bin/check/percent \
bin/check/person \
Expand All @@ -76,6 +77,7 @@ TESTS = \
bin/check/ldouble \
bin/check/long \
bin/check/longlong \
bin/check/meta \
bin/check/month \
bin/check/percent \
bin/check/person \
Expand Down Expand Up @@ -106,6 +108,7 @@ bin_check_intmax_SOURCES = src/fmt.c test/intmax.c
bin_check_ldouble_SOURCES = src/fmt.c test/ldouble.c
bin_check_long_SOURCES = src/fmt.c test/long.c
bin_check_longlong_SOURCES = src/fmt.c test/longlong.c
bin_check_meta_SOURCES = src/fmt.c test/meta.c
bin_check_month_SOURCES = src/fmt.c test/month.c
bin_check_percent_SOURCES = src/fmt.c test/percent.c
bin_check_person_SOURCES = src/fmt.c test/person.c
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AC_PREREQ([2.68])


# Initialize package
AC_INIT([fmt], [3.0.6], [[email protected]], [fmt], [https://github.com/guillermocalvo/fmt/])
AC_INIT([fmt], [1.3], [[email protected]], [fmt], [https://github.com/guillermocalvo/fmt/])


# Information on the package
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fmt",
"version": "1.2",
"version": "1.3",
"description": "A tiny C string formatting library",
"repo": "guillermocalvo/fmt",
"license": "LGPL",
Expand Down
8 changes: 7 additions & 1 deletion src/fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* fmt source code file
*
* @version 1.2
* @version 1.3
* @author Copyright (c) 2017 Guillermo Calvo
*
*/
Expand Down Expand Up @@ -32,6 +32,7 @@

# define PARAM_MARK '%'
# define PARAM_BEGIN '{'
# define PARAM_META '@'
# define PARAM_OPTIONS ':'
# define PARAM_END '}'

Expand Down Expand Up @@ -241,6 +242,11 @@ int fmt_vprint(struct fmt_stream * out, const char * format, va_list * arg){
case TYPE_PERCENT: result = PRINT_BUILTIN(out, param, arg, 0); break;
}

}else if(*param.id == PARAM_META){
/* print meta formatter */
fmt_formatter meta = va_arg(*arg, fmt_formatter);
result = meta(out, param.id + 1, param.options, arg);

}else{
/* print extended parameter */
struct fmt_handler * handler = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* fmt header file
*
* @version 1.2
* @version 1.3
* @author Copyright (c) 2017 Guillermo Calvo
*
*/
Expand Down
28 changes: 28 additions & 0 deletions test/meta.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

# include "testing.h"


static char buffer[128];

int format_meta(struct fmt_stream * out, const char * id, const char * options, va_list * arg);

/**
* Test print meta formatter
*/
TEST_CASE{

struct fmt_stream out = {0};

fmt_stream_buffer(&out, buffer, sizeof(buffer));

(void)fmt_print(&out, "TEST %{@META:OPTIONS} TEST", format_meta, 123);

TEST_EQUALS("TEST (META/123/OPTIONS) TEST", buffer);
}

int format_meta(struct fmt_stream * out, const char * id, const char * options, va_list * arg){

int number = va_arg(*arg, int);

return( fmt_print_builtin(out, "(%s/%d/%s)", id, number, options) );
}

0 comments on commit 388d626

Please sign in to comment.