diff options
author | Remko Tronçon <git@el-tramo.be> | 2011-02-14 18:57:18 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-02-14 21:36:32 (GMT) |
commit | cb05f5a908e20006c954ce38755c2e422ecc2388 (patch) | |
tree | a793551a5fe279a57d4330119560e8542f745484 /Swiften/JID | |
parent | cad974b45c0fb9355e68d9728e42c9ae3dbcebc7 (diff) | |
download | swift-cb05f5a908e20006c954ce38755c2e422ecc2388.zip swift-cb05f5a908e20006c954ce38755c2e422ecc2388.tar.bz2 |
Removed Swift::String.
Diffstat (limited to 'Swiften/JID')
-rw-r--r-- | Swiften/JID/JID.cpp | 43 | ||||
-rw-r--r-- | Swiften/JID/JID.h | 30 | ||||
-rw-r--r-- | Swiften/JID/UnitTest/JIDTest.cpp | 58 |
3 files changed, 66 insertions, 65 deletions
diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp index 3ecd881..e4611b3 100644 --- a/Swiften/JID/JID.cpp +++ b/Swiften/JID/JID.cpp @@ -9,17 +9,18 @@ #include <vector> #include <iostream> -#include <Swiften/Base/String.h> +#include <string> #ifdef SWIFTEN_CACHE_JID_PREP #include <boost/unordered_map.hpp> #endif #include <stringprep.h> +#include <Swiften/Base/String.h> #include "Swiften/JID/JID.h" #include "Swiften/IDN/StringPrep.h" #ifdef SWIFTEN_CACHE_JID_PREP -typedef boost::unordered_map<std::string, Swift::String> PrepCache; +typedef boost::unordered_map<std::string, std::string> PrepCache; static PrepCache nodePrepCache; static PrepCache domainPrepCache; @@ -29,39 +30,39 @@ static PrepCache resourcePrepCache; namespace Swift { JID::JID(const char* jid) { - initializeFromString(String(jid)); + initializeFromString(std::string(jid)); } -JID::JID(const String& jid) { +JID::JID(const std::string& jid) { initializeFromString(jid); } -JID::JID(const String& node, const String& domain) : hasResource_(false) { +JID::JID(const std::string& node, const std::string& domain) : hasResource_(false) { nameprepAndSetComponents(node, domain, ""); } -JID::JID(const String& node, const String& domain, const String& resource) : hasResource_(true) { +JID::JID(const std::string& node, const std::string& domain, const std::string& resource) : hasResource_(true) { nameprepAndSetComponents(node, domain, resource); } -void JID::initializeFromString(const String& jid) { - if (jid.beginsWith('@')) { +void JID::initializeFromString(const std::string& jid) { + if (String::beginsWith(jid, '@')) { return; } - String bare, resource; + std::string bare, resource; size_t slashIndex = jid.find('/'); - if (slashIndex != jid.npos()) { + if (slashIndex != jid.npos) { hasResource_ = true; - bare = jid.getSubstring(0, slashIndex); - resource = jid.getSubstring(slashIndex + 1, jid.npos()); + bare = jid.substr(0, slashIndex); + resource = jid.substr(slashIndex + 1, jid.npos); } else { hasResource_ = false; bare = jid; } - std::pair<String,String> nodeAndDomain = bare.getSplittedAtFirst('@'); - if (nodeAndDomain.second.isEmpty()) { + std::pair<std::string,std::string> nodeAndDomain = String::getSplittedAtFirst(bare, '@'); + if (nodeAndDomain.second.empty()) { nameprepAndSetComponents("", nodeAndDomain.first, resource); } else { @@ -70,7 +71,7 @@ void JID::initializeFromString(const String& jid) { } -void JID::nameprepAndSetComponents(const String& node, const String& domain, const String& resource) { +void JID::nameprepAndSetComponents(const std::string& node, const std::string& domain, const std::string& resource) { #ifndef SWIFTEN_CACHE_JID_PREP node_ = StringPrep::getPrepared(node, StringPrep::NamePrep); domain_ = StringPrep::getPrepared(domain, StringPrep::XMPPNodePrep); @@ -78,19 +79,19 @@ void JID::nameprepAndSetComponents(const String& node, const String& domain, con #else std::pair<PrepCache::iterator, bool> r; - r = nodePrepCache.insert(std::make_pair(node.getUTF8String(), String())); + r = nodePrepCache.insert(std::make_pair(node, std::string())); if (r.second) { r.first->second = StringPrep::getPrepared(node, StringPrep::NamePrep); } node_ = r.first->second; - r = domainPrepCache.insert(std::make_pair(domain.getUTF8String(), String())); + r = domainPrepCache.insert(std::make_pair(domain, std::string())); if (r.second) { r.first->second = StringPrep::getPrepared(domain, StringPrep::XMPPNodePrep); } domain_ = r.first->second; - r = resourcePrepCache.insert(std::make_pair(resource.getUTF8String(), String())); + r = resourcePrepCache.insert(std::make_pair(resource, std::string())); if (r.second) { r.first->second = StringPrep::getPrepared(resource, StringPrep::XMPPResourcePrep); } @@ -98,9 +99,9 @@ void JID::nameprepAndSetComponents(const String& node, const String& domain, con #endif } -String JID::toString() const { - String string; - if (!node_.isEmpty()) { +std::string JID::toString() const { + std::string string; + if (!node_.empty()) { string += node_ + "@"; } string += domain_; diff --git a/Swiften/JID/JID.h b/Swiften/JID/JID.h index 76c2606..78136ff 100644 --- a/Swiften/JID/JID.h +++ b/Swiften/JID/JID.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Base/String.h" +#include <string> namespace Swift { class JID { @@ -15,22 +15,22 @@ namespace Swift { WithResource, WithoutResource }; - explicit JID(const String& = String()); + explicit JID(const std::string& = std::string()); explicit JID(const char*); - JID(const String& node, const String& domain); - JID(const String& node, const String& domain, const String& resource); + JID(const std::string& node, const std::string& domain); + JID(const std::string& node, const std::string& domain, const std::string& resource); bool isValid() const { - return !domain_.isEmpty(); /* FIXME */ + return !domain_.empty(); /* FIXME */ } - const String& getNode() const { + const std::string& getNode() const { return node_; } - const String& getDomain() const { + const std::string& getDomain() const { return domain_; } - const String& getResource() const { + const std::string& getResource() const { return resource_; } bool isBare() const { @@ -44,7 +44,7 @@ namespace Swift { return result; } - String toString() const; + std::string toString() const; bool equals(const JID& o, CompareType compareType) const { return compare(o, compareType) == 0; @@ -52,7 +52,7 @@ namespace Swift { int compare(const JID& o, CompareType compareType) const; - operator String() const { + operator std::string() const { return toString(); } @@ -74,13 +74,13 @@ namespace Swift { } private: - void nameprepAndSetComponents(const String& node, const String& domain, const String& resource); - void initializeFromString(const String&); + void nameprepAndSetComponents(const std::string& node, const std::string& domain, const std::string& resource); + void initializeFromString(const std::string&); private: - String node_; - String domain_; + std::string node_; + std::string domain_; bool hasResource_; - String resource_; + std::string resource_; }; } diff --git a/Swiften/JID/UnitTest/JIDTest.cpp b/Swiften/JID/UnitTest/JIDTest.cpp index 51e6d2c..0f22e15 100644 --- a/Swiften/JID/UnitTest/JIDTest.cpp +++ b/Swiften/JID/UnitTest/JIDTest.cpp @@ -59,18 +59,18 @@ class JIDTest : public CppUnit::TestFixture void testConstructorWithString() { JID testling("foo@bar/baz"); - CPPUNIT_ASSERT_EQUAL(String("foo"), testling.getNode()); - CPPUNIT_ASSERT_EQUAL(String("bar"), testling.getDomain()); - CPPUNIT_ASSERT_EQUAL(String("baz"), testling.getResource()); + CPPUNIT_ASSERT_EQUAL(std::string("foo"), testling.getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getDomain()); + CPPUNIT_ASSERT_EQUAL(std::string("baz"), testling.getResource()); CPPUNIT_ASSERT(!testling.isBare()); } void testConstructorWithString_NoResource() { JID testling("foo@bar"); - CPPUNIT_ASSERT_EQUAL(String("foo"), testling.getNode()); - CPPUNIT_ASSERT_EQUAL(String("bar"), testling.getDomain()); - CPPUNIT_ASSERT_EQUAL(String(""), testling.getResource()); + CPPUNIT_ASSERT_EQUAL(std::string("foo"), testling.getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getDomain()); + CPPUNIT_ASSERT_EQUAL(std::string(""), testling.getResource()); CPPUNIT_ASSERT(testling.isBare()); } @@ -84,38 +84,38 @@ class JIDTest : public CppUnit::TestFixture void testConstructorWithString_NoNode() { JID testling("bar/baz"); - CPPUNIT_ASSERT_EQUAL(String(""), testling.getNode()); - CPPUNIT_ASSERT_EQUAL(String("bar"), testling.getDomain()); - CPPUNIT_ASSERT_EQUAL(String("baz"), testling.getResource()); + CPPUNIT_ASSERT_EQUAL(std::string(""), testling.getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getDomain()); + CPPUNIT_ASSERT_EQUAL(std::string("baz"), testling.getResource()); CPPUNIT_ASSERT(!testling.isBare()); } void testConstructorWithString_OnlyDomain() { JID testling("bar"); - CPPUNIT_ASSERT_EQUAL(String(""), testling.getNode()); - CPPUNIT_ASSERT_EQUAL(String("bar"), testling.getDomain()); - CPPUNIT_ASSERT_EQUAL(String(""), testling.getResource()); + CPPUNIT_ASSERT_EQUAL(std::string(""), testling.getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getDomain()); + CPPUNIT_ASSERT_EQUAL(std::string(""), testling.getResource()); CPPUNIT_ASSERT(testling.isBare()); } void testConstructorWithString_UpperCaseNode() { JID testling("Fo\xCE\xA9@bar"); - CPPUNIT_ASSERT_EQUAL(String("fo\xCF\x89"), testling.getNode()); - CPPUNIT_ASSERT_EQUAL(String("bar"), testling.getDomain()); + CPPUNIT_ASSERT_EQUAL(std::string("fo\xCF\x89"), testling.getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getDomain()); } void testConstructorWithString_UpperCaseDomain() { JID testling("Fo\xCE\xA9"); - CPPUNIT_ASSERT_EQUAL(String("fo\xCF\x89"), testling.getDomain()); + CPPUNIT_ASSERT_EQUAL(std::string("fo\xCF\x89"), testling.getDomain()); } void testConstructorWithString_UpperCaseResource() { JID testling("bar/Fo\xCE\xA9"); - CPPUNIT_ASSERT_EQUAL(testling.getResource(), String("Fo\xCE\xA9")); + CPPUNIT_ASSERT_EQUAL(testling.getResource(), std::string("Fo\xCE\xA9")); } void testConstructorWithString_EmptyNode() { @@ -127,9 +127,9 @@ class JIDTest : public CppUnit::TestFixture void testConstructorWithStrings() { JID testling("foo", "bar", "baz"); - CPPUNIT_ASSERT_EQUAL(String("foo"), testling.getNode()); - CPPUNIT_ASSERT_EQUAL(String("bar"), testling.getDomain()); - CPPUNIT_ASSERT_EQUAL(String("baz"), testling.getResource()); + CPPUNIT_ASSERT_EQUAL(std::string("foo"), testling.getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getDomain()); + CPPUNIT_ASSERT_EQUAL(std::string("baz"), testling.getResource()); } void testIsBare() { @@ -143,49 +143,49 @@ class JIDTest : public CppUnit::TestFixture void testToBare() { JID testling("foo@bar/baz"); - CPPUNIT_ASSERT_EQUAL(String("foo"), testling.toBare().getNode()); - CPPUNIT_ASSERT_EQUAL(String("bar"), testling.toBare().getDomain()); + CPPUNIT_ASSERT_EQUAL(std::string("foo"), testling.toBare().getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.toBare().getDomain()); CPPUNIT_ASSERT(testling.toBare().isBare()); } void testToBare_EmptyNode() { JID testling("bar/baz"); - CPPUNIT_ASSERT_EQUAL(String(""), testling.toBare().getNode()); - CPPUNIT_ASSERT_EQUAL(String("bar"), testling.toBare().getDomain()); + CPPUNIT_ASSERT_EQUAL(std::string(""), testling.toBare().getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.toBare().getDomain()); CPPUNIT_ASSERT(testling.toBare().isBare()); } void testToBare_EmptyResource() { JID testling("bar/"); - CPPUNIT_ASSERT_EQUAL(String(""), testling.toBare().getNode()); - CPPUNIT_ASSERT_EQUAL(String("bar"), testling.toBare().getDomain()); + CPPUNIT_ASSERT_EQUAL(std::string(""), testling.toBare().getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.toBare().getDomain()); CPPUNIT_ASSERT(testling.toBare().isBare()); } void testToString() { JID testling("foo@bar/baz"); - CPPUNIT_ASSERT_EQUAL(String("foo@bar/baz"), testling.toString()); + CPPUNIT_ASSERT_EQUAL(std::string("foo@bar/baz"), testling.toString()); } void testToString_EmptyNode() { JID testling("bar/baz"); - CPPUNIT_ASSERT_EQUAL(String("bar/baz"), testling.toString()); + CPPUNIT_ASSERT_EQUAL(std::string("bar/baz"), testling.toString()); } void testToString_NoResource() { JID testling("foo@bar"); - CPPUNIT_ASSERT_EQUAL(String("foo@bar"), testling.toString()); + CPPUNIT_ASSERT_EQUAL(std::string("foo@bar"), testling.toString()); } void testToString_EmptyResource() { JID testling("foo@bar/"); - CPPUNIT_ASSERT_EQUAL(String("foo@bar/"), testling.toString()); + CPPUNIT_ASSERT_EQUAL(std::string("foo@bar/"), testling.toString()); } void testCompare_SmallerNode() { |