2014-05-05 17:30:46 +00: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 11:12:37 +00: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 17:23:56 +00:00
|
|
|
// IWYU pragma: private, include "nsString.h"
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
/**
|
|
|
|
* nsTDependentSubstring_CharT
|
|
|
|
*
|
|
|
|
* A string class which wraps an external array of string characters. It
|
|
|
|
* is the client code's responsibility to ensure that the external buffer
|
|
|
|
* remains valid for a long as the string is alive.
|
|
|
|
*
|
|
|
|
* NAMES:
|
|
|
|
* nsDependentSubstring for wide characters
|
|
|
|
* nsDependentCSubstring for narrow characters
|
|
|
|
*/
|
2004-02-19 02:44:03 +00:00
|
|
|
class nsTDependentSubstring_CharT : public nsTSubstring_CharT
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
|
|
|
public:
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
typedef nsTDependentSubstring_CharT self_type;
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
public:
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
void Rebind(const substring_type&, uint32_t aStartPos,
|
|
|
|
uint32_t aLength = size_type(-1));
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
void Rebind(const char_type* aData, size_type aLength);
|
2011-12-09 08:35:41 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
void Rebind(const char_type* aStart, const char_type* aEnd)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
Rebind(aStart, size_type(aEnd - aStart));
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTDependentSubstring_CharT(const substring_type& aStr, uint32_t aStartPos,
|
|
|
|
uint32_t aLength = size_type(-1))
|
2014-05-05 17:30:46 +00:00
|
|
|
: substring_type()
|
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
Rebind(aStr, aStartPos, aLength);
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTDependentSubstring_CharT(const char_type* aData, size_type aLength)
|
|
|
|
: substring_type(const_cast<char_type*>(aData), aLength, F_NONE)
|
|
|
|
{
|
|
|
|
}
|
2011-12-09 08:35:41 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTDependentSubstring_CharT(const char_type* aStart, const char_type* aEnd)
|
|
|
|
: substring_type(const_cast<char_type*>(aStart), uint32_t(aEnd - aStart),
|
|
|
|
F_NONE)
|
|
|
|
{
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2013-11-27 13:40:54 +00:00
|
|
|
#if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER)
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTDependentSubstring_CharT(char16ptr_t aData, size_type aLength)
|
|
|
|
: nsTDependentSubstring_CharT(static_cast<const char16_t*>(aData), aLength)
|
|
|
|
{
|
|
|
|
}
|
2013-11-27 13:40:54 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTDependentSubstring_CharT(char16ptr_t aStart, char16ptr_t aEnd)
|
|
|
|
: nsTDependentSubstring_CharT(static_cast<const char16_t*>(aStart),
|
|
|
|
static_cast<const char16_t*>(aEnd))
|
|
|
|
{
|
|
|
|
}
|
2013-11-27 13:40:54 +00:00
|
|
|
#endif
|
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTDependentSubstring_CharT(const const_iterator& aStart,
|
|
|
|
const const_iterator& aEnd)
|
|
|
|
: substring_type(const_cast<char_type*>(aStart.get()),
|
|
|
|
uint32_t(aEnd.get() - aStart.get()), F_NONE)
|
|
|
|
{
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// Create a nsTDependentSubstring to be bound later
|
|
|
|
nsTDependentSubstring_CharT()
|
2014-05-27 07:15:35 +00:00
|
|
|
: substring_type()
|
|
|
|
{
|
|
|
|
}
|
2004-11-25 07:03:20 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// auto-generated copy-constructor OK (XXX really?? what about base class copy-ctor?)
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
private:
|
|
|
|
// NOT USED
|
2014-05-27 07:15:35 +00:00
|
|
|
void operator=(const self_type&); // we're immutable, you can't assign into a substring
|
2014-05-05 17:30:46 +00:00
|
|
|
};
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
inline const nsTDependentSubstring_CharT
|
|
|
|
Substring(const nsTSubstring_CharT& aStr, uint32_t aStartPos,
|
|
|
|
uint32_t aLength = uint32_t(-1))
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
return nsTDependentSubstring_CharT(aStr, aStartPos, aLength);
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
inline const nsTDependentSubstring_CharT
|
|
|
|
Substring(const nsReadingIterator<CharT>& aStart,
|
|
|
|
const nsReadingIterator<CharT>& aEnd)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
return nsTDependentSubstring_CharT(aStart.get(), aEnd.get());
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
inline const nsTDependentSubstring_CharT
|
|
|
|
Substring(const CharT* aData, uint32_t aLength)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
return nsTDependentSubstring_CharT(aData, aLength);
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2011-12-09 08:35:41 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
inline const nsTDependentSubstring_CharT
|
|
|
|
Substring(const CharT* aStart, const CharT* aEnd)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
return nsTDependentSubstring_CharT(aStart, aEnd);
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
inline const nsTDependentSubstring_CharT
|
|
|
|
StringHead(const nsTSubstring_CharT& aStr, uint32_t aCount)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
return nsTDependentSubstring_CharT(aStr, 0, aCount);
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
inline const nsTDependentSubstring_CharT
|
|
|
|
StringTail(const nsTSubstring_CharT& aStr, uint32_t aCount)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
return nsTDependentSubstring_CharT(aStr, aStr.Length() - aCount, aCount);
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|