xpcom/string/public/nsTSubstringTuple.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/string/public/nsTSubstringTuple.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,78 @@
     1.4 +//* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +// IWYU pragma: private, include "nsString.h"
    1.10 +
    1.11 +  /**
    1.12 +   * nsTSubstringTuple_CharT
    1.13 +   *
    1.14 +   * Represents a tuple of string fragments.  Built as a recursive binary tree.
    1.15 +   * It is used to implement the concatenation of two or more string objects.
    1.16 +   *
    1.17 +   * NOTE: This class is a private implementation detail and should never be 
    1.18 +   * referenced outside the string code.
    1.19 +   */
    1.20 +class nsTSubstringTuple_CharT
    1.21 +  {
    1.22 +    public:
    1.23 +
    1.24 +      typedef CharT                      char_type;
    1.25 +      typedef nsCharTraits<char_type>    char_traits;
    1.26 +
    1.27 +      typedef nsTSubstringTuple_CharT    self_type;
    1.28 +      typedef nsTSubstring_CharT         substring_type;
    1.29 +      typedef nsTSubstring_CharT         base_string_type;
    1.30 +      typedef uint32_t                   size_type;
    1.31 +
    1.32 +    public:
    1.33 +
    1.34 +      nsTSubstringTuple_CharT(const base_string_type* a, const base_string_type* b)
    1.35 +        : mHead(nullptr)
    1.36 +        , mFragA(a)
    1.37 +        , mFragB(b) {}
    1.38 +
    1.39 +      nsTSubstringTuple_CharT(const self_type& head, const base_string_type* b)
    1.40 +        : mHead(&head)
    1.41 +        , mFragA(nullptr) // this fragment is ignored when head != nullptr
    1.42 +        , mFragB(b) {}
    1.43 +
    1.44 +        /**
    1.45 +         * computes the aggregate string length
    1.46 +         */
    1.47 +      size_type Length() const;
    1.48 +
    1.49 +        /**
    1.50 +         * writes the aggregate string to the given buffer.  bufLen is assumed
    1.51 +         * to be equal to or greater than the value returned by the Length()
    1.52 +         * method.  the string written to |buf| is not null-terminated.
    1.53 +         */
    1.54 +      void WriteTo(char_type *buf, uint32_t bufLen) const;
    1.55 +
    1.56 +        /**
    1.57 +         * returns true if this tuple is dependent on (i.e., overlapping with)
    1.58 +         * the given char sequence.
    1.59 +         */
    1.60 +      bool IsDependentOn(const char_type *start, const char_type *end) const;
    1.61 +
    1.62 +    private:
    1.63 +
    1.64 +      const self_type*        mHead;
    1.65 +      const base_string_type* mFragA;
    1.66 +      const base_string_type* mFragB;
    1.67 +  };
    1.68 +
    1.69 +inline
    1.70 +const nsTSubstringTuple_CharT
    1.71 +operator+(const nsTSubstringTuple_CharT::base_string_type& a, const nsTSubstringTuple_CharT::base_string_type& b)
    1.72 +  {
    1.73 +    return nsTSubstringTuple_CharT(&a, &b);
    1.74 +  }
    1.75 +
    1.76 +inline
    1.77 +const nsTSubstringTuple_CharT
    1.78 +operator+(const nsTSubstringTuple_CharT& head, const nsTSubstringTuple_CharT::base_string_type& b)
    1.79 +  {
    1.80 +    return nsTSubstringTuple_CharT(head, &b);
    1.81 +  }

mercurial