xpcom/string/public/nsTDependentSubstring.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6 // IWYU pragma: private, include "nsString.h"
michael@0 7
michael@0 8 /**
michael@0 9 * nsTDependentSubstring_CharT
michael@0 10 *
michael@0 11 * A string class which wraps an external array of string characters. It
michael@0 12 * is the client code's responsibility to ensure that the external buffer
michael@0 13 * remains valid for a long as the string is alive.
michael@0 14 *
michael@0 15 * NAMES:
michael@0 16 * nsDependentSubstring for wide characters
michael@0 17 * nsDependentCSubstring for narrow characters
michael@0 18 */
michael@0 19 class nsTDependentSubstring_CharT : public nsTSubstring_CharT
michael@0 20 {
michael@0 21 public:
michael@0 22
michael@0 23 typedef nsTDependentSubstring_CharT self_type;
michael@0 24
michael@0 25 public:
michael@0 26
michael@0 27 void Rebind( const substring_type&, uint32_t startPos, uint32_t length = size_type(-1) );
michael@0 28
michael@0 29 void Rebind( const char_type* data, size_type length );
michael@0 30
michael@0 31 void Rebind( const char_type* start, const char_type* end )
michael@0 32 {
michael@0 33 Rebind(start, size_type(end - start));
michael@0 34 }
michael@0 35
michael@0 36 nsTDependentSubstring_CharT( const substring_type& str, uint32_t startPos, uint32_t length = size_type(-1) )
michael@0 37 : substring_type()
michael@0 38 {
michael@0 39 Rebind(str, startPos, length);
michael@0 40 }
michael@0 41
michael@0 42 nsTDependentSubstring_CharT( const char_type* data, size_type length )
michael@0 43 : substring_type(const_cast<char_type*>(data), length, F_NONE) {}
michael@0 44
michael@0 45 nsTDependentSubstring_CharT( const char_type* start, const char_type* end )
michael@0 46 : substring_type(const_cast<char_type*>(start), uint32_t(end - start), F_NONE) {}
michael@0 47
michael@0 48 #if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER)
michael@0 49 nsTDependentSubstring_CharT( char16ptr_t data, size_type length )
michael@0 50 : nsTDependentSubstring_CharT(static_cast<const char16_t*>(data), length) {}
michael@0 51
michael@0 52 nsTDependentSubstring_CharT( char16ptr_t start, char16ptr_t end )
michael@0 53 : nsTDependentSubstring_CharT(static_cast<const char16_t*>(start), static_cast<const char16_t*>(end)) {}
michael@0 54 #endif
michael@0 55
michael@0 56 nsTDependentSubstring_CharT( const const_iterator& start, const const_iterator& end )
michael@0 57 : substring_type(const_cast<char_type*>(start.get()), uint32_t(end.get() - start.get()), F_NONE) {}
michael@0 58
michael@0 59 // Create a nsTDependentSubstring to be bound later
michael@0 60 nsTDependentSubstring_CharT()
michael@0 61 : substring_type() {}
michael@0 62
michael@0 63 // auto-generated copy-constructor OK (XXX really?? what about base class copy-ctor?)
michael@0 64
michael@0 65 private:
michael@0 66 // NOT USED
michael@0 67 void operator=( const self_type& ); // we're immutable, you can't assign into a substring
michael@0 68 };
michael@0 69
michael@0 70 inline
michael@0 71 const nsTDependentSubstring_CharT
michael@0 72 Substring( const nsTSubstring_CharT& str, uint32_t startPos, uint32_t length = uint32_t(-1) )
michael@0 73 {
michael@0 74 return nsTDependentSubstring_CharT(str, startPos, length);
michael@0 75 }
michael@0 76
michael@0 77 inline
michael@0 78 const nsTDependentSubstring_CharT
michael@0 79 Substring( const nsReadingIterator<CharT>& start, const nsReadingIterator<CharT>& end )
michael@0 80 {
michael@0 81 return nsTDependentSubstring_CharT(start.get(), end.get());
michael@0 82 }
michael@0 83
michael@0 84 inline
michael@0 85 const nsTDependentSubstring_CharT
michael@0 86 Substring( const CharT* data, uint32_t length )
michael@0 87 {
michael@0 88 return nsTDependentSubstring_CharT(data, length);
michael@0 89 }
michael@0 90
michael@0 91 inline
michael@0 92 const nsTDependentSubstring_CharT
michael@0 93 Substring( const CharT* start, const CharT* end )
michael@0 94 {
michael@0 95 return nsTDependentSubstring_CharT(start, end);
michael@0 96 }
michael@0 97
michael@0 98 inline
michael@0 99 const nsTDependentSubstring_CharT
michael@0 100 StringHead( const nsTSubstring_CharT& str, uint32_t count )
michael@0 101 {
michael@0 102 return nsTDependentSubstring_CharT(str, 0, count);
michael@0 103 }
michael@0 104
michael@0 105 inline
michael@0 106 const nsTDependentSubstring_CharT
michael@0 107 StringTail( const nsTSubstring_CharT& str, uint32_t count )
michael@0 108 {
michael@0 109 return nsTDependentSubstring_CharT(str, str.Length() - count, count);
michael@0 110 }

mercurial