summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-02-12 12:48:14 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-02-12 12:48:14 (GMT)
commitd073e9d261bb7134723e77f142603a555f8f9629 (patch)
tree3949c6749b3fec30a3ae4f7dd70d35aa56f99992 /Swiften
parent5de579953a2e87afd7f4c56962c68f18ab3888aa (diff)
downloadswift-d073e9d261bb7134723e77f142603a555f8f9629.zip
swift-d073e9d261bb7134723e77f142603a555f8f9629.tar.bz2
Share locale object between delay parsers.
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Parser/PayloadParsers/DelayParser.cpp8
-rw-r--r--Swiften/Parser/PayloadParsers/DelayParser.h5
-rw-r--r--Swiften/Parser/PayloadParsers/DelayParserFactory.cpp18
-rw-r--r--Swiften/Parser/PayloadParsers/DelayParserFactory.h7
-rw-r--r--Swiften/Parser/SConscript1
5 files changed, 30 insertions, 9 deletions
diff --git a/Swiften/Parser/PayloadParsers/DelayParser.cpp b/Swiften/Parser/PayloadParsers/DelayParser.cpp
index b6fa240..8e8abff 100644
--- a/Swiften/Parser/PayloadParsers/DelayParser.cpp
+++ b/Swiften/Parser/PayloadParsers/DelayParser.cpp
@@ -12,15 +12,13 @@
namespace Swift {
-DelayParser::DelayParser() : level_(0) {
+DelayParser::DelayParser(const std::locale& locale) : locale(locale), level_(0) {
}
boost::posix_time::ptime DelayParser::dateFromString(const String& string) {
- boost::posix_time::time_input_facet* facet = new boost::posix_time::time_input_facet("%Y-%m-%d %H:%M:%S%F%Q");
- boost::posix_time::ptime result(boost::posix_time::not_a_date_time);
- std::locale dateLocale(std::locale::classic(), facet);
std::istringstream stream(string.getUTF8String());
- stream.imbue(dateLocale);
+ stream.imbue(locale);
+ boost::posix_time::ptime result(boost::posix_time::not_a_date_time);
stream >> result;
return result;
}
diff --git a/Swiften/Parser/PayloadParsers/DelayParser.h b/Swiften/Parser/PayloadParsers/DelayParser.h
index ce92dc2..b2fbdea 100644
--- a/Swiften/Parser/PayloadParsers/DelayParser.h
+++ b/Swiften/Parser/PayloadParsers/DelayParser.h
@@ -12,7 +12,7 @@
namespace Swift {
class DelayParser : public GenericPayloadParser<Delay> {
public:
- DelayParser();
+ DelayParser(const std::locale& locale);
virtual void handleStartElement(const String& element, const String&, const AttributeMap& attributes);
virtual void handleEndElement(const String& element, const String&);
@@ -20,6 +20,9 @@ namespace Swift {
private:
boost::posix_time::ptime dateFromString(const String& string);
+
+ private:
+ std::locale locale;
int level_;
};
}
diff --git a/Swiften/Parser/PayloadParsers/DelayParserFactory.cpp b/Swiften/Parser/PayloadParsers/DelayParserFactory.cpp
new file mode 100644
index 0000000..19d0530
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/DelayParserFactory.cpp
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2010 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swiften/Parser/PayloadParsers/DelayParserFactory.h>
+
+#include <boost/date_time/time_facet.hpp>
+
+namespace Swift {
+
+DelayParserFactory::DelayParserFactory() {
+ boost::posix_time::time_input_facet* facet = new boost::posix_time::time_input_facet("%Y-%m-%d %H:%M:%S%F%Q");
+ locale = std::locale(std::locale::classic(), facet);
+}
+
+}
diff --git a/Swiften/Parser/PayloadParsers/DelayParserFactory.h b/Swiften/Parser/PayloadParsers/DelayParserFactory.h
index 8b1f91e..f3dd328 100644
--- a/Swiften/Parser/PayloadParsers/DelayParserFactory.h
+++ b/Swiften/Parser/PayloadParsers/DelayParserFactory.h
@@ -14,16 +14,17 @@ namespace Swift {
class DelayParserFactory : public PayloadParserFactory {
public:
- DelayParserFactory() {
- }
+ DelayParserFactory();
virtual bool canParse(const String& /*element*/, const String& ns, const AttributeMap&) const {
return ns == "urn:xmpp:delay";
}
virtual PayloadParser* createPayloadParser() {
- return new DelayParser();
+ return new DelayParser(locale);
}
+ private:
+ std::locale locale;
};
}
diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript
index 6e77109..90b3b78 100644
--- a/Swiften/Parser/SConscript
+++ b/Swiften/Parser/SConscript
@@ -25,6 +25,7 @@ sources = [
"PayloadParsers/CapsInfoParser.cpp",
"PayloadParsers/DiscoInfoParser.cpp",
"PayloadParsers/DiscoItemsParser.cpp",
+ "PayloadParsers/DelayParserFactory.cpp",
"PayloadParsers/ErrorParser.cpp",
"PayloadParsers/FormParser.cpp",
"PayloadParsers/IBBParser.cpp",