2 * Copyright (C) 2012 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include "imv_reason_string.h"
18 #include <utils/debug.h>
20 typedef struct private_imv_reason_string_t private_imv_reason_string_t
;
23 * Private data of an imv_reason_string_t object.
25 struct private_imv_reason_string_t
{
28 * Public members of imv_reason_string_t
30 imv_reason_string_t
public;
38 * Separator concatenating multiple reasons
43 * Contains the concatenated reasons
49 METHOD(imv_reason_string_t
, add_reason
, void,
50 private_imv_reason_string_t
*this, imv_lang_string_t reason
[])
54 s_reason
= imv_lang_string_select_string(reason
, this->lang
);
56 if (this->reasons
.len
)
58 /* append any further reasons */
59 this->reasons
= chunk_cat("mcc", this->reasons
,
60 chunk_from_str(this->separator
),
61 chunk_create(s_reason
, strlen(s_reason
)));
65 /* add the first reason */
66 this->reasons
= chunk_clone(chunk_create(s_reason
, strlen(s_reason
)));
70 METHOD(imv_reason_string_t
, get_encoding
, chunk_t
,
71 private_imv_reason_string_t
*this)
76 METHOD(imv_reason_string_t
, destroy
, void,
77 private_imv_reason_string_t
*this)
79 free(this->reasons
.ptr
);
84 * Described in header.
86 imv_reason_string_t
*imv_reason_string_create(char *lang
, char *separator
)
88 private_imv_reason_string_t
*this;
92 .add_reason
= _add_reason
,
93 .get_encoding
= _get_encoding
,
97 .separator
= separator
,
100 return &this->public;