Browse Source

adding strlist() converter

PYADPT-55
Volker Birk 9 years ago
parent
commit
3c998aaba8
  1. 36
      src/str_attr.cc
  2. 4
      src/str_attr.hh

36
src/str_attr.cc

@ -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
src/str_attr.hh

@ -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