1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "talk/xmllite/qname.h" 6 7 #include "talk/base/common.h" 8 #include "talk/xmllite/xmlelement.h" 9 #include "talk/xmllite/xmlconstants.h" 10 11 namespace buzz { 12 13 QName::QName() : namespace_(QN_EMPTY.namespace_), 14 local_part_(QN_EMPTY.local_part_) {} 15 16 QName::QName(const std::string & ns, const std::string & local) : 17 namespace_(ns), local_part_(local) {} 18 19 QName::QName(bool add, const std::string & ns, const std::string & local) : 20 namespace_(ns), local_part_(local) {} 21 22 static std::string 23 QName_LocalPart(const std::string & name) { 24 size_t i = name.rfind(':'); 25 if (i == std::string::npos) 26 return name; 27 return name.substr(i + 1); 28 } 29 30 static std::string 31 QName_Namespace(const std::string & name) { 32 size_t i = name.rfind(':'); 33 if (i == std::string::npos) 34 return STR_EMPTY; 35 return name.substr(0, i); 36 } 37 38 QName::QName(const std::string & mergedOrLocal) : 39 namespace_(QName_Namespace(mergedOrLocal)), 40 local_part_(QName_LocalPart(mergedOrLocal)) {} 41 42 std::string 43 QName::Merged() const { 44 if (namespace_ == STR_EMPTY) 45 return local_part_; 46 return namespace_ + ':' + local_part_; 47 } 48 49 bool 50 QName::operator==(const QName & other) const { 51 return 52 local_part_ == other.local_part_ && 53 namespace_ == other.namespace_; 54 } 55 56 int 57 QName::Compare(const QName & other) const { 58 int result = local_part_.compare(other.local_part_); 59 if (result) 60 return result; 61 62 return namespace_.compare(other.namespace_); 63 } 64 65 } // namespace buzz 66