1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/string/public/nsTDependentSubstring.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,110 @@ 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 + * nsTDependentSubstring_CharT 1.13 + * 1.14 + * A string class which wraps an external array of string characters. It 1.15 + * is the client code's responsibility to ensure that the external buffer 1.16 + * remains valid for a long as the string is alive. 1.17 + * 1.18 + * NAMES: 1.19 + * nsDependentSubstring for wide characters 1.20 + * nsDependentCSubstring for narrow characters 1.21 + */ 1.22 +class nsTDependentSubstring_CharT : public nsTSubstring_CharT 1.23 + { 1.24 + public: 1.25 + 1.26 + typedef nsTDependentSubstring_CharT self_type; 1.27 + 1.28 + public: 1.29 + 1.30 + void Rebind( const substring_type&, uint32_t startPos, uint32_t length = size_type(-1) ); 1.31 + 1.32 + void Rebind( const char_type* data, size_type length ); 1.33 + 1.34 + void Rebind( const char_type* start, const char_type* end ) 1.35 + { 1.36 + Rebind(start, size_type(end - start)); 1.37 + } 1.38 + 1.39 + nsTDependentSubstring_CharT( const substring_type& str, uint32_t startPos, uint32_t length = size_type(-1) ) 1.40 + : substring_type() 1.41 + { 1.42 + Rebind(str, startPos, length); 1.43 + } 1.44 + 1.45 + nsTDependentSubstring_CharT( const char_type* data, size_type length ) 1.46 + : substring_type(const_cast<char_type*>(data), length, F_NONE) {} 1.47 + 1.48 + nsTDependentSubstring_CharT( const char_type* start, const char_type* end ) 1.49 + : substring_type(const_cast<char_type*>(start), uint32_t(end - start), F_NONE) {} 1.50 + 1.51 +#if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER) 1.52 + nsTDependentSubstring_CharT( char16ptr_t data, size_type length ) 1.53 + : nsTDependentSubstring_CharT(static_cast<const char16_t*>(data), length) {} 1.54 + 1.55 + nsTDependentSubstring_CharT( char16ptr_t start, char16ptr_t end ) 1.56 + : nsTDependentSubstring_CharT(static_cast<const char16_t*>(start), static_cast<const char16_t*>(end)) {} 1.57 +#endif 1.58 + 1.59 + nsTDependentSubstring_CharT( const const_iterator& start, const const_iterator& end ) 1.60 + : substring_type(const_cast<char_type*>(start.get()), uint32_t(end.get() - start.get()), F_NONE) {} 1.61 + 1.62 + // Create a nsTDependentSubstring to be bound later 1.63 + nsTDependentSubstring_CharT() 1.64 + : substring_type() {} 1.65 + 1.66 + // auto-generated copy-constructor OK (XXX really?? what about base class copy-ctor?) 1.67 + 1.68 + private: 1.69 + // NOT USED 1.70 + void operator=( const self_type& ); // we're immutable, you can't assign into a substring 1.71 + }; 1.72 + 1.73 +inline 1.74 +const nsTDependentSubstring_CharT 1.75 +Substring( const nsTSubstring_CharT& str, uint32_t startPos, uint32_t length = uint32_t(-1) ) 1.76 + { 1.77 + return nsTDependentSubstring_CharT(str, startPos, length); 1.78 + } 1.79 + 1.80 +inline 1.81 +const nsTDependentSubstring_CharT 1.82 +Substring( const nsReadingIterator<CharT>& start, const nsReadingIterator<CharT>& end ) 1.83 + { 1.84 + return nsTDependentSubstring_CharT(start.get(), end.get()); 1.85 + } 1.86 + 1.87 +inline 1.88 +const nsTDependentSubstring_CharT 1.89 +Substring( const CharT* data, uint32_t length ) 1.90 + { 1.91 + return nsTDependentSubstring_CharT(data, length); 1.92 + } 1.93 + 1.94 +inline 1.95 +const nsTDependentSubstring_CharT 1.96 +Substring( const CharT* start, const CharT* end ) 1.97 + { 1.98 + return nsTDependentSubstring_CharT(start, end); 1.99 + } 1.100 + 1.101 +inline 1.102 +const nsTDependentSubstring_CharT 1.103 +StringHead( const nsTSubstring_CharT& str, uint32_t count ) 1.104 + { 1.105 + return nsTDependentSubstring_CharT(str, 0, count); 1.106 + } 1.107 + 1.108 +inline 1.109 +const nsTDependentSubstring_CharT 1.110 +StringTail( const nsTSubstring_CharT& str, uint32_t count ) 1.111 + { 1.112 + return nsTDependentSubstring_CharT(str, str.Length() - count, count); 1.113 + }