00001
00002
00003
00004
00005
00006
00007 #pragma once
00008
00009 #include <string>
00010 #include <vector>
00011 #include <sstream>
00012
00013 #include <Swiften/Base/API.h>
00014
00015 #define SWIFTEN_STRING_TO_CFSTRING(a) \
00016 CFStringCreateWithBytes(NULL, reinterpret_cast<const UInt8*>(a.c_str()), a.size(), kCFStringEncodingUTF8, false)
00017
00018 namespace Swift {
00019 namespace String {
00020 SWIFTEN_API std::vector<unsigned int> getUnicodeCodePoints(const std::string&);
00021 SWIFTEN_API std::pair<std::string, std::string> getSplittedAtFirst(const std::string&, char c);
00022 SWIFTEN_API std::vector<std::string> split(const std::string&, char c);
00023 SWIFTEN_API void replaceAll(std::string&, char c, const std::string& s);
00024
00025 inline bool beginsWith(const std::string& s, char c) {
00026 return s.size() > 0 && s[0] == c;
00027 }
00028
00029 inline bool endsWith(const std::string& s, char c) {
00030 return s.size() > 0 && s[s.size()-1] == c;
00031 }
00032
00033 std::string convertIntToHexString(int h);
00034 int convertHexStringToInt(const std::string& s);
00035 };
00036
00037 class SWIFTEN_API makeString {
00038 public:
00039 template <typename T> makeString& operator<<(T const& v) {
00040 stream << v;
00041 return *this;
00042 }
00043
00044 operator std::string() const {
00045 return stream.str();
00046 }
00047
00048 private:
00049 std::ostringstream stream;
00050 };
00051 }