summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2013-08-22 21:07:51 (GMT)
committerRemko Tronçon <git@el-tramo.be>2013-08-23 08:02:12 (GMT)
commit00284e5f4445a7bbab482196901c5927ea7d5488 (patch)
treef2ca6e0c51632a8aa5a7a884f3b312bacc3a2fb0 /Swiften/Elements/FormField.cpp
parent54da0a4c0cceae947afbde586a97d1cc60c50ed8 (diff)
downloadswift-00284e5f4445a7bbab482196901c5927ea7d5488.zip
swift-00284e5f4445a7bbab482196901c5927ea7d5488.tar.bz2
FormField element refactoring.
This should make FormField easier to use. Change-Id: Ia5eeedcdb673e2fe5e38fd23d5ab00970178bc44
Diffstat (limited to 'Swiften/Elements/FormField.cpp')
-rw-r--r--Swiften/Elements/FormField.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/Swiften/Elements/FormField.cpp b/Swiften/Elements/FormField.cpp
new file mode 100644
index 0000000..27ced82
--- /dev/null
+++ b/Swiften/Elements/FormField.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Swiften/Elements/FormField.h>
+
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string/join.hpp>
+#include <boost/algorithm/string/classification.hpp>
+
+using namespace Swift;
+
+FormField::~FormField() {
+}
+
+std::string FormField::getTextMultiValue() const {
+ assert(type == TextMultiType || type == UnknownType);
+ return boost::algorithm::join(values, "\n");
+}
+
+void FormField::setTextMultiValue(const std::string& value) {
+ assert(type == TextMultiType || type == UnknownType);
+ values.clear();
+ boost::split(values, value, boost::is_any_of("\n"));
+}
+
+void FormField::setBoolValue(bool b) {
+ assert(type == BooleanType || type == UnknownType);
+ values.clear();
+ values.push_back(b ? "1" : "0");
+}