Home | History | Annotate | Download | only in xmllite
      1 /*
      2  *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #include "webrtc/libjingle/xmllite/qname.h"
     12 
     13 namespace buzz {
     14 
     15 QName::QName() {
     16 }
     17 
     18 QName::QName(const QName& qname)
     19     : namespace_(qname.namespace_),
     20       local_part_(qname.local_part_) {
     21 }
     22 
     23 QName::QName(const StaticQName& const_value)
     24     : namespace_(const_value.ns),
     25       local_part_(const_value.local) {
     26 }
     27 
     28 QName::QName(const std::string& ns, const std::string& local)
     29     : namespace_(ns),
     30       local_part_(local) {
     31 }
     32 
     33 QName::QName(const std::string& merged_or_local) {
     34   size_t i = merged_or_local.rfind(':');
     35   if (i == std::string::npos) {
     36     local_part_ = merged_or_local;
     37   } else {
     38     namespace_ = merged_or_local.substr(0, i);
     39     local_part_ = merged_or_local.substr(i + 1);
     40   }
     41 }
     42 
     43 QName::~QName() {
     44 }
     45 
     46 std::string QName::Merged() const {
     47   if (namespace_[0] == '\0')
     48     return local_part_;
     49 
     50   std::string result;
     51   result.reserve(namespace_.length() + 1 + local_part_.length());
     52   result += namespace_;
     53   result += ':';
     54   result += local_part_;
     55   return result;
     56 }
     57 
     58 bool QName::IsEmpty() const {
     59   return namespace_.empty() && local_part_.empty();
     60 }
     61 
     62 int QName::Compare(const StaticQName& other) const {
     63   int result = local_part_.compare(other.local);
     64   if (result != 0)
     65     return result;
     66 
     67   return namespace_.compare(other.ns);
     68 }
     69 
     70 int QName::Compare(const QName& other) const {
     71   int result = local_part_.compare(other.local_part_);
     72   if (result != 0)
     73     return result;
     74 
     75   return namespace_.compare(other.namespace_);
     76 }
     77 
     78 }  // namespace buzz
     79