From 4ce9a63053cebb547552fce8c60499216ccdbc8a Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Tue, 4 Mar 2014 16:32:08 +0100 Subject: [PATCH] shared/hfp: Add hfp_gw_result_get_number_default function --- src/shared/hfp.c | 17 +++++++++++++++++ src/shared/hfp.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/src/shared/hfp.c b/src/shared/hfp.c index 44b5b5529..08393d87c 100644 --- a/src/shared/hfp.c +++ b/src/shared/hfp.c @@ -224,6 +224,23 @@ static void next_field(struct hfp_gw_result *result) result->offset++; } +bool hfp_gw_result_get_number_default(struct hfp_gw_result *result, + unsigned int *val, + unsigned int default_val) +{ + skip_whitespace(result); + + if (result->data[result->offset] == ',') { + if (val) + *val = default_val; + + result->offset++; + return true; + } + + return hfp_gw_result_get_number(result, val); +} + bool hfp_gw_result_get_number(struct hfp_gw_result *result, unsigned int *val) { int tmp = 0; diff --git a/src/shared/hfp.h b/src/shared/hfp.h index 4da5c97b3..743db657b 100644 --- a/src/shared/hfp.h +++ b/src/shared/hfp.h @@ -114,6 +114,9 @@ bool hfp_gw_register(struct hfp_gw *hfp, hfp_result_func_t callback, bool hfp_gw_unregister(struct hfp_gw *hfp, const char *prefix); bool hfp_gw_result_get_number(struct hfp_gw_result *result, unsigned int *val); +bool hfp_gw_result_get_number_default(struct hfp_gw_result *result, + unsigned int *val, + unsigned int default_val); bool hfp_gw_result_open_container(struct hfp_gw_result *result); bool hfp_gw_result_close_container(struct hfp_gw_result *result); bool hfp_gw_result_get_string(struct hfp_gw_result *result, char *buf, -- 2.47.3