2014-05-05 21:30:46 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2013-09-23 21:23:56 +04:00
|
|
|
// IWYU pragma: private, include "nsString.h"
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
#ifndef nsTString_h
|
|
|
|
#define nsTString_h
|
|
|
|
|
|
|
|
#include "nsTSubstring.h"
|
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
/**
|
|
|
|
* This is the canonical null-terminated string class. All subclasses
|
|
|
|
* promise null-terminated storage. Instances of this class allocate
|
|
|
|
* strings on the heap.
|
|
|
|
*
|
|
|
|
* NAMES:
|
|
|
|
* nsString for wide characters
|
|
|
|
* nsCString for narrow characters
|
|
|
|
*
|
|
|
|
* This class is also known as nsAFlat[C]String, where "flat" is used
|
|
|
|
* to denote a null-terminated string.
|
|
|
|
*/
|
2017-08-15 00:22:50 +03:00
|
|
|
template <typename T>
|
|
|
|
class nsTString : public nsTSubstring<T>
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
public:
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
typedef nsTString<T> self_type;
|
|
|
|
|
|
|
|
#ifdef __clang__
|
|
|
|
// bindgen w/ clang 3.9 at least chokes on a typedef, but using is okay.
|
|
|
|
using typename nsTSubstring<T>::substring_type;
|
|
|
|
#else
|
|
|
|
// On the other hand msvc chokes on the using statement. It seems others
|
|
|
|
// don't care either way so we lump them in here.
|
|
|
|
typedef typename nsTSubstring<T>::substring_type substring_type;
|
|
|
|
#endif
|
|
|
|
|
2017-10-06 00:06:43 +03:00
|
|
|
typedef typename substring_type::literalstring_type literalstring_type;
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
typedef typename substring_type::fallible_t fallible_t;
|
|
|
|
|
|
|
|
typedef typename substring_type::char_type char_type;
|
|
|
|
typedef typename substring_type::char_traits char_traits;
|
|
|
|
typedef typename substring_type::incompatible_char_type incompatible_char_type;
|
|
|
|
|
|
|
|
typedef typename substring_type::substring_tuple_type substring_tuple_type;
|
|
|
|
|
|
|
|
typedef typename substring_type::const_iterator const_iterator;
|
|
|
|
typedef typename substring_type::iterator iterator;
|
|
|
|
|
|
|
|
typedef typename substring_type::comparator_type comparator_type;
|
|
|
|
|
|
|
|
typedef typename substring_type::char_iterator char_iterator;
|
|
|
|
typedef typename substring_type::const_char_iterator const_char_iterator;
|
|
|
|
|
|
|
|
typedef typename substring_type::index_type index_type;
|
|
|
|
typedef typename substring_type::size_type size_type;
|
|
|
|
|
|
|
|
// These are only for internal use within the string classes:
|
|
|
|
typedef typename substring_type::DataFlags DataFlags;
|
|
|
|
typedef typename substring_type::ClassFlags ClassFlags;
|
|
|
|
|
|
|
|
using typename substring_type::IsChar;
|
|
|
|
using typename substring_type::IsChar16;
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
public:
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
/**
|
|
|
|
* constructors
|
|
|
|
*/
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
nsTString()
|
2017-07-21 01:46:58 +03:00
|
|
|
: substring_type(ClassFlags::NULL_TERMINATED)
|
2014-05-27 11:15:35 +04:00
|
|
|
{
|
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
explicit
|
2017-08-15 00:22:50 +03:00
|
|
|
nsTString(const char_type* aData, size_type aLength = size_type(-1))
|
2017-07-21 01:46:58 +03:00
|
|
|
: substring_type(ClassFlags::NULL_TERMINATED)
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aData, aLength);
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
#if defined(MOZ_USE_CHAR16_WRAPPER)
|
|
|
|
template <typename EnableIfChar16 = IsChar16>
|
2014-05-05 21:30:46 +04:00
|
|
|
explicit
|
2017-08-15 00:22:50 +03:00
|
|
|
nsTString(char16ptr_t aStr, size_type aLength = size_type(-1))
|
2017-07-21 01:46:58 +03:00
|
|
|
: substring_type(ClassFlags::NULL_TERMINATED)
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(static_cast<const char16_t*>(aStr), aLength);
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
2013-11-27 17:40:54 +04:00
|
|
|
#endif
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
nsTString(const self_type& aStr)
|
2017-07-21 01:46:58 +03:00
|
|
|
: substring_type(ClassFlags::NULL_TERMINATED)
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aStr);
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
|
|
|
|
2017-10-02 17:58:15 +03:00
|
|
|
nsTString(self_type&& aStr)
|
|
|
|
: substring_type(ClassFlags::NULL_TERMINATED)
|
|
|
|
{
|
|
|
|
this->Assign(mozilla::Move(aStr));
|
|
|
|
}
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
MOZ_IMPLICIT nsTString(const substring_tuple_type& aTuple)
|
2017-07-21 01:46:58 +03:00
|
|
|
: substring_type(ClassFlags::NULL_TERMINATED)
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aTuple);
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
explicit
|
2017-08-15 00:22:50 +03:00
|
|
|
nsTString(const substring_type& aReadable)
|
2017-07-21 01:46:58 +03:00
|
|
|
: substring_type(ClassFlags::NULL_TERMINATED)
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aReadable);
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
|
|
|
|
2017-10-02 17:58:15 +03:00
|
|
|
explicit
|
|
|
|
nsTString(substring_type&& aReadable)
|
|
|
|
: substring_type(ClassFlags::NULL_TERMINATED)
|
|
|
|
{
|
|
|
|
this->Assign(mozilla::Move(aReadable));
|
|
|
|
}
|
|
|
|
|
2017-10-06 00:06:43 +03:00
|
|
|
// NOTE(nika): gcc 4.9 workaround. Remove when support is dropped.
|
|
|
|
explicit
|
|
|
|
nsTString(const literalstring_type& aReadable)
|
|
|
|
: substring_type(ClassFlags::NULL_TERMINATED)
|
|
|
|
{
|
|
|
|
this->Assign(aReadable);
|
|
|
|
}
|
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
|
|
|
|
// |operator=| does not inherit, so we must define our own
|
2014-05-27 11:15:35 +04:00
|
|
|
self_type& operator=(char_type aChar)
|
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aChar);
|
2014-05-27 11:15:35 +04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
self_type& operator=(const char_type* aData)
|
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aData);
|
2014-05-27 11:15:35 +04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
self_type& operator=(const self_type& aStr)
|
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aStr);
|
2014-05-27 11:15:35 +04:00
|
|
|
return *this;
|
|
|
|
}
|
2017-10-02 17:58:15 +03:00
|
|
|
self_type& operator=(self_type&& aStr)
|
|
|
|
{
|
|
|
|
this->Assign(mozilla::Move(aStr));
|
|
|
|
return *this;
|
|
|
|
}
|
2017-08-15 00:22:50 +03:00
|
|
|
#if defined(MOZ_USE_CHAR16_WRAPPER)
|
|
|
|
template <typename EnableIfChar16 = IsChar16>
|
2014-05-27 11:15:35 +04:00
|
|
|
self_type& operator=(const char16ptr_t aStr)
|
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(static_cast<const char16_t*>(aStr));
|
2014-05-27 11:15:35 +04:00
|
|
|
return *this;
|
|
|
|
}
|
2013-11-27 17:40:54 +04:00
|
|
|
#endif
|
2014-05-27 11:15:35 +04:00
|
|
|
self_type& operator=(const substring_type& aStr)
|
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aStr);
|
2014-05-27 11:15:35 +04:00
|
|
|
return *this;
|
|
|
|
}
|
2017-10-02 17:58:15 +03:00
|
|
|
self_type& operator=(substring_type&& aStr)
|
|
|
|
{
|
|
|
|
this->Assign(mozilla::Move(aStr));
|
|
|
|
return *this;
|
|
|
|
}
|
2017-10-06 00:06:43 +03:00
|
|
|
// NOTE(nika): gcc 4.9 workaround. Remove when support is dropped.
|
|
|
|
self_type& operator=(const literalstring_type& aStr)
|
|
|
|
{
|
|
|
|
this->Assign(aStr);
|
|
|
|
return *this;
|
|
|
|
}
|
2014-05-27 11:15:35 +04:00
|
|
|
self_type& operator=(const substring_tuple_type& aTuple)
|
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aTuple);
|
2014-05-27 11:15:35 +04:00
|
|
|
return *this;
|
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
/**
|
|
|
|
* returns the null-terminated string
|
|
|
|
*/
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2017-09-22 18:26:26 +03:00
|
|
|
template <typename U, typename Dummy> struct raw_type { typedef const U* type; };
|
2017-08-15 00:22:50 +03:00
|
|
|
#if defined(MOZ_USE_CHAR16_WRAPPER)
|
2017-09-22 18:26:26 +03:00
|
|
|
template <typename Dummy> struct raw_type<char16_t, Dummy> { typedef char16ptr_t type; };
|
2013-11-27 17:40:54 +04:00
|
|
|
#endif
|
2017-08-15 00:22:50 +03:00
|
|
|
|
2017-09-22 18:26:26 +03:00
|
|
|
MOZ_NO_DANGLING_ON_TEMPORARIES typename raw_type<T, int>::type get() const
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
return this->mData;
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
/**
|
|
|
|
* returns character at specified index.
|
|
|
|
*
|
|
|
|
* NOTE: unlike nsTSubstring::CharAt, this function allows you to index
|
|
|
|
* the null terminator character.
|
|
|
|
*/
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
char_type CharAt(index_type aIndex) const
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
NS_ASSERTION(aIndex <= this->mLength, "index exceeds allowable range");
|
|
|
|
return this->mData[aIndex];
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
char_type operator[](index_type aIndex) const
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2014-05-27 11:15:35 +04:00
|
|
|
return CharAt(aIndex);
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
#if MOZ_STRING_WITH_OBSOLETE_API
|
|
|
|
|
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
/**
|
|
|
|
* Search for the given substring within this string.
|
|
|
|
*
|
|
|
|
* @param aString is substring to be sought in this
|
|
|
|
* @param aIgnoreCase selects case sensitivity
|
|
|
|
* @param aOffset tells us where in this string to start searching
|
|
|
|
* @param aCount tells us how far from the offset we are to search. Use
|
|
|
|
* -1 to search the whole string.
|
|
|
|
* @return offset in string, or kNotFound
|
|
|
|
*/
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
int32_t Find(const nsTString<char>& aString, bool aIgnoreCase = false,
|
2014-05-27 11:15:35 +04:00
|
|
|
int32_t aOffset = 0, int32_t aCount = -1) const;
|
|
|
|
int32_t Find(const char* aString, bool aIgnoreCase = false,
|
|
|
|
int32_t aOffset = 0, int32_t aCount = -1) const;
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
template <typename EnableIfChar16 = IsChar16>
|
|
|
|
int32_t Find(const self_type& aString, int32_t aOffset = 0,
|
2014-05-27 11:15:35 +04:00
|
|
|
int32_t aCount = -1) const;
|
2017-08-15 00:22:50 +03:00
|
|
|
template <typename EnableIfChar16 = IsChar16>
|
|
|
|
int32_t Find(const char_type* aString, int32_t aOffset = 0,
|
2014-05-27 11:15:35 +04:00
|
|
|
int32_t aCount = -1) const;
|
2013-11-27 17:40:54 +04:00
|
|
|
#ifdef MOZ_USE_CHAR16_WRAPPER
|
2017-08-15 00:22:50 +03:00
|
|
|
template <typename EnableIfChar16 = IsChar16>
|
2014-05-27 11:15:35 +04:00
|
|
|
int32_t Find(char16ptr_t aString, int32_t aOffset = 0,
|
|
|
|
int32_t aCount = -1) const
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
return Find(static_cast<const char16_t*>(aString), aOffset, aCount);
|
|
|
|
}
|
2013-11-27 17:40:54 +04:00
|
|
|
#endif
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This methods scans the string backwards, looking for the given string
|
|
|
|
*
|
|
|
|
* @param aString is substring to be sought in this
|
|
|
|
* @param aIgnoreCase tells us whether or not to do caseless compare
|
|
|
|
* @param aOffset tells us where in this string to start searching.
|
|
|
|
* Use -1 to search from the end of the string.
|
|
|
|
* @param aCount tells us how many iterations to make starting at the
|
|
|
|
* given offset.
|
|
|
|
* @return offset in string, or kNotFound
|
|
|
|
*/
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
// Case aIgnoreCase option only with char versions
|
|
|
|
int32_t RFind(const nsTString<char>& aString, bool aIgnoreCase = false,
|
2014-05-27 11:15:35 +04:00
|
|
|
int32_t aOffset = -1, int32_t aCount = -1) const;
|
|
|
|
int32_t RFind(const char* aCString, bool aIgnoreCase = false,
|
|
|
|
int32_t aOffset = -1, int32_t aCount = -1) const;
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
template <typename EnableIfChar16 = IsChar16>
|
|
|
|
int32_t RFind(const self_type& aString, int32_t aOffset = -1,
|
2014-05-27 11:15:35 +04:00
|
|
|
int32_t aCount = -1) const;
|
2017-08-15 00:22:50 +03:00
|
|
|
template <typename EnableIfChar16 = IsChar16>
|
|
|
|
int32_t RFind(const char_type* aString, int32_t aOffset = -1,
|
2014-05-27 11:15:35 +04:00
|
|
|
int32_t aCount = -1) const;
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
/**
|
|
|
|
* Search for given char within this string
|
|
|
|
*
|
|
|
|
* @param aChar is the character to search for
|
|
|
|
* @param aOffset tells us where in this string to start searching
|
|
|
|
* @param aCount tells us how far from the offset we are to search.
|
|
|
|
* Use -1 to search the whole string.
|
|
|
|
* @return offset in string, or kNotFound
|
|
|
|
*/
|
|
|
|
|
|
|
|
// int32_t FindChar( char16_t aChar, int32_t aOffset=0, int32_t aCount=-1 ) const;
|
2014-05-27 11:15:35 +04:00
|
|
|
int32_t RFindChar(char16_t aChar, int32_t aOffset = -1,
|
|
|
|
int32_t aCount = -1) const;
|
2014-05-05 21:30:46 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method searches this string for the first character found in
|
|
|
|
* the given string.
|
|
|
|
*
|
|
|
|
* @param aString contains set of chars to be found
|
|
|
|
* @param aOffset tells us where in this string to start searching
|
|
|
|
* (counting from left)
|
|
|
|
* @return offset in string, or kNotFound
|
|
|
|
*/
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
int32_t FindCharInSet(const char_type* aString, int32_t aOffset = 0) const;
|
2014-05-27 11:15:35 +04:00
|
|
|
int32_t FindCharInSet(const self_type& aString, int32_t aOffset = 0) const
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
return FindCharInSet(aString.get(), aOffset);
|
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
template <typename EnableIfChar16 = IsChar16>
|
|
|
|
int32_t FindCharInSet(const char* aSet, int32_t aOffset = 0) const;
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
/**
|
|
|
|
* This method searches this string for the last character found in
|
|
|
|
* the given string.
|
|
|
|
*
|
|
|
|
* @param aString contains set of chars to be found
|
|
|
|
* @param aOffset tells us where in this string to start searching
|
|
|
|
* (counting from left)
|
|
|
|
* @return offset in string, or kNotFound
|
|
|
|
*/
|
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
int32_t RFindCharInSet(const char_type* aString, int32_t aOffset = -1) const;
|
|
|
|
int32_t RFindCharInSet(const self_type& aString, int32_t aOffset = -1) const
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
return RFindCharInSet(aString.get(), aOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compares a given string to this string.
|
|
|
|
*
|
|
|
|
* @param aString is the string to be compared
|
|
|
|
* @param aIgnoreCase tells us how to treat case
|
|
|
|
* @param aCount tells us how many chars to compare
|
|
|
|
* @return -1,0,1
|
|
|
|
*/
|
2017-08-15 00:22:50 +03:00
|
|
|
template <typename EnableIfChar = IsChar>
|
|
|
|
int32_t Compare(const char_type* aString, bool aIgnoreCase = false,
|
2014-05-27 11:15:35 +04:00
|
|
|
int32_t aCount = -1) const;
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
/**
|
|
|
|
* Equality check between given string and this string.
|
|
|
|
*
|
|
|
|
* @param aString is the string to check
|
|
|
|
* @param aIgnoreCase tells us how to treat case
|
|
|
|
* @param aCount tells us how many chars to compare
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2017-08-15 00:22:50 +03:00
|
|
|
template <typename EnableIfChar = IsChar>
|
|
|
|
bool EqualsIgnoreCase(const char_type* aString, int32_t aCount = -1) const
|
2014-05-27 11:15:35 +04:00
|
|
|
{
|
2014-05-05 21:30:46 +04:00
|
|
|
return Compare(aString, true, aCount) == 0;
|
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
template <typename EnableIfChar16 = IsChar16>
|
|
|
|
bool EqualsIgnoreCase(const incompatible_char_type* aString, int32_t aCount = -1) const;
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
/**
|
|
|
|
* Perform string to double-precision float conversion.
|
|
|
|
*
|
|
|
|
* @param aErrorCode will contain error if one occurs
|
|
|
|
* @return double-precision float rep of string value
|
|
|
|
*/
|
2014-05-27 11:15:35 +04:00
|
|
|
double ToDouble(nsresult* aErrorCode) const;
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
/**
|
|
|
|
* Perform string to single-precision float conversion.
|
|
|
|
*
|
|
|
|
* @param aErrorCode will contain error if one occurs
|
|
|
|
* @return single-precision float rep of string value
|
|
|
|
*/
|
2017-08-15 00:22:50 +03:00
|
|
|
float ToFloat(nsresult* aErrorCode) const;
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
/**
|
|
|
|
* Perform string to int conversion.
|
|
|
|
* @param aErrorCode will contain error if one occurs
|
|
|
|
* @param aRadix tells us which radix to assume; kAutoDetect tells us to determine the radix for you.
|
|
|
|
* @return int rep of string value, and possible (out) error code
|
|
|
|
*/
|
2014-05-27 11:15:35 +04:00
|
|
|
int32_t ToInteger(nsresult* aErrorCode, uint32_t aRadix = kRadix10) const;
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
/**
|
|
|
|
* Perform string to 64-bit int conversion.
|
|
|
|
* @param aErrorCode will contain error if one occurs
|
|
|
|
* @param aRadix tells us which radix to assume; kAutoDetect tells us to determine the radix for you.
|
|
|
|
* @return 64-bit int rep of string value, and possible (out) error code
|
|
|
|
*/
|
2014-05-27 11:15:35 +04:00
|
|
|
int64_t ToInteger64(nsresult* aErrorCode, uint32_t aRadix = kRadix10) const;
|
2014-05-05 21:30:46 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* |Left|, |Mid|, and |Right| are annoying signatures that seem better almost
|
|
|
|
* any _other_ way than they are now. Consider these alternatives
|
|
|
|
*
|
|
|
|
* aWritable = aReadable.Left(17); // ...a member function that returns a |Substring|
|
|
|
|
* aWritable = Left(aReadable, 17); // ...a global function that returns a |Substring|
|
|
|
|
* Left(aReadable, 17, aWritable); // ...a global function that does the assignment
|
|
|
|
*
|
|
|
|
* as opposed to the current signature
|
|
|
|
*
|
|
|
|
* aReadable.Left(aWritable, 17); // ...a member function that does the assignment
|
|
|
|
*
|
|
|
|
* or maybe just stamping them out in favor of |Substring|, they are just duplicate functionality
|
|
|
|
*
|
|
|
|
* aWritable = Substring(aReadable, 0, 17);
|
|
|
|
*/
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
size_type Mid(self_type& aResult, index_type aStartPos, size_type aCount) const;
|
2014-05-05 21:30:46 +04:00
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
size_type Left(self_type& aResult, size_type aCount) const
|
2004-02-20 04:53:23 +03:00
|
|
|
{
|
2014-05-05 21:30:46 +04:00
|
|
|
return Mid(aResult, 0, aCount);
|
|
|
|
}
|
2004-02-20 04:53:23 +03:00
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
size_type Right(self_type& aResult, size_type aCount) const
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
aCount = XPCOM_MIN(this->mLength, aCount);
|
|
|
|
return Mid(aResult, this->mLength - aCount, aCount);
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
2004-02-20 04:53:23 +03:00
|
|
|
|
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
/**
|
|
|
|
* Set a char inside this string at given index
|
|
|
|
*
|
|
|
|
* @param aChar is the char you want to write into this string
|
|
|
|
* @param anIndex is the ofs where you want to write the given char
|
|
|
|
* @return TRUE if successful
|
|
|
|
*/
|
2004-02-20 04:53:23 +03:00
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
bool SetCharAt(char16_t aChar, uint32_t aIndex);
|
2010-08-07 04:46:51 +04:00
|
|
|
|
2004-02-20 04:53:23 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
/**
|
|
|
|
* These methods are used to remove all occurrences of the
|
|
|
|
* characters found in aSet from this string.
|
|
|
|
*
|
|
|
|
* @param aSet -- characters to be cut from this
|
|
|
|
*/
|
2017-08-15 00:22:50 +03:00
|
|
|
void StripChars(const char_type* aSet);
|
|
|
|
|
|
|
|
template<typename EnableIfChar16 = IsChar16>
|
|
|
|
bool StripChars(const incompatible_char_type* aSet, const fallible_t&);
|
2004-02-20 04:53:23 +03:00
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
template<typename EnableIfChar16 = IsChar16>
|
|
|
|
void StripChars(const incompatible_char_type* aSet);
|
2004-02-20 04:53:23 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
/**
|
|
|
|
* This method strips whitespace throughout the string.
|
|
|
|
*/
|
|
|
|
void StripWhitespace();
|
2017-03-23 14:52:31 +03:00
|
|
|
bool StripWhitespace(const fallible_t&);
|
2014-05-05 21:30:46 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* swaps occurence of 1 string for another
|
|
|
|
*/
|
2004-02-20 04:53:23 +03:00
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
void ReplaceChar(char_type aOldChar, char_type aNewChar);
|
2017-08-15 00:22:50 +03:00
|
|
|
void ReplaceChar(const char_type* aSet, char_type aNewChar);
|
|
|
|
|
|
|
|
template<typename EnableIfChar16 = IsChar16>
|
|
|
|
void ReplaceChar(const char* aSet, char16_t aNewChar);
|
|
|
|
|
2014-12-13 02:57:09 +03:00
|
|
|
/**
|
|
|
|
* Replace all occurrences of aTarget with aNewValue.
|
|
|
|
* The complexity of this function is O(n+m), n being the length of the string
|
|
|
|
* and m being the length of aNewValue.
|
|
|
|
*/
|
2014-05-27 11:15:35 +04:00
|
|
|
void ReplaceSubstring(const self_type& aTarget, const self_type& aNewValue);
|
|
|
|
void ReplaceSubstring(const char_type* aTarget, const char_type* aNewValue);
|
2016-04-27 07:16:50 +03:00
|
|
|
MOZ_MUST_USE bool ReplaceSubstring(const self_type& aTarget,
|
|
|
|
const self_type& aNewValue,
|
|
|
|
const fallible_t&);
|
|
|
|
MOZ_MUST_USE bool ReplaceSubstring(const char_type* aTarget,
|
|
|
|
const char_type* aNewValue,
|
|
|
|
const fallible_t&);
|
2004-02-20 04:53:23 +03:00
|
|
|
|
|
|
|
|
2004-02-19 05:44:03 +03:00
|
|
|
/**
|
2014-05-05 21:30:46 +04:00
|
|
|
* This method trims characters found in aTrimSet from
|
|
|
|
* either end of the underlying string.
|
2004-02-19 05:44:03 +03:00
|
|
|
*
|
2014-05-05 21:30:46 +04:00
|
|
|
* @param aSet -- contains chars to be trimmed from both ends
|
|
|
|
* @param aEliminateLeading
|
|
|
|
* @param aEliminateTrailing
|
|
|
|
* @param aIgnoreQuotes -- if true, causes surrounding quotes to be ignored
|
|
|
|
* @return this
|
|
|
|
*/
|
2014-05-27 11:15:35 +04:00
|
|
|
void Trim(const char* aSet, bool aEliminateLeading = true,
|
|
|
|
bool aEliminateTrailing = true, bool aIgnoreQuotes = false);
|
2014-05-05 21:30:46 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method strips whitespace from string.
|
|
|
|
* You can control whether whitespace is yanked from start and end of
|
|
|
|
* string as well.
|
2008-09-19 19:07:22 +04:00
|
|
|
*
|
2014-05-05 21:30:46 +04:00
|
|
|
* @param aEliminateLeading controls stripping of leading ws
|
|
|
|
* @param aEliminateTrailing controls stripping of trailing ws
|
2004-02-19 05:44:03 +03:00
|
|
|
*/
|
2014-05-27 11:15:35 +04:00
|
|
|
void CompressWhitespace(bool aEliminateLeading = true,
|
|
|
|
bool aEliminateTrailing = true);
|
2014-05-05 21:30:46 +04:00
|
|
|
|
|
|
|
#endif // !MOZ_STRING_WITH_OBSOLETE_API
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allow this string to be bound to a character buffer
|
|
|
|
* until the string is rebound or mutated; the caller
|
|
|
|
* must ensure that the buffer outlives the string.
|
|
|
|
*/
|
2014-05-27 11:15:35 +04:00
|
|
|
void Rebind(const char_type* aData, size_type aLength);
|
2014-05-05 21:30:46 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* verify restrictions for dependent strings
|
|
|
|
*/
|
2015-02-20 16:02:00 +03:00
|
|
|
void AssertValidDependentString()
|
2004-02-19 05:44:03 +03:00
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
NS_ASSERTION(this->mData, "nsTDependentString must wrap a non-NULL buffer");
|
|
|
|
NS_ASSERTION(this->mLength != size_type(-1), "nsTDependentString has bogus length");
|
|
|
|
NS_ASSERTION(this->mData[substring_type::mLength] == 0,
|
2014-05-27 11:15:35 +04:00
|
|
|
"nsTDependentString must wrap only null-terminated strings. "
|
|
|
|
"You are probably looking for nsTDependentSubstring.");
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
|
|
|
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
protected:
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
// allow subclasses to initialize fields directly
|
2017-08-15 00:22:50 +03:00
|
|
|
nsTString(char_type* aData, size_type aLength, DataFlags aDataFlags,
|
|
|
|
ClassFlags aClassFlags)
|
2017-07-21 01:46:58 +03:00
|
|
|
: substring_type(aData, aLength, aDataFlags,
|
|
|
|
aClassFlags | ClassFlags::NULL_TERMINATED)
|
2014-05-27 11:15:35 +04:00
|
|
|
{
|
|
|
|
}
|
2014-12-13 02:57:09 +03:00
|
|
|
|
2017-09-22 07:35:46 +03:00
|
|
|
friend const nsTString<char>& VoidCString();
|
|
|
|
friend const nsTString<char16_t>& VoidString();
|
2017-08-14 07:46:53 +03:00
|
|
|
|
|
|
|
// Used by Null[C]String.
|
2017-08-15 00:22:50 +03:00
|
|
|
explicit nsTString(DataFlags aDataFlags)
|
2017-08-14 07:46:53 +03:00
|
|
|
: substring_type(char_traits::sEmptyBuffer, 0,
|
|
|
|
aDataFlags | DataFlags::TERMINATED,
|
|
|
|
ClassFlags::NULL_TERMINATED)
|
|
|
|
{}
|
|
|
|
|
2014-12-13 02:57:09 +03:00
|
|
|
struct Segment {
|
|
|
|
uint32_t mBegin, mLength;
|
|
|
|
Segment(uint32_t aBegin, uint32_t aLength)
|
|
|
|
: mBegin(aBegin)
|
|
|
|
, mLength(aLength)
|
|
|
|
{}
|
|
|
|
};
|
2014-05-05 21:30:46 +04:00
|
|
|
};
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
// TODO(erahm): Do something with ToDouble so that we can extern the
|
|
|
|
// nsTString templates.
|
|
|
|
//extern template class nsTString<char>;
|
|
|
|
//extern template class nsTString<char16_t>;
|
2014-05-05 21:30:46 +04:00
|
|
|
|
|
|
|
/**
|
2017-08-15 00:22:50 +03:00
|
|
|
* nsTAutoStringN
|
2014-05-05 21:30:46 +04:00
|
|
|
*
|
2017-08-15 00:22:50 +03:00
|
|
|
* Subclass of nsTString that adds support for stack-based string
|
2014-05-05 21:30:46 +04:00
|
|
|
* allocation. It is normally not a good idea to use this class on the
|
|
|
|
* heap, because it will allocate space which may be wasted if the string
|
|
|
|
* it contains is significantly smaller or any larger than 64 characters.
|
|
|
|
*
|
|
|
|
* NAMES:
|
2017-08-15 00:22:50 +03:00
|
|
|
* nsAutoStringN / nsTAutoString for wide characters
|
|
|
|
* nsAutoCStringN / nsTAutoCString for narrow characters
|
2014-05-05 21:30:46 +04:00
|
|
|
*/
|
2017-08-15 00:22:50 +03:00
|
|
|
template<typename T, size_t N>
|
2017-09-27 13:19:33 +03:00
|
|
|
class MOZ_NON_MEMMOVABLE nsTAutoStringN : public nsTString<T>
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
typedef nsTAutoStringN<T, N> self_type;
|
|
|
|
|
2017-09-27 13:19:33 +03:00
|
|
|
typedef nsTString<T> base_string_type;
|
|
|
|
typedef typename base_string_type::string_type string_type;
|
|
|
|
typedef typename base_string_type::char_type char_type;
|
|
|
|
typedef typename base_string_type::char_traits char_traits;
|
|
|
|
typedef typename base_string_type::substring_type substring_type;
|
|
|
|
typedef typename base_string_type::size_type size_type;
|
|
|
|
typedef typename base_string_type::substring_tuple_type substring_tuple_type;
|
2017-10-06 00:06:43 +03:00
|
|
|
typedef typename base_string_type::literalstring_type literalstring_type;
|
2017-08-15 00:22:50 +03:00
|
|
|
|
2017-09-27 13:19:33 +03:00
|
|
|
// These are only for internal use within the string classes:
|
|
|
|
typedef typename base_string_type::DataFlags DataFlags;
|
|
|
|
typedef typename base_string_type::ClassFlags ClassFlags;
|
2017-08-15 00:22:50 +03:00
|
|
|
|
2017-09-27 13:19:33 +03:00
|
|
|
using typename base_string_type::IsChar;
|
|
|
|
using typename base_string_type::IsChar16;
|
2014-05-05 21:30:46 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* constructors
|
|
|
|
*/
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
nsTAutoStringN()
|
2017-09-27 13:19:33 +03:00
|
|
|
: string_type(mStorage, 0, DataFlags::TERMINATED | DataFlags::INLINE,
|
|
|
|
ClassFlags::INLINE)
|
|
|
|
, mInlineCapacity(N - 1)
|
2014-05-27 11:15:35 +04:00
|
|
|
{
|
2017-09-27 13:19:33 +03:00
|
|
|
// null-terminate
|
|
|
|
mStorage[0] = char_type(0);
|
2014-05-27 11:15:35 +04:00
|
|
|
}
|
2014-05-05 21:30:46 +04:00
|
|
|
|
|
|
|
explicit
|
2017-08-15 00:22:50 +03:00
|
|
|
nsTAutoStringN(char_type aChar)
|
2017-09-27 13:19:33 +03:00
|
|
|
: self_type()
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aChar);
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
explicit
|
2017-08-15 00:22:50 +03:00
|
|
|
nsTAutoStringN(const char_type* aData, size_type aLength = size_type(-1))
|
2017-09-27 13:19:33 +03:00
|
|
|
: self_type()
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aData, aLength);
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
#if defined(MOZ_USE_CHAR16_WRAPPER)
|
|
|
|
template <typename EnableIfChar16 = IsChar16>
|
2014-05-05 21:30:46 +04:00
|
|
|
explicit
|
2017-08-15 00:22:50 +03:00
|
|
|
nsTAutoStringN(char16ptr_t aData, size_type aLength = size_type(-1))
|
2017-09-27 13:19:33 +03:00
|
|
|
: self_type(static_cast<const char16_t*>(aData), aLength)
|
2014-05-27 11:15:35 +04:00
|
|
|
{
|
|
|
|
}
|
2013-11-27 17:40:54 +04:00
|
|
|
#endif
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
nsTAutoStringN(const self_type& aStr)
|
2017-09-27 13:19:33 +03:00
|
|
|
: self_type()
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aStr);
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
|
|
|
|
2017-10-02 17:58:15 +03:00
|
|
|
nsTAutoStringN(self_type&& aStr)
|
|
|
|
: self_type()
|
|
|
|
{
|
|
|
|
this->Assign(mozilla::Move(aStr));
|
|
|
|
}
|
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
explicit
|
2017-08-15 00:22:50 +03:00
|
|
|
nsTAutoStringN(const substring_type& aStr)
|
2017-09-27 13:19:33 +03:00
|
|
|
: self_type()
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aStr);
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
|
|
|
|
2017-10-02 17:58:15 +03:00
|
|
|
explicit
|
|
|
|
nsTAutoStringN(substring_type&& aStr)
|
|
|
|
: self_type()
|
|
|
|
{
|
|
|
|
this->Assign(mozilla::Move(aStr));
|
|
|
|
}
|
|
|
|
|
2017-10-06 00:06:43 +03:00
|
|
|
// NOTE(nika): gcc 4.9 workaround. Remove when support is dropped.
|
|
|
|
explicit
|
|
|
|
nsTAutoStringN(const literalstring_type& aStr)
|
|
|
|
: self_type()
|
|
|
|
{
|
|
|
|
this->Assign(aStr);
|
|
|
|
}
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
MOZ_IMPLICIT nsTAutoStringN(const substring_tuple_type& aTuple)
|
2017-09-27 13:19:33 +03:00
|
|
|
: self_type()
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aTuple);
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// |operator=| does not inherit, so we must define our own
|
2014-05-27 11:15:35 +04:00
|
|
|
self_type& operator=(char_type aChar)
|
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aChar);
|
2014-05-27 11:15:35 +04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
self_type& operator=(const char_type* aData)
|
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aData);
|
2014-05-27 11:15:35 +04:00
|
|
|
return *this;
|
|
|
|
}
|
2017-08-15 00:22:50 +03:00
|
|
|
#if defined(MOZ_USE_CHAR16_WRAPPER)
|
|
|
|
template <typename EnableIfChar16 = IsChar16>
|
2014-05-27 11:15:35 +04:00
|
|
|
self_type& operator=(char16ptr_t aStr)
|
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aStr);
|
2014-05-27 11:15:35 +04:00
|
|
|
return *this;
|
|
|
|
}
|
2013-11-27 17:40:54 +04:00
|
|
|
#endif
|
2014-05-27 11:15:35 +04:00
|
|
|
self_type& operator=(const self_type& aStr)
|
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aStr);
|
2014-05-27 11:15:35 +04:00
|
|
|
return *this;
|
|
|
|
}
|
2017-10-02 17:58:15 +03:00
|
|
|
self_type& operator=(self_type&& aStr)
|
|
|
|
{
|
|
|
|
this->Assign(mozilla::Move(aStr));
|
|
|
|
return *this;
|
|
|
|
}
|
2014-05-27 11:15:35 +04:00
|
|
|
self_type& operator=(const substring_type& aStr)
|
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aStr);
|
2014-05-27 11:15:35 +04:00
|
|
|
return *this;
|
|
|
|
}
|
2017-10-02 17:58:15 +03:00
|
|
|
self_type& operator=(substring_type&& aStr)
|
|
|
|
{
|
|
|
|
this->Assign(mozilla::Move(aStr));
|
|
|
|
return *this;
|
|
|
|
}
|
2017-10-06 00:06:43 +03:00
|
|
|
// NOTE(nika): gcc 4.9 workaround. Remove when support is dropped.
|
|
|
|
self_type& operator=(const literalstring_type& aStr)
|
|
|
|
{
|
|
|
|
this->Assign(aStr);
|
|
|
|
return *this;
|
|
|
|
}
|
2014-05-27 11:15:35 +04:00
|
|
|
self_type& operator=(const substring_tuple_type& aTuple)
|
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Assign(aTuple);
|
2014-05-27 11:15:35 +04:00
|
|
|
return *this;
|
|
|
|
}
|
2009-08-04 08:13:28 +04:00
|
|
|
|
2017-08-09 13:41:38 +03:00
|
|
|
static const size_t kStorageSize = N;
|
2014-05-05 21:30:46 +04:00
|
|
|
|
2017-09-27 13:19:33 +03:00
|
|
|
protected:
|
|
|
|
friend class nsTSubstring<T>;
|
2014-05-05 21:30:46 +04:00
|
|
|
|
2017-09-27 13:19:33 +03:00
|
|
|
size_type mInlineCapacity;
|
|
|
|
|
|
|
|
private:
|
2017-08-09 13:41:38 +03:00
|
|
|
char_type mStorage[N];
|
2014-05-05 21:30:46 +04:00
|
|
|
};
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
// Externs for the most common nsTAutoStringN variations.
|
|
|
|
extern template class nsTAutoStringN<char, 64>;
|
|
|
|
extern template class nsTAutoStringN<char16_t, 64>;
|
2014-05-05 21:30:46 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// nsAutoString stores pointers into itself which are invalidated when an
|
|
|
|
// nsTArray is resized, so nsTArray must not be instantiated with nsAutoString
|
|
|
|
// elements!
|
|
|
|
//
|
|
|
|
template<class E> class nsTArrayElementTraits;
|
2017-08-15 00:22:50 +03:00
|
|
|
template<typename T>
|
|
|
|
class nsTArrayElementTraits<nsTAutoString<T>>
|
2014-05-27 11:15:35 +04:00
|
|
|
{
|
2014-05-05 21:30:46 +04:00
|
|
|
public:
|
|
|
|
template<class A> struct Dont_Instantiate_nsTArray_of;
|
|
|
|
template<class A> struct Instead_Use_nsTArray_of;
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
static Dont_Instantiate_nsTArray_of<nsTAutoString<T>>*
|
|
|
|
Construct(Instead_Use_nsTArray_of<nsTString<T>>* aE)
|
2014-05-27 11:15:35 +04:00
|
|
|
{
|
2014-05-05 21:30:46 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
template<class A>
|
2017-08-15 00:22:50 +03:00
|
|
|
static Dont_Instantiate_nsTArray_of<nsTAutoString<T>>*
|
|
|
|
Construct(Instead_Use_nsTArray_of<nsTString<T>>* aE, const A& aArg)
|
2014-05-27 11:15:35 +04:00
|
|
|
{
|
2014-05-05 21:30:46 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2017-08-15 00:22:50 +03:00
|
|
|
static Dont_Instantiate_nsTArray_of<nsTAutoString<T>>*
|
|
|
|
Destruct(Instead_Use_nsTArray_of<nsTString<T>>* aE)
|
2014-05-27 11:15:35 +04:00
|
|
|
{
|
2014-05-05 21:30:46 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-07-31 23:06:36 +03:00
|
|
|
* getter_Copies support for adopting raw string out params that are
|
|
|
|
* heap-allocated, e.g.:
|
2014-05-05 21:30:46 +04:00
|
|
|
*
|
2017-07-31 23:06:36 +03:00
|
|
|
* char* gStr;
|
|
|
|
* void GetBlah(char** aStr)
|
|
|
|
* {
|
|
|
|
* *aStr = strdup(gStr);
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* // This works, but is clumsy.
|
|
|
|
* void Inelegant()
|
|
|
|
* {
|
|
|
|
* char* buf;
|
|
|
|
* GetBlah(&buf);
|
|
|
|
* nsCString str;
|
|
|
|
* str.Adopt(buf);
|
|
|
|
* // ...
|
|
|
|
* }
|
2014-05-05 21:30:46 +04:00
|
|
|
*
|
2017-07-31 23:06:36 +03:00
|
|
|
* // This is nicer.
|
|
|
|
* void Elegant()
|
2014-05-05 21:30:46 +04:00
|
|
|
* {
|
2017-07-31 23:06:36 +03:00
|
|
|
* nsCString str;
|
|
|
|
* GetBlah(getter_Copies(str));
|
2014-05-05 21:30:46 +04:00
|
|
|
* // ...
|
|
|
|
* }
|
|
|
|
*/
|
2017-08-15 00:22:50 +03:00
|
|
|
template <typename T>
|
|
|
|
class MOZ_STACK_CLASS nsTGetterCopies
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
public:
|
2017-08-15 00:22:50 +03:00
|
|
|
typedef T char_type;
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
explicit nsTGetterCopies(nsTSubstring<T>& aStr)
|
2014-05-27 11:15:35 +04:00
|
|
|
: mString(aStr)
|
|
|
|
, mData(nullptr)
|
|
|
|
{
|
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
~nsTGetterCopies()
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
mString.Adopt(mData); // OK if mData is null
|
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
operator char_type**()
|
|
|
|
{
|
|
|
|
return &mData;
|
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
private:
|
2017-08-15 00:22:50 +03:00
|
|
|
nsTSubstring<T>& mString;
|
2014-05-27 11:15:35 +04:00
|
|
|
char_type* mData;
|
2014-05-05 21:30:46 +04:00
|
|
|
};
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2017-07-31 23:06:36 +03:00
|
|
|
// See the comment above nsTGetterCopies_CharT for how to use this.
|
2017-08-15 00:22:50 +03:00
|
|
|
template <typename T>
|
|
|
|
inline nsTGetterCopies<T>
|
|
|
|
getter_Copies(nsTSubstring<T>& aString)
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2017-08-15 00:22:50 +03:00
|
|
|
return nsTGetterCopies<T>(aString);
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
#endif
|