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 11namespace buzz { 12 13QName::QName() : namespace_(QN_EMPTY.namespace_), 14 local_part_(QN_EMPTY.local_part_) {} 15 16QName::QName(const std::string & ns, const std::string & local) : 17 namespace_(ns), local_part_(local) {} 18 19QName::QName(bool add, const std::string & ns, const std::string & local) : 20 namespace_(ns), local_part_(local) {} 21 22static std::string 23QName_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 30static std::string 31QName_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 38QName::QName(const std::string & mergedOrLocal) : 39 namespace_(QName_Namespace(mergedOrLocal)), 40 local_part_(QName_LocalPart(mergedOrLocal)) {} 41 42std::string 43QName::Merged() const { 44 if (namespace_ == STR_EMPTY) 45 return local_part_; 46 return namespace_ + ':' + local_part_; 47} 48 49bool 50QName::operator==(const QName & other) const { 51 return 52 local_part_ == other.local_part_ && 53 namespace_ == other.namespace_; 54} 55 56int 57QName::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