xpcom/string/public/nsTSubstringTuple.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 //* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 // IWYU pragma: private, include "nsString.h"
     8   /**
     9    * nsTSubstringTuple_CharT
    10    *
    11    * Represents a tuple of string fragments.  Built as a recursive binary tree.
    12    * It is used to implement the concatenation of two or more string objects.
    13    *
    14    * NOTE: This class is a private implementation detail and should never be 
    15    * referenced outside the string code.
    16    */
    17 class nsTSubstringTuple_CharT
    18   {
    19     public:
    21       typedef CharT                      char_type;
    22       typedef nsCharTraits<char_type>    char_traits;
    24       typedef nsTSubstringTuple_CharT    self_type;
    25       typedef nsTSubstring_CharT         substring_type;
    26       typedef nsTSubstring_CharT         base_string_type;
    27       typedef uint32_t                   size_type;
    29     public:
    31       nsTSubstringTuple_CharT(const base_string_type* a, const base_string_type* b)
    32         : mHead(nullptr)
    33         , mFragA(a)
    34         , mFragB(b) {}
    36       nsTSubstringTuple_CharT(const self_type& head, const base_string_type* b)
    37         : mHead(&head)
    38         , mFragA(nullptr) // this fragment is ignored when head != nullptr
    39         , mFragB(b) {}
    41         /**
    42          * computes the aggregate string length
    43          */
    44       size_type Length() const;
    46         /**
    47          * writes the aggregate string to the given buffer.  bufLen is assumed
    48          * to be equal to or greater than the value returned by the Length()
    49          * method.  the string written to |buf| is not null-terminated.
    50          */
    51       void WriteTo(char_type *buf, uint32_t bufLen) const;
    53         /**
    54          * returns true if this tuple is dependent on (i.e., overlapping with)
    55          * the given char sequence.
    56          */
    57       bool IsDependentOn(const char_type *start, const char_type *end) const;
    59     private:
    61       const self_type*        mHead;
    62       const base_string_type* mFragA;
    63       const base_string_type* mFragB;
    64   };
    66 inline
    67 const nsTSubstringTuple_CharT
    68 operator+(const nsTSubstringTuple_CharT::base_string_type& a, const nsTSubstringTuple_CharT::base_string_type& b)
    69   {
    70     return nsTSubstringTuple_CharT(&a, &b);
    71   }
    73 inline
    74 const nsTSubstringTuple_CharT
    75 operator+(const nsTSubstringTuple_CharT& head, const nsTSubstringTuple_CharT::base_string_type& b)
    76   {
    77     return nsTSubstringTuple_CharT(head, &b);
    78   }

mercurial