summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers/FormSerializer.cpp')
-rw-r--r--Swiften/Serializer/PayloadSerializers/FormSerializer.cpp45
1 files changed, 23 insertions, 22 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp b/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp
index 77c2fd4..53b4241 100644
--- a/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp
@@ -8,9 +8,10 @@
#include <boost/shared_ptr.hpp>
#include <iostream>
+#include <string>
-#include "Swiften/Base/foreach.h"
#include "Swiften/Base/String.h"
+#include "Swiften/Base/foreach.h"
#include "Swiften/Serializer/XML/XMLTextNode.h"
#include "Swiften/Serializer/XML/XMLRawTextNode.h"
@@ -18,8 +19,8 @@ using namespace Swift;
namespace {
template<typename T> void serializeValueAsString(boost::shared_ptr<FormField> field, boost::shared_ptr<XMLElement> parent) {
- String value = boost::dynamic_pointer_cast<T>(field)->getValue();
- if (!value.isEmpty()) {
+ std::string value = boost::dynamic_pointer_cast<T>(field)->getValue();
+ if (!value.empty()) {
boost::shared_ptr<XMLElement> valueElement(new XMLElement("value"));
valueElement->addNode(XMLTextNode::create(value));
parent->addNode(valueElement);
@@ -33,9 +34,9 @@ namespace Swift {
FormSerializer::FormSerializer() : GenericPayloadSerializer<Form>() {
}
-String FormSerializer::serializePayload(boost::shared_ptr<Form> form) const {
+std::string FormSerializer::serializePayload(boost::shared_ptr<Form> form) const {
boost::shared_ptr<XMLElement> formElement(new XMLElement("x", "jabber:x:data"));
- String type;
+ std::string type;
switch (form->getType()) {
case Form::FormType: type = "form"; break;
case Form::SubmitType: type = "submit"; break;
@@ -43,10 +44,10 @@ String FormSerializer::serializePayload(boost::shared_ptr<Form> form) const {
case Form::ResultType: type = "result"; break;
}
formElement->setAttribute("type", type);
- if (!form->getTitle().isEmpty()) {
+ if (!form->getTitle().empty()) {
multiLineify(form->getTitle(), "title", formElement);
}
- if (!form->getInstructions().isEmpty()) {
+ if (!form->getInstructions().empty()) {
multiLineify(form->getInstructions(), "instructions", formElement);
}
foreach(boost::shared_ptr<FormField> field, form->getFields()) {
@@ -57,23 +58,23 @@ String FormSerializer::serializePayload(boost::shared_ptr<Form> form) const {
boost::shared_ptr<XMLElement> FormSerializer::fieldToXML(boost::shared_ptr<FormField> field) const {
boost::shared_ptr<XMLElement> fieldElement(new XMLElement("field"));
- if (!field->getName().isEmpty()) {
+ if (!field->getName().empty()) {
fieldElement->setAttribute("var", field->getName());
}
- if (!field->getLabel().isEmpty()) {
+ if (!field->getLabel().empty()) {
fieldElement->setAttribute("label", field->getLabel());
}
if (field->getRequired()) {
fieldElement->addNode(boost::shared_ptr<XMLElement>(new XMLElement("required")));
}
- if (!field->getDescription().isEmpty()) {
+ if (!field->getDescription().empty()) {
boost::shared_ptr<XMLElement> descriptionElement(new XMLElement("desc"));
descriptionElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(field->getDescription())));
fieldElement->addNode(descriptionElement);
}
// Set the value and type
- String fieldType;
+ std::string fieldType;
if (boost::dynamic_pointer_cast<BooleanFormField>(field)) {
fieldType = "boolean";
boost::shared_ptr<XMLElement> valueElement(new XMLElement("value"));
@@ -117,8 +118,8 @@ boost::shared_ptr<XMLElement> FormSerializer::fieldToXML(boost::shared_ptr<FormF
}
else if (boost::dynamic_pointer_cast<ListMultiFormField>(field)) {
fieldType = "list-multi";
- std::vector<String> lines = boost::dynamic_pointer_cast<ListMultiFormField>(field)->getValue();
- foreach(const String& line, lines) {
+ std::vector<std::string> lines = boost::dynamic_pointer_cast<ListMultiFormField>(field)->getValue();
+ foreach(const std::string& line, lines) {
boost::shared_ptr<XMLElement> valueElement(new XMLElement("value"));
valueElement->addNode(XMLTextNode::create(line));
fieldElement->addNode(valueElement);
@@ -129,8 +130,8 @@ boost::shared_ptr<XMLElement> FormSerializer::fieldToXML(boost::shared_ptr<FormF
multiLineify(boost::dynamic_pointer_cast<TextMultiFormField>(field)->getValue(), "value", fieldElement);
}
else if (boost::dynamic_pointer_cast<UntypedFormField>(field)) {
- std::vector<String> lines = boost::dynamic_pointer_cast<UntypedFormField>(field)->getValue();
- foreach(const String& line, lines) {
+ std::vector<std::string> lines = boost::dynamic_pointer_cast<UntypedFormField>(field)->getValue();
+ foreach(const std::string& line, lines) {
boost::shared_ptr<XMLElement> valueElement(new XMLElement("value"));
valueElement->addNode(XMLTextNode::create(line));
fieldElement->addNode(valueElement);
@@ -139,13 +140,13 @@ boost::shared_ptr<XMLElement> FormSerializer::fieldToXML(boost::shared_ptr<FormF
else {
assert(false);
}
- if (!fieldType.isEmpty()) {
+ if (!fieldType.empty()) {
fieldElement->setAttribute("type", fieldType);
}
foreach (const FormField::Option& option, field->getOptions()) {
boost::shared_ptr<XMLElement> optionElement(new XMLElement("option"));
- if (!option.label.isEmpty()) {
+ if (!option.label.empty()) {
optionElement->setAttribute("label", option.label);
}
@@ -159,11 +160,11 @@ boost::shared_ptr<XMLElement> FormSerializer::fieldToXML(boost::shared_ptr<FormF
return fieldElement;
}
-void FormSerializer::multiLineify(const String& text, const String& elementName, boost::shared_ptr<XMLElement> element) const {
- String unRdText(text);
- unRdText.removeAll('\r');
- std::vector<String> lines = unRdText.split('\n');
- foreach (String line, lines) {
+void FormSerializer::multiLineify(const std::string& text, const std::string& elementName, boost::shared_ptr<XMLElement> element) const {
+ std::string unRdText(text);
+ unRdText.erase(std::remove(unRdText.begin(), unRdText.end(), '\r'), unRdText.end());
+ std::vector<std::string> lines = String::split(unRdText, '\n');
+ foreach (std::string line, lines) {
boost::shared_ptr<XMLElement> lineElement(new XMLElement(elementName));
lineElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(line)));
element->addNode(lineElement);