summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-05-23 19:09:49 (GMT)
committerVlad Voicu <vladvoic@gmail.com>2011-05-31 18:34:02 (GMT)
commit174421ab5664edc5242184bb84fcccf0a07914ea (patch)
tree7414fdb091254a826d0e4054fa2a5fe66e995e49 /Swiften
parenta2085ddc61b74d630d1b117e6b0a2be05dd911ea (diff)
downloadswift-contrib-174421ab5664edc5242184bb84fcccf0a07914ea.zip
swift-contrib-174421ab5664edc5242184bb84fcccf0a07914ea.tar.bz2
Added makeString().
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Base/String.h18
-rw-r--r--Swiften/JID/JID.cpp8
2 files changed, 21 insertions, 5 deletions
diff --git a/Swiften/Base/String.h b/Swiften/Base/String.h
index 0de6cac..db6c28b 100644
--- a/Swiften/Base/String.h
+++ b/Swiften/Base/String.h
@@ -8,6 +8,7 @@
#include <string>
#include <vector>
+#include <sstream>
#define SWIFTEN_STRING_TO_CFSTRING(a) \
CFStringCreateWithBytes(NULL, reinterpret_cast<const UInt8*>(a.c_str()), a.size(), kCFStringEncodingUTF8, false)
@@ -18,11 +19,28 @@ namespace Swift {
std::pair<std::string, std::string> getSplittedAtFirst(const std::string&, char c);
std::vector<std::string> split(const std::string&, char c);
void replaceAll(std::string&, char c, const std::string& s);
+
inline bool beginsWith(const std::string& s, char c) {
return s.size() > 0 && s[0] == c;
}
+
inline bool endsWith(const std::string& s, char c) {
return s.size() > 0 && s[s.size()-1] == c;
}
};
+
+ class makeString {
+ public:
+ template <typename T> makeString& operator<<(T const& v) {
+ stream << v;
+ return *this;
+ }
+
+ operator std::string() const {
+ return stream.str();
+ }
+
+ private:
+ std::ostringstream stream;
+ };
}
diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp
index 9fa0574..2ebbdd6 100644
--- a/Swiften/JID/JID.cpp
+++ b/Swiften/JID/JID.cpp
@@ -24,6 +24,8 @@
#include <Swiften/JID/JID.h>
#include <Swiften/IDN/StringPrep.h>
+using namespace Swift;
+
#ifdef SWIFTEN_CACHE_JID_PREP
typedef boost::unordered_map<std::string, std::string> PrepCache;
@@ -35,9 +37,7 @@ static PrepCache resourcePrepCache;
static const std::list<char> escapedChars = boost::assign::list_of(' ')('"')('&')('\'')('/')('<')('>')('@')(':');
static std::string getEscaped(char c) {
- std::ostringstream s;
- s << '\\' << std::hex << static_cast<int>(c);
- return s.str();
+ return makeString() << '\\' << std::hex << static_cast<int>(c);
}
static bool getEscapeSequenceValue(const std::string& sequence, unsigned char& value) {
@@ -110,8 +110,6 @@ struct EscapedCharacterFormatter {
};
#endif
-using namespace Swift;
-
JID::JID(const char* jid) {
initializeFromString(std::string(jid));
}