Browse Source

adding strlist() converter

AllGroupDevicesShowHandshake
Volker Birk 6 years ago
parent
commit
3c998aaba8
2 changed files with 40 additions and 0 deletions
  1. +36
    -0
      src/str_attr.cc
  2. +4
    -0
      src/str_attr.hh

+ 36
- 0
src/str_attr.cc View File

@ -37,6 +37,42 @@ namespace pEp {
free_timestamp(ts);
ts = new_timestamp(value);
}
list strlist(stringlist_t *&sl)
{
list result;
for (stringlist_t *_sl = sl; _sl && _sl->value; _sl = _sl->next) {
string s(_sl->value);
result.append(object(s));
}
return result;
}
void strlist(stringlist_t *&sl, list value)
{
stringlist_t *_sl = new_stringlist(NULL);
if (!_sl)
throw bad_alloc();
stringlist_t *_s = _sl;
for (int i=0; i<len(value); i++) {
extract< string > extract_string(value[i]);
if (!extract_string.check()) {
free_stringlist(_sl);
}
string s = extract_string();
_s = stringlist_add(_s, s.c_str());
if (!_s) {
free_stringlist(_sl);
throw bad_alloc();
}
}
free_stringlist(sl);
sl = _sl;
}
}
}

+ 4
- 0
src/str_attr.hh View File

@ -3,6 +3,7 @@
#include <string>
#include <pEp/pEpEngine.h>
#include <pEp/timestamp.h>
#include <pEp/stringlist.h>
namespace pEp {
namespace utility {
@ -14,6 +15,9 @@ namespace pEp {
time_t timestamp_attr(timestamp *&ts);
void timestamp_attr(timestamp *&ts, time_t value);
list strlist(stringlist_t *&sl);
void strlist(stringlist_t *&sl, list value);
}
}

Loading…
Cancel
Save