Remove the v1 string ABI compatibility hacks. Replace references of nsTAString_CharT with nsTSubstring_CharT which is the new base class. r=dbaron

This commit is contained in:
Benjamin Smedberg 2008-09-19 11:07:22 -04:00
Родитель 36750c5af2
Коммит 1d1f0a090a
33 изменённых файлов: 95 добавлений и 2236 удалений

Просмотреть файл

@ -639,8 +639,6 @@ HAVE_DTRACE= @HAVE_DTRACE@
VISIBILITY_FLAGS = @VISIBILITY_FLAGS@
WRAP_SYSTEM_INCLUDES = @WRAP_SYSTEM_INCLUDES@
MOZ_V1_STRING_ABI = @MOZ_V1_STRING_ABI@
MOZ_EMBEDDING_LEVEL_DEFAULT = @MOZ_EMBEDDING_LEVEL_DEFAULT@
MOZ_EMBEDDING_LEVEL_BASIC = @MOZ_EMBEDDING_LEVEL_BASIC@
MOZ_EMBEDDING_LEVEL_MINIMAL = @MOZ_EMBEDDING_LEVEL_MINIMAL@

Просмотреть файл

@ -4413,7 +4413,6 @@ MOZ_UI_LOCALE=en-US
MOZ_UNIVERSALCHARDET=1
MOZ_URL_CLASSIFIER=
MOZ_USE_NATIVE_UCONV=
MOZ_V1_STRING_ABI=
MOZ_VIEW_SOURCE=1
MOZ_XPFE_COMPONENTS=1
MOZ_XPINSTALL=1
@ -7798,18 +7797,6 @@ fi
dnl NECKO_ configuration options are not global
_NON_GLOBAL_ACDEFINES="$_NON_GLOBAL_ACDEFINES NECKO_"
dnl ========================================================
dnl string api compatibility
dnl ========================================================
MOZ_ARG_DISABLE_BOOL(v1-string-abi,
[ --disable-v1-string-abi Disable binary compatibility layer for strings],
MOZ_V1_STRING_ABI=,
MOZ_V1_STRING_ABI=1)
AC_SUBST(MOZ_V1_STRING_ABI)
if test "$MOZ_V1_STRING_ABI"; then
AC_DEFINE(MOZ_V1_STRING_ABI)
fi
dnl Only build Mork if it's required
AC_SUBST(MOZ_MORK)
if test "$MOZ_MORK"; then
@ -8247,7 +8234,6 @@ HAVE_MBRTOWC
HAVE_SYS_MOUNT_H
HAVE_SYS_VFS_H
HAVE_WCRTOMB
MOZ_V1_STRING_ABI
"
AC_CONFIG_HEADER(

Просмотреть файл

@ -184,42 +184,6 @@ NS_UnescapeURL(const nsCSubstring &str, PRUint32 flags, nsCSubstring &result) {
return str;
}
// nsACString is nsCSubstring when MOZ_V1_STRING_ABI is undefined.
#ifdef MOZ_V1_STRING_ABI
inline const nsACString &
NS_EscapeURL(const nsACString &str, PRUint32 flags, nsACString &result) {
// The iterator version of BeginReading provides us with both the data
// pointer and the length with only one function call.
nsACString::const_iterator iter;
str.BeginReading(iter);
if (NS_EscapeURL(iter.get(), iter.size_forward(), flags, result))
return result;
return str;
}
inline const nsACString &
NS_EscapeURL(const nsCSubstring &str, PRUint32 flags, nsACString &result) {
if (NS_EscapeURL(str.Data(), str.Length(), flags, result))
return result;
return str;
}
inline const nsACString &
NS_UnescapeURL(const nsACString &str, PRUint32 flags, nsACString &result) {
// The iterator version of BeginReading provides us with both the data
// pointer and the length with only one function call.
nsACString::const_iterator iter;
str.BeginReading(iter);
if (NS_UnescapeURL(iter.get(), iter.size_forward(), flags, result))
return result;
return str;
}
inline const nsACString &
NS_UnescapeURL(const nsCSubstring &str, PRUint32 flags, nsACString &result) {
if (NS_UnescapeURL(str.Data(), str.Length(), flags, result))
return result;
return str;
}
#endif // MOZ_V1_STRING_ABI
/**
* CString version of nsEscape. Returns true on success, false
* on out of memory. To reverse this function, use NS_UnescapeURL.

Просмотреть файл

@ -54,7 +54,6 @@ EXPORTS = \
nsDependentString.h \
nsDependentSubstring.h \
nsLiteralString.h \
nsObsoleteAString.h \
nsPrintfCString.h \
nsPromiseFlatString.h \
nsReadableUtils.h \
@ -64,10 +63,8 @@ EXPORTS = \
nsStringIterator.h \
nsSubstring.h \
nsSubstringTuple.h \
nsTAString.h \
nsTDependentString.h \
nsTDependentSubstring.h \
nsTObsoleteAString.h \
nsTPromiseFlatString.h \
nsTString.h \
nsTSubstring.h \

Просмотреть файл

@ -47,12 +47,6 @@
#include "nsStringIterator.h"
#endif
#ifdef MOZ_V1_STRING_ABI
#ifndef nsObsoleteAString_h___
#include "nsObsoleteAString.h"
#endif
#endif
// If some platform(s) can't handle our template that matches literal strings,
// then we'll disable it on those platforms.
#ifndef NS_DISABLE_LITERAL_TEMPLATE
@ -63,15 +57,16 @@
#include <string.h>
#define kNotFound -1
// declare nsAString
#include "string-template-def-unichar.h"
#include "nsTAString.h"
#include "nsTSubstring.h"
#include "string-template-undef.h"
// declare nsACString
#include "string-template-def-char.h"
#include "nsTAString.h"
#include "nsTSubstring.h"
#include "string-template-undef.h"

Просмотреть файл

@ -1,102 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is IBM Corporation.
* Portions created by IBM Corporation are Copyright (C) 2003
* IBM Corporation. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@meer.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsObsoleteAString_h___
#define nsObsoleteAString_h___
/*
STRING INTERNALS
This file defines nsObsoleteAString and nsObsoleteACString. These are
abstract classes (interfaces), containing only virtual functions
corresponding to the FROZEN nsA[C]String classes. They exist to provide
the new non-abstract nsA[C]String classes with a mechanism to maintain
backwards binary compatability.
From a binary point-of-view, the new nsA[C]String classes appear to have a
vtable pointer to the vtable of nsObsoleteA[C]StringThunk.
nsObsoleteA[C]StringThunk is a subclass of nsObsoleteA[C]String that serves
as a simple bridge between the virtual functions that make up the FROZEN
nsA[C]String contract and the new ns[C]Substring, which is now our only
subclass of nsA[C]String.
The methods on the new nsA[C]String are now all non-virtual. This reduces
codesize at the callsite, and reduces the number of memory dereferences and
jumps required to invoke a method on nsA[C]String. The result is improved
performance and reduced codesize. However, to maintain binary
compatibility, each method on nsA[C]String must check the value of its
vtable to determine if it corresponds to the built-in implementation of
nsObsoleteA[C]String (i.e., the address of the canonical vtable). If it
does, then the vtable can be ignored, and the nsA[C]String object (i.e.,
|this|) can be cast to ns[C]Substring directly. In which case, the
nsA[C]String methods can be satisfied by invoking the corresponding methods
directly on ns[C]Substring. If the vtable address does not correspond to
the built-in implementation, then the virtual functions on
nsObsoleteA[C]String must be invoked instead.
So, if a nsA[C]String reference corresponds to an external implementation
(such as the old nsEmbed[C]String that shipped with previous versions of
Mozilla), then methods invoked on that nsA[C]String will still act like
virtual function calls. This ensures binary compatibility while avoiding
virtual function calls in most cases.
Finally, nsObsoleteA[C]String (i.e., the FROZEN nsA[C]String vtable) is
now a DEPRECATED interface. See nsStringAPI.h and nsEmbedString.h for
the new preferred way to access nsA[C]String references in an external
component or Gecko embedding application.
*/
#ifndef nsStringFwd_h___
#include "nsStringFwd.h"
#endif
#ifndef nscore_h___
#include "nscore.h"
#endif
// declare nsObsoleteAString
#include "string-template-def-unichar.h"
#include "nsTObsoleteAString.h"
#include "string-template-undef.h"
// declare nsObsoleteACString
#include "string-template-def-char.h"
#include "nsTObsoleteAString.h"
#include "string-template-undef.h"
#endif // !defined(nsObsoleteAString_h___)

Просмотреть файл

@ -54,10 +54,6 @@
*/
class nsAString;
class nsObsoleteAString;
#ifdef MOZ_V1_STRING_ABI
class nsSubstring;
#endif
class nsSubstringTuple;
class nsString;
class nsAutoString;
@ -74,10 +70,6 @@ class nsXPIDLString;
*/
class nsACString;
class nsObsoleteACString;
#ifdef MOZ_V1_STRING_ABI
class nsCSubstring;
#endif
class nsCSubstringTuple;
class nsCString;
class nsCAutoString;
@ -93,10 +85,8 @@ class nsXPIDLCString;
* typedefs for backwards compatibility
*/
#ifndef MOZ_V1_STRING_ABI
typedef nsAString nsSubstring;
typedef nsACString nsCSubstring;
#endif
typedef nsString nsAFlatString;
typedef nsSubstring nsASingleFragmentString;

Просмотреть файл

@ -68,10 +68,6 @@ class nsReadingIterator
private:
friend class nsAString;
friend class nsACString;
#ifdef MOZ_V1_STRING_ABI
friend class nsSubstring;
friend class nsCSubstring;
#endif
// unfortunately, the API for nsReadingIterator requires that the
// iterator know its start and end positions. this was needed when
@ -206,10 +202,6 @@ class nsWritingIterator
private:
friend class nsAString;
friend class nsACString;
#ifdef MOZ_V1_STRING_ABI
friend class nsSubstring;
friend class nsCSubstring;
#endif
// unfortunately, the API for nsWritingIterator requires that the
// iterator know its start and end positions. this was needed when

Просмотреть файл

@ -36,39 +36,6 @@
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsSubstring_h___
#define nsSubstring_h___
#ifndef nsAString_h___
#include "nsAString.h"
#endif
#define kNotFound -1
// If some platform(s) can't handle our template that matches literal strings,
// then we'll disable it on those platforms.
#ifndef NS_DISABLE_LITERAL_TEMPLATE
# if (defined(_MSC_VER) && (_MSC_VER < 1310)) || (defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x560)) || (defined(__HP_aCC) && (__HP_aCC <= 012100))
# define NS_DISABLE_LITERAL_TEMPLATE
# endif
#endif /* !NS_DISABLE_LITERAL_TEMPLATE */
#include <string.h>
// declare nsSubstring
#include "string-template-def-unichar.h"
#include "nsTSubstring.h"
#include "string-template-undef.h"
// declare nsCSubstring
#include "string-template-def-char.h"
#include "nsTSubstring.h"
#include "string-template-undef.h"
#ifndef nsSubstringTuple_h___
#include "nsSubstringTuple.h"
#endif
#endif // !defined(nsSubstring_h___)

Просмотреть файл

@ -1,638 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is IBM Corporation.
* Portions created by IBM Corporation are Copyright (C) 2003
* IBM Corporation. All Rights Reserved.
*
* Contributor(s):
* Scott Collins <scc@mozilla.org> (original author)
* Darin Fisher <darin@meer.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef MOZILLA_INTERNAL_API
#error Cannot use internal string classes without MOZILLA_INTERNAL_API defined. Use the frozen header nsStringAPI.h instead.
#endif
/**
* The base for string comparators
*/
class NS_COM nsTStringComparator_CharT
{
public:
typedef CharT char_type;
nsTStringComparator_CharT() {}
virtual int operator()( const char_type*, const char_type*, PRUint32 length ) const = 0;
virtual int operator()( char_type, char_type ) const = 0;
};
/**
* The default string comparator (case-sensitive comparision)
*/
class NS_COM nsTDefaultStringComparator_CharT
: public nsTStringComparator_CharT
{
public:
typedef CharT char_type;
nsTDefaultStringComparator_CharT() {}
virtual int operator()( const char_type*, const char_type*, PRUint32 length ) const;
virtual int operator()( char_type, char_type ) const;
};
/**
* nsTAString is the most abstract class in the string hierarchy.
*
* In its original inception, nsTAString was designed to allow the data
* storage for a string to be separated into multiple fragments. This was
* intended to enable lazy string flattening or avoid string flattening
* altogether in some cases. This abstraction, however, meant that every
* single string operation (including simple operations such as IsEmpty() and
* BeginReading()) required virtual function calls. A virtual destructor was
* also required. This not only meant additional overhead for invoking
* string methods but also added to additional codesize at every callsite (to
* load the virtual function address).
*
* Today nsTAString exists mainly for backwards compatibility of the string
* API. It is restricted to representing a contiguous array of characters,
* where the character array is not necessarily null-terminated. Moreover,
* since nsTAString's virtual function table was frozen for Mozilla 1.0,
* nsTAString necessarily maintains ABI compatibility with older versions of
* Gecko. (nsTObsoleteAString provides that frozen ABI. See
* nsObsoleteAString.h for a description of how we solve the ABI
* compatibility requirement while eliminating virtual function calls on
* nsTAString.)
*
* XPIDL still generates C++ header files with references to nsTAStrings, so
* nsTAString will still be heavily used in real code.
*
* If the opportunity to break ABI compatibility with Mozilla 1.0 were to
* ever arise, our first move should be to make nsTAString equate to
* nsTSubstring. This may in fact be an option today for some Gecko-based
* products.
*/
class nsTAString_CharT
{
public:
typedef CharT char_type;
typedef nsCharTraits<char_type> char_traits;
typedef char_traits::incompatible_char_type incompatible_char_type;
typedef nsTAString_CharT self_type;
typedef nsTAString_CharT abstract_string_type;
typedef nsTObsoleteAString_CharT obsolete_string_type;
typedef nsTSubstring_CharT substring_type;
typedef nsTSubstringTuple_CharT substring_tuple_type;
typedef nsReadingIterator<char_type> const_iterator;
typedef nsWritingIterator<char_type> iterator;
typedef nsTStringComparator_CharT comparator_type;
typedef PRUint32 size_type;
typedef PRUint32 index_type;
#ifdef MOZ_V1_STRING_ABI
public:
// this acts like a virtual destructor
NS_COM NS_CONSTRUCTOR_FASTCALL ~nsTAString_CharT();
/**
* BeginReading/EndReading can be used to get immutable access to the
* string's underlying buffer. EndReading returns a pointer to the
* end of the string's buffer. nsReadableUtils.h provides a collection
* of utility functions that work with these iterators.
*/
inline const_iterator& BeginReading( const_iterator& iter ) const
{
size_type len = GetReadableBuffer(&iter.mStart);
iter.mEnd = iter.mStart + len;
iter.mPosition = iter.mStart;
return iter;
}
inline const_iterator& EndReading( const_iterator& iter ) const
{
size_type len = GetReadableBuffer(&iter.mStart);
iter.mEnd = iter.mStart + len;
iter.mPosition = iter.mEnd;
return iter;
}
inline const char_type* BeginReading() const
{
const char_type *b;
GetReadableBuffer(&b);
return b;
}
inline const char_type* EndReading() const
{
const char_type *b;
size_type len = GetReadableBuffer(&b);
return b + len;
}
/**
* BeginWriting/EndWriting can be used to get mutable access to the
* string's underlying buffer. EndWriting returns a pointer to the
* end of the string's buffer.
*
* If these methods are unable to return a mutable buffer, then they
* will return a null iterator.
*/
inline iterator& BeginWriting( iterator& iter )
{
size_type len = GetWritableBuffer(&iter.mStart);
iter.mEnd = iter.mStart + len;
iter.mPosition = iter.mStart;
return iter;
}
inline iterator& EndWriting( iterator& iter )
{
size_type len = GetWritableBuffer(&iter.mStart);
iter.mEnd = iter.mStart + len;
iter.mPosition = iter.mEnd;
return iter;
}
inline char_type* BeginWriting()
{
char_type *b;
GetWritableBuffer(&b);
return b;
}
inline char_type* EndWriting()
{
char_type *b;
size_type len = GetWritableBuffer(&b);
return b ? b + len : nsnull;
}
/**
* Get a const pointer to the string's internal buffer. The caller
* MUST NOT modify the characters at the returned address.
*
* @returns The length of the buffer in characters.
*/
inline size_type GetData( const char_type** data ) const
{
return GetReadableBuffer(data);
}
/**
* Get a pointer to the string's internal buffer, optionally resizing
* the buffer first. If size_type(-1) is passed for newLen, then the
* current length of the string is used. The caller MAY modify the
* characters at the returned address (up to but not exceeding the
* length of the string).
*
* @returns The length of the buffer in characters or 0 if unable to
* satisfy the request due to low-memory conditions.
*/
inline size_type GetMutableData( char_type** data, size_type newLen = size_type(-1) )
{
return GetWritableBuffer(data, newLen);
}
/**
* Length checking functions. IsEmpty is a helper function to avoid
* writing code like: |if (str.Length() == 0)|
*/
NS_COM size_type NS_FASTCALL Length() const;
PRBool IsEmpty() const { return Length() == 0; }
/**
* String equality tests. Pass a string comparator if you want to
* control how the strings are compared. By default, a binary
* "case-sensitive" comparision is performed.
*/
NS_COM PRBool NS_FASTCALL Equals( const self_type& ) const;
NS_COM PRBool NS_FASTCALL Equals( const self_type&, const comparator_type& ) const;
NS_COM PRBool NS_FASTCALL Equals( const char_type* ) const;
NS_COM PRBool NS_FASTCALL Equals( const char_type*, const comparator_type& ) const;
/**
* An efficient comparison with ASCII that can be used even
* for wide strings. Call this version when you know the
* length of 'data'.
*/
NS_COM PRBool NS_FASTCALL EqualsASCII( const char* data, size_type len ) const;
/**
* An efficient comparison with ASCII that can be used even
* for wide strings. Call this version when 'data' is
* null-terminated.
*/
NS_COM PRBool NS_FASTCALL EqualsASCII( const char* data ) const;
// EqualsLiteral must ONLY be applied to an actual literal string.
// Do not attempt to use it with a regular char* pointer, or with a char
// array variable.
// The template trick to acquire the array length at compile time without
// using a macro is due to Corey Kosak, with much thanks.
#ifdef NS_DISABLE_LITERAL_TEMPLATE
inline PRBool EqualsLiteral( const char* str ) const
{
return EqualsASCII(str);
}
#else
template<int N>
inline PRBool EqualsLiteral( const char (&str)[N] ) const
{
return EqualsASCII(str, N-1);
}
template<int N>
inline PRBool EqualsLiteral( char (&str)[N] ) const
{
const char* s = str;
return EqualsASCII(s, N-1);
}
#endif
// The LowerCaseEquals methods compare the lower case version of
// this string to some ASCII/Literal string. The ASCII string is
// *not* lowercased for you. If you compare to an ASCII or literal
// string that contains an uppercase character, it is guaranteed to
// return false. We will throw assertions too.
NS_COM PRBool NS_FASTCALL LowerCaseEqualsASCII( const char* data, size_type len ) const;
NS_COM PRBool NS_FASTCALL LowerCaseEqualsASCII( const char* data ) const;
// LowerCaseEqualsLiteral must ONLY be applied to an actual
// literal string. Do not attempt to use it with a regular char*
// pointer, or with a char array variable. Use
// LowerCaseEqualsASCII for them.
#ifdef NS_DISABLE_LITERAL_TEMPLATE
inline PRBool LowerCaseEqualsLiteral( const char* str ) const
{
return LowerCaseEqualsASCII(str);
}
#else
template<int N>
inline PRBool LowerCaseEqualsLiteral( const char (&str)[N] ) const
{
return LowerCaseEqualsASCII(str, N-1);
}
template<int N>
inline PRBool LowerCaseEqualsLiteral( char (&str)[N] ) const
{
const char* s = str;
return LowerCaseEqualsASCII(s, N-1);
}
#endif
/**
* A string always references a non-null data pointer. In some
* applications (e.g., the DOM) it is necessary for a string class
* to have some way to distinguish an empty string from a null (or
* void) string. These methods enable support for the concept of
* a void string.
*/
NS_COM PRBool NS_FASTCALL IsVoid() const;
NS_COM void NS_FASTCALL SetIsVoid( PRBool );
/**
* This method returns true if the string's underlying buffer is
* null-terminated. This should rarely be needed by applications.
* The PromiseFlatTString method should be used to ensure that a
* string's underlying buffer is null-terminated.
*/
NS_COM PRBool NS_FASTCALL IsTerminated() const;
/**
* These are contant time since nsTAString uses flat storage
*/
NS_COM char_type NS_FASTCALL First() const;
NS_COM char_type NS_FASTCALL Last() const;
/**
* Returns the number of occurrences of the given character.
*/
NS_COM size_type NS_FASTCALL CountChar( char_type ) const;
/**
* Locates the offset of the first occurrence of the character. Pass a
* non-zero offset to control where the search begins.
*/
NS_COM PRInt32 NS_FASTCALL FindChar( char_type, index_type offset = 0 ) const;
/**
* SetCapacity is not required to do anything; however, it can be used
* as a hint to the implementation to reduce allocations.
*
* SetCapacity(0) is a suggestion to discard all associated storage.
*
* The |newCapacity| value does not include room for the null
* terminator. The actual allocation size will be one unit larger
* than the given value to make room for a null terminator.
*/
NS_COM void NS_FASTCALL SetCapacity( size_type newCapacity );
/**
* SetLength is used to resize the string's internal buffer. It has
* the effect of moving the string's null-terminator to the offset
* specified by |newLen|, and if the string's internal buffer was
* previously readonly or dependent on some other string, then it will
* be copied. If there is insufficient memory to perform the resize,
* then the string will not be modified. If the length of the string
* is reduced sufficiently, then the string's internal buffer may be
* resized to something smaller.
*/
NS_COM void NS_FASTCALL SetLength( size_type newLen );
/**
* Can't use |Truncate| to make a string longer!
*/
void Truncate( size_type newLen = 0 )
{
NS_ASSERTION(newLen <= Length(), "Truncate cannot make string longer");
SetLength(newLen);
}
/**
* |Assign| and |operator=| make |this| equivalent to the string or
* buffer given as an argument. If possible, they do this by sharing
* a reference counted buffer (see |nsTSubstring|). If not, they copy
* the buffer into their own buffer.
*/
NS_COM void NS_FASTCALL Assign( const self_type& readable );
NS_COM void NS_FASTCALL Assign( const substring_tuple_type& tuple );
NS_COM void NS_FASTCALL Assign( const char_type* data );
NS_COM void NS_FASTCALL Assign( const char_type* data, size_type length );
NS_COM void NS_FASTCALL Assign( char_type c );
NS_COM void NS_FASTCALL AssignASCII( const char* data, size_type length );
NS_COM void NS_FASTCALL AssignASCII( const char* data );
// AssignLiteral must ONLY be applied to an actual literal string.
// Do not attempt to use it with a regular char* pointer, or with a char
// array variable. Use AssignASCII for those.
#ifdef NS_DISABLE_LITERAL_TEMPLATE
void AssignLiteral( const char* str )
{ AssignASCII(str); }
#else
template<int N>
void AssignLiteral( const char (&str)[N] )
{ AssignASCII(str, N-1); }
template<int N>
void AssignLiteral( char (&str)[N] )
{ AssignASCII(str, N-1); }
#endif
// copy-assignment operator. I must define my own if I don't want the compiler to make me one
self_type& operator=( const self_type& readable ) { Assign(readable); return *this; }
self_type& operator=( const substring_tuple_type& tuple ) { Assign(tuple); return *this; }
self_type& operator=( const char_type* data ) { Assign(data); return *this; }
self_type& operator=( char_type c ) { Assign(c); return *this; }
/**
* |Append|, |operator+=| are used to add characters to the end of this string.
*/
NS_COM void NS_FASTCALL Append( const self_type& readable );
NS_COM void NS_FASTCALL Append( const substring_tuple_type& tuple );
NS_COM void NS_FASTCALL Append( const char_type* data );
NS_COM void NS_FASTCALL Append( const char_type* data, size_type length );
NS_COM void NS_FASTCALL Append( char_type c );
NS_COM void NS_FASTCALL AppendASCII( const char* data, size_type length );
NS_COM void NS_FASTCALL AppendASCII( const char* data );
// AppendLiteral must ONLY be applied to an actual literal string.
// Do not attempt to use it with a regular char* pointer, or with a char
// array variable. Use AppendASCII for those.
#ifdef NS_DISABLE_LITERAL_TEMPLATE
void AppendLiteral( const char* str )
{ AppendASCII(str); }
#else
template<int N>
void AppendLiteral( const char (&str)[N] )
{ AppendASCII(str, N-1); }
template<int N>
void AppendLiteral( char (&str)[N] )
{ AppendASCII(str, N-1); }
#endif
self_type& operator+=( const self_type& readable ) { Append(readable); return *this; }
self_type& operator+=( const substring_tuple_type& tuple ) { Append(tuple); return *this; }
self_type& operator+=( const char_type* data ) { Append(data); return *this; }
self_type& operator+=( char_type c ) { Append(c); return *this; }
/**
* |Insert| is used to add characters into this string at a given position.
* NOTE: It's a shame the |pos| parameter isn't at the front of the arg list.
*/
NS_COM void NS_FASTCALL Insert( const self_type& readable, index_type pos );
NS_COM void NS_FASTCALL Insert( const substring_tuple_type& tuple, index_type pos );
NS_COM void NS_FASTCALL Insert( const char_type* data, index_type pos );
NS_COM void NS_FASTCALL Insert( const char_type* data, index_type pos, size_type length );
NS_COM void NS_FASTCALL Insert( char_type c, index_type pos );
/**
* |Cut| is used to remove a range of characters from this string.
*/
NS_COM void NS_FASTCALL Cut( index_type cutStart, size_type cutLength );
/**
* |Replace| is used overwrite a range of characters from this string.
*/
NS_COM void NS_FASTCALL Replace( index_type cutStart, size_type cutLength, const self_type& readable );
NS_COM void NS_FASTCALL Replace( index_type cutStart, size_type cutLength, const substring_tuple_type& readable );
/**
* this is public to support automatic conversion of tuple to abstract
* string, which is necessary to support our API.
*/
nsTAString_CharT(const substring_tuple_type& tuple)
: mVTable(obsolete_string_type::sCanonicalVTable)
, mData(nsnull)
, mLength(0)
, mFlags(0)
{
NS_ASSERTION(mVTable, "mVTable is null! Is this a static string instance?!");
Assign(tuple);
}
protected:
friend class nsTSubstringTuple_CharT;
// GCC 3.2 erroneously needs these (even though they are subclasses!)
friend class nsTSubstring_CharT;
friend class nsTDependentSubstring_CharT;
friend class nsTPromiseFlatString_CharT;
/**
* the address of our virtual function table. required for backwards
* compatibility with Mozilla 1.0 frozen nsAC?String interface.
*/
const void* mVTable;
/**
* these fields are "here" only when mVTable == sCanonicalVTable.
*
* they exist to support automatic construction of a nsTAString
* from a nsTSubstringTuple.
*/
char_type* mData;
size_type mLength;
PRUint32 mFlags;
/**
* nsTAString must be subclassed before it can be instantiated.
*/
nsTAString_CharT(char_type* data, size_type length, PRUint32 flags)
: mVTable(obsolete_string_type::sCanonicalVTable)
, mData(data)
, mLength(length)
, mFlags(flags)
{
NS_ASSERTION(mVTable, "mVTable is null! Is this a static string instance?!");
}
/**
* optional ctor for use by subclasses.
*
* NOTE: mData and mLength are intentionally left uninitialized.
*/
explicit
nsTAString_CharT(PRUint32 flags)
: mVTable(obsolete_string_type::sCanonicalVTable)
, mFlags(flags)
{
NS_ASSERTION(mVTable, "mVTable is null! Is this a static string instance?!");
}
/**
* get pointer to internal string buffer (may not be null terminated).
* return length of buffer.
*/
NS_COM size_type NS_FASTCALL GetReadableBuffer( const char_type **data ) const;
NS_COM size_type NS_FASTCALL GetWritableBuffer( char_type **data, size_type newLen = size_type(-1) );
/**
* returns true if this tuple is dependent on (i.e., overlapping with)
* the given char sequence.
*/
PRBool NS_FASTCALL IsDependentOn(const char_type *start, const char_type *end) const;
/**
* we can be converted to a const nsTSubstring (dependent on this)
*/
const substring_type NS_FASTCALL ToSubstring() const;
/**
* type cast helpers
*/
const obsolete_string_type* AsObsoleteString() const
{
return reinterpret_cast<const obsolete_string_type*>(this);
}
obsolete_string_type* AsObsoleteString()
{
return reinterpret_cast<obsolete_string_type*>(this);
}
const substring_type* AsSubstring() const
{
return reinterpret_cast<const substring_type*>(this);
}
substring_type* AsSubstring()
{
return reinterpret_cast<substring_type*>(this);
}
private:
// GCC 2.95.3, EGCS-2.91.66, Sun Workshop/Forte, and IBM VisualAge C++
// require a public copy-constructor in order to support automatic
// construction of a nsTAString from a nsTSubstringTuple. I believe
// enabling the default copy-constructor is harmless, but I do not want
// it to be enabled by default because that might tempt people into
// using it (where it would be invalid).
#if !defined(__SUNPRO_CC) && \
!(defined(_AIX) && defined(__IBMCPP__)) && \
(!defined(__GNUC__) || __GNUC__ > 2 || __GNUC_MINOR__ > 95)
// NOT TO BE IMPLEMENTED
nsTAString_CharT( const self_type& );
#endif
// NOT TO BE IMPLEMENTED
void operator= ( incompatible_char_type );
void Assign ( incompatible_char_type );
void operator+= ( incompatible_char_type );
void Append ( incompatible_char_type );
void Insert ( incompatible_char_type, index_type );
#endif
};

Просмотреть файл

@ -128,7 +128,4 @@ class nsTDependentString_CharT : public nsTString_CharT
// NOT USED
nsTDependentString_CharT( const substring_tuple_type& );
#ifdef MOZ_V1_STRING_ABI
nsTDependentString_CharT( const abstract_string_type& );
#endif
};

Просмотреть файл

@ -40,6 +40,14 @@
/**
* 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
*/
class nsTDependentSubstring_CharT : public nsTSubstring_CharT
{
@ -49,21 +57,10 @@ class nsTDependentSubstring_CharT : public nsTSubstring_CharT
public:
#ifdef MOZ_V1_STRING_ABI
NS_COM void Rebind( const abstract_string_type&, PRUint32 startPos, PRUint32 length = size_type(-1) );
#endif
NS_COM void Rebind( const substring_type&, PRUint32 startPos, PRUint32 length = size_type(-1) );
NS_COM void Rebind( const char_type* start, const char_type* end );
#ifdef MOZ_V1_STRING_ABI
nsTDependentSubstring_CharT( const abstract_string_type& str, PRUint32 startPos, PRUint32 length = size_type(-1) )
: substring_type()
{
Rebind(str, startPos, length);
}
#endif
nsTDependentSubstring_CharT( const substring_type& str, PRUint32 startPos, PRUint32 length = size_type(-1) )
: substring_type()
{
@ -87,15 +84,6 @@ class nsTDependentSubstring_CharT : public nsTSubstring_CharT
void operator=( const self_type& ); // we're immutable, you can't assign into a substring
};
#ifdef MOZ_V1_STRING_ABI
inline
const nsTDependentSubstring_CharT
Substring( const nsTAString_CharT& str, PRUint32 startPos, PRUint32 length = PRUint32(-1) )
{
return nsTDependentSubstring_CharT(str, startPos, length);
}
#endif
inline
const nsTDependentSubstring_CharT
Substring( const nsTSubstring_CharT& str, PRUint32 startPos, PRUint32 length = PRUint32(-1) )
@ -117,15 +105,6 @@ Substring( const CharT* start, const CharT* end )
return nsTDependentSubstring_CharT(start, end);
}
#ifdef MOZ_V1_STRING_ABI
inline
const nsTDependentSubstring_CharT
StringHead( const nsTAString_CharT& str, PRUint32 count )
{
return nsTDependentSubstring_CharT(str, 0, count);
}
#endif
inline
const nsTDependentSubstring_CharT
StringHead( const nsTSubstring_CharT& str, PRUint32 count )
@ -133,15 +112,6 @@ StringHead( const nsTSubstring_CharT& str, PRUint32 count )
return nsTDependentSubstring_CharT(str, 0, count);
}
#ifdef MOZ_V1_STRING_ABI
inline
const nsTDependentSubstring_CharT
StringTail( const nsTAString_CharT& str, PRUint32 count )
{
return nsTDependentSubstring_CharT(str, str.Length() - count, count);
}
#endif
inline
const nsTDependentSubstring_CharT
StringTail( const nsTSubstring_CharT& str, PRUint32 count )

Просмотреть файл

@ -1,165 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is IBM Corporation.
* Portions created by IBM Corporation are Copyright (C) 2003
* IBM Corporation. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@meer.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* nsTObsoleteAString_CharT : binary compatible with old nsAC?String vtable
*
* @status FROZEN
*/
class nsTObsoleteAString_CharT
{
public:
/**
* This is holds the address of the vtable for the canonical string
* implementation (i.e., nsTString).
*/
NS_COM static const void *sCanonicalVTable;
/**
* An |nsFragmentRequest| is used to tell |GetReadableFragment| and
* |GetWritableFragment| what to do.
*
* @see GetReadableFragment
*/
enum nsFragmentRequest { kPrevFragment, kFirstFragment, kLastFragment, kNextFragment, kFragmentAt };
/**
* A |nsReadableFragment| provides |const| access to a contiguous hunk of
* string of homogenous units, e.g., bytes (|char|). This doesn't mean it
* represents a flat hunk. It could be a variable length encoding, for
* instance UTF-8. And the fragment itself need not be zero-terminated.
*
* An |nsReadableFragment| is the underlying machinery that lets
* |nsReadingIterator|s work.
*
* @see nsReadingIterator
* @status FROZEN
*/
struct nsReadableFragment
{
const CharT* mStart;
const CharT* mEnd;
const void* mFragmentIdentifier;
nsReadableFragment() : mStart(0), mEnd(0), mFragmentIdentifier(0) {}
};
/**
* A |nsWritableFragment| provides non-|const| access to a contiguous hunk of
* string of homogenous units, e.g., bytes (|char|). This doesn't mean it
* represents a flat hunk. It could be a variable length encoding, for
* instance UTF-8. And the fragment itself need not be zero-terminated.
*
* An |nsWritableFragment| is the underlying machinery that lets
* |nsWritingIterator|s work.
*
* @see nsWritingIterator
* @status FROZEN
*/
struct nsWritableFragment
{
CharT* mStart;
CharT* mEnd;
void* mFragmentIdentifier;
nsWritableFragment() : mStart(0), mEnd(0), mFragmentIdentifier(0) {}
};
protected:
typedef CharT char_type;
typedef void buffer_handle_type;
typedef void shared_buffer_handle_type;
typedef nsReadableFragment const_fragment_type;
typedef nsWritableFragment fragment_type;
typedef nsTAString_CharT abstract_string_type;
typedef PRUint32 size_type;
typedef PRUint32 index_type;
protected:
friend class nsTAString_CharT;
friend class nsTSubstring_CharT;
/** here's the old nsAC?String vtable **/
virtual ~nsTObsoleteAString_CharT() { }
virtual PRUint32 GetImplementationFlags() const = 0;
virtual const buffer_handle_type* GetFlatBufferHandle() const = 0;
virtual const buffer_handle_type* GetBufferHandle() const = 0;
virtual const shared_buffer_handle_type* GetSharedBufferHandle() const = 0;
virtual size_type Length() const = 0;
virtual PRBool IsVoid() const = 0;
virtual void SetIsVoid( PRBool ) = 0;
virtual void SetCapacity( size_type ) = 0;
virtual void SetLength( size_type ) = 0;
virtual void Cut( index_type cutStart, size_type cutLength ) = 0;
virtual void do_AssignFromReadable( const abstract_string_type& ) = 0;
virtual void do_AssignFromElementPtr( const char_type* ) = 0;
virtual void do_AssignFromElementPtrLength( const char_type*, size_type ) = 0;
virtual void do_AssignFromElement( char_type ) = 0;
virtual void do_AppendFromReadable( const abstract_string_type& ) = 0;
virtual void do_AppendFromElementPtr( const char_type* ) = 0;
virtual void do_AppendFromElementPtrLength( const char_type*, size_type ) = 0;
virtual void do_AppendFromElement( char_type ) = 0;
virtual void do_InsertFromReadable( const abstract_string_type&, index_type ) = 0;
virtual void do_InsertFromElementPtr( const char_type*, index_type ) = 0;
virtual void do_InsertFromElementPtrLength( const char_type*, index_type, size_type ) = 0;
virtual void do_InsertFromElement( char_type, index_type ) = 0;
virtual void do_ReplaceFromReadable( index_type, size_type, const abstract_string_type& ) = 0;
virtual const char_type* GetReadableFragment( const_fragment_type&, nsFragmentRequest, PRUint32 = 0 ) const = 0;
virtual char_type* GetWritableFragment( fragment_type&, nsFragmentRequest, PRUint32 = 0 ) = 0;
};
// forward declare implementation
class nsTObsoleteAStringThunk_CharT;

Просмотреть файл

@ -100,9 +100,6 @@ class nsTPromiseFlatString_CharT : public nsTString_CharT
private:
NS_COM void Init( const substring_type& );
#ifdef MOZ_V1_STRING_ABI
NS_COM void Init( const abstract_string_type& );
#endif
// NOT TO BE IMPLEMENTED
void operator=( const self_type& );
@ -119,15 +116,6 @@ class nsTPromiseFlatString_CharT : public nsTString_CharT
Init(str);
}
#ifdef MOZ_V1_STRING_ABI
explicit
nsTPromiseFlatString_CharT( const abstract_string_type& readable )
: string_type()
{
Init(readable);
}
#endif
explicit
nsTPromiseFlatString_CharT( const substring_tuple_type& tuple )
: string_type()
@ -138,15 +126,6 @@ class nsTPromiseFlatString_CharT : public nsTString_CharT
}
};
#ifdef MOZ_V1_STRING_ABI
inline
const nsTPromiseFlatString_CharT
TPromiseFlatString_CharT( const nsTAString_CharT& str )
{
return nsTPromiseFlatString_CharT(str);
}
#endif
// e.g., PromiseFlatCString(Substring(s))
inline
const nsTPromiseFlatString_CharT

Просмотреть файл

@ -44,6 +44,10 @@
* 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.
*/
@ -89,11 +93,7 @@ class nsTString_CharT : public nsTSubstring_CharT
}
explicit
#ifdef MOZ_V1_STRING_ABI
nsTString_CharT( const abstract_string_type& readable )
#else
nsTString_CharT( const substring_type& readable )
#endif
: substring_type()
{
Assign(readable);
@ -106,10 +106,6 @@ class nsTString_CharT : public nsTSubstring_CharT
self_type& operator=( const self_type& str ) { Assign(str); return *this; }
self_type& operator=( const substring_type& str ) { Assign(str); return *this; }
self_type& operator=( const substring_tuple_type& tuple ) { Assign(tuple); return *this; }
#ifdef MOZ_V1_STRING_ABI
self_type& operator=( const abstract_string_type& readable ) { Assign(readable); return *this; }
#endif
/**
* returns the null-terminated string
@ -457,9 +453,6 @@ class nsTFixedString_CharT : public nsTString_CharT
self_type& operator=( const char_type* data ) { Assign(data); return *this; }
self_type& operator=( const substring_type& str ) { Assign(str); return *this; }
self_type& operator=( const substring_tuple_type& tuple ) { Assign(tuple); return *this; }
#ifdef MOZ_V1_STRING_ABI
self_type& operator=( const abstract_string_type& readable ) { Assign(readable); return *this; }
#endif
protected:
@ -474,7 +467,13 @@ class nsTFixedString_CharT : public nsTString_CharT
* nsTAutoString_CharT
*
* Subclass of nsTString_CharT that adds support for stack-based string
* allocation. Do not allocate this class on the heap! ;-)
* 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:
* nsAutoString for wide characters
* nsCAutoString for narrow characters
*/
class NS_STACK_CLASS nsTAutoString_CharT : public nsTFixedString_CharT
{
@ -525,24 +524,12 @@ class NS_STACK_CLASS nsTAutoString_CharT : public nsTFixedString_CharT
Assign(tuple);
}
#ifdef MOZ_V1_STRING_ABI
explicit
nsTAutoString_CharT( const abstract_string_type& readable )
: fixed_string_type(mStorage, kDefaultStorageSize, 0)
{
Assign(readable);
}
#endif
// |operator=| does not inherit, so we must define our own
self_type& operator=( char_type c ) { Assign(c); return *this; }
self_type& operator=( const char_type* data ) { Assign(data); return *this; }
self_type& operator=( const self_type& str ) { Assign(str); return *this; }
self_type& operator=( const substring_type& str ) { Assign(str); return *this; }
self_type& operator=( const substring_tuple_type& tuple ) { Assign(tuple); return *this; }
#ifdef MOZ_V1_STRING_ABI
self_type& operator=( const abstract_string_type& readable ) { Assign(readable); return *this; }
#endif
enum { kDefaultStorageSize = 64 };
@ -557,7 +544,12 @@ class NS_STACK_CLASS nsTAutoString_CharT : public nsTFixedString_CharT
*
* (1) mData can be null
* (2) objects of this type can be automatically cast to |const CharT*|
* (3) getter_Copies method is supported to adopt data
* (3) getter_Copies method is supported to adopt data allocated with
* NS_Alloc, such as "out string" parameters in XPIDL.
*
* NAMES:
* nsXPIDLString for wide characters
* nsXPIDLCString for narrow characters
*/
class nsTXPIDLString_CharT : public nsTString_CharT
{
@ -602,9 +594,6 @@ class nsTXPIDLString_CharT : public nsTString_CharT
self_type& operator=( const self_type& str ) { Assign(str); return *this; }
self_type& operator=( const substring_type& str ) { Assign(str); return *this; }
self_type& operator=( const substring_tuple_type& tuple ) { Assign(tuple); return *this; }
#ifdef MOZ_V1_STRING_ABI
self_type& operator=( const abstract_string_type& readable ) { Assign(readable); return *this; }
#endif
};
@ -685,9 +674,6 @@ class nsTAdoptingString_CharT : public nsTXPIDLString_CharT
// |operator=| does not inherit, so we must define our own
self_type& operator=( const substring_type& str ) { Assign(str); return *this; }
self_type& operator=( const substring_tuple_type& tuple ) { Assign(tuple); return *this; }
#ifdef MOZ_V1_STRING_ABI
self_type& operator=( const abstract_string_type& readable ) { Assign(readable); return *this; }
#endif
// Adopt(), if possible, when assigning to a self_type&. Note
// that this violates the constness of str, str is always

Просмотреть файл

@ -36,44 +36,83 @@
*
* ***** END LICENSE BLOCK ***** */
#ifndef MOZILLA_INTERNAL_API
#error Cannot use internal string classes without MOZILLA_INTERNAL_API defined. Use the frozen header nsStringAPI.h instead.
#endif
/**
* nsTSubstring
*
* The base string type. This type is not instantiated directly. A sub-
* class is instantiated instead. For example, see nsTString.
*
* This type works like nsTAString except that it does not have the ABI
* requirements of that interface. Like nsTAString, nsTSubstring
* represents a single contiguous array of characters that may or may not
* be null-terminated.
*
* Many of the accessors on nsTSubstring are inlined as an optimization.
*
* This class is also known as "nsASingleFragmentC?String".
* The base for string comparators
*/
class nsTSubstring_CharT : public nsTAString_CharT
class NS_COM nsTStringComparator_CharT
{
public:
typedef CharT char_type;
typedef nsTSubstring_CharT self_type;
typedef nsTString_CharT string_type;
nsTStringComparator_CharT() {}
typedef char_type* char_iterator;
typedef const char_type* const_char_iterator;
virtual int operator()( const char_type*, const char_type*, PRUint32 length ) const = 0;
virtual int operator()( char_type, char_type ) const = 0;
};
#ifdef MOZ_V1_STRING_ABI
typedef nsTAString_CharT base_string_type;
#else
typedef nsTSubstring_CharT base_string_type;
#endif
/**
* The default string comparator (case-sensitive comparision)
*/
class NS_COM nsTDefaultStringComparator_CharT
: public nsTStringComparator_CharT
{
public:
typedef CharT char_type;
nsTDefaultStringComparator_CharT() {}
virtual int operator()( const char_type*, const char_type*, PRUint32 length ) const;
virtual int operator()( char_type, char_type ) const;
};
/**
* nsTSubstring is the most abstract class in the string hierarchy. It
* represents a single contiguous array of characters, which may or may not
* be null-terminated. This type is not instantiated directly. A sub-class
* is instantiated instead. For example, see nsTString.
*
* NAMES:
* nsAString for wide characters
* nsACString for narrow characters
*
* Many of the accessors on nsTSubstring are inlined as an optimization.
*/
class nsTSubstring_CharT
{
public:
typedef CharT char_type;
typedef nsCharTraits<char_type> char_traits;
typedef char_traits::incompatible_char_type incompatible_char_type;
typedef nsTSubstring_CharT self_type;
typedef self_type abstract_string_type;
typedef self_type base_string_type;
typedef self_type substring_type;
typedef nsTSubstringTuple_CharT substring_tuple_type;
typedef nsTString_CharT string_type;
typedef nsReadingIterator<char_type> const_iterator;
typedef nsWritingIterator<char_type> iterator;
typedef nsTStringComparator_CharT comparator_type;
typedef char_type* char_iterator;
typedef const char_type* const_char_iterator;
typedef PRUint32 size_type;
typedef PRUint32 index_type;
public:
#ifndef MOZ_V1_STRING_ABI
// this acts like a virtual destructor
NS_COM NS_CONSTRUCTOR_FASTCALL ~nsTSubstring_CharT();
#endif
/**
* reading iterators
@ -226,11 +265,6 @@ class nsTSubstring_CharT : public nsTAString_CharT
NS_COM PRBool NS_FASTCALL Equals( const self_type& ) const;
NS_COM PRBool NS_FASTCALL Equals( const self_type&, const comparator_type& ) const;
#ifdef MOZ_V1_STRING_ABI
NS_COM PRBool NS_FASTCALL Equals( const abstract_string_type& readable ) const;
NS_COM PRBool NS_FASTCALL Equals( const abstract_string_type& readable, const comparator_type& comp ) const;
#endif
NS_COM PRBool NS_FASTCALL Equals( const char_type* data ) const;
NS_COM PRBool NS_FASTCALL Equals( const char_type* data, const comparator_type& comp ) const;
@ -310,9 +344,6 @@ class nsTSubstring_CharT : public nsTAString_CharT
NS_COM void NS_FASTCALL Assign( const char_type* data, size_type length = size_type(-1) );
NS_COM void NS_FASTCALL Assign( const self_type& );
NS_COM void NS_FASTCALL Assign( const substring_tuple_type& );
#ifdef MOZ_V1_STRING_ABI
NS_COM void NS_FASTCALL Assign( const abstract_string_type& );
#endif
NS_COM void NS_FASTCALL AssignASCII( const char* data, size_type length );
NS_COM void NS_FASTCALL AssignASCII( const char* data );
@ -336,9 +367,6 @@ class nsTSubstring_CharT : public nsTAString_CharT
self_type& operator=( const char_type* data ) { Assign(data); return *this; }
self_type& operator=( const self_type& str ) { Assign(str); return *this; }
self_type& operator=( const substring_tuple_type& tuple ) { Assign(tuple); return *this; }
#ifdef MOZ_V1_STRING_ABI
self_type& operator=( const abstract_string_type& readable ) { Assign(readable); return *this; }
#endif
NS_COM void NS_FASTCALL Adopt( char_type* data, size_type length = size_type(-1) );
@ -351,9 +379,6 @@ class nsTSubstring_CharT : public nsTAString_CharT
NS_COM void NS_FASTCALL Replace( index_type cutStart, size_type cutLength, const char_type* data, size_type length = size_type(-1) );
void Replace( index_type cutStart, size_type cutLength, const self_type& str ) { Replace(cutStart, cutLength, str.Data(), str.Length()); }
NS_COM void NS_FASTCALL Replace( index_type cutStart, size_type cutLength, const substring_tuple_type& tuple );
#ifdef MOZ_V1_STRING_ABI
NS_COM void NS_FASTCALL Replace( index_type cutStart, size_type cutLength, const abstract_string_type& readable );
#endif
NS_COM void NS_FASTCALL ReplaceASCII( index_type cutStart, size_type cutLength, const char* data, size_type length = size_type(-1) );
@ -361,9 +386,6 @@ class nsTSubstring_CharT : public nsTAString_CharT
void Append( const char_type* data, size_type length = size_type(-1) ) { Replace(mLength, 0, data, length); }
void Append( const self_type& str ) { Replace(mLength, 0, str); }
void Append( const substring_tuple_type& tuple ) { Replace(mLength, 0, tuple); }
#ifdef MOZ_V1_STRING_ABI
void Append( const abstract_string_type& readable ) { Replace(mLength, 0, readable); }
#endif
void AppendASCII( const char* data, size_type length = size_type(-1) ) { ReplaceASCII(mLength, 0, data, length); }
@ -386,17 +408,11 @@ class nsTSubstring_CharT : public nsTAString_CharT
self_type& operator+=( const char_type* data ) { Append(data); return *this; }
self_type& operator+=( const self_type& str ) { Append(str); return *this; }
self_type& operator+=( const substring_tuple_type& tuple ) { Append(tuple); return *this; }
#ifdef MOZ_V1_STRING_ABI
self_type& operator+=( const abstract_string_type& readable ) { Append(readable); return *this; }
#endif
void Insert( char_type c, index_type pos ) { Replace(pos, 0, c); }
void Insert( const char_type* data, index_type pos, size_type length = size_type(-1) ) { Replace(pos, 0, data, length); }
void Insert( const self_type& str, index_type pos ) { Replace(pos, 0, str); }
void Insert( const substring_tuple_type& tuple, index_type pos ) { Replace(pos, 0, tuple); }
#ifdef MOZ_V1_STRING_ABI
void Insert( const abstract_string_type& readable, index_type pos ) { Replace(pos, 0, readable); }
#endif
void Cut( index_type cutStart, size_type cutLength ) { Replace(cutStart, cutLength, char_traits::sEmptyBuffer, 0); }
@ -496,17 +512,14 @@ class nsTSubstring_CharT : public nsTAString_CharT
protected:
friend class nsTObsoleteAStringThunk_CharT;
friend class nsTAString_CharT;
friend class nsTSubstringTuple_CharT;
// XXX GCC 3.4 needs this :-(
friend class nsTPromiseFlatString_CharT;
#ifndef MOZ_V1_STRING_ABI
char_type* mData;
size_type mLength;
PRUint32 mFlags;
#endif
// default initialization
NS_COM nsTSubstring_CharT();

Просмотреть файл

@ -55,12 +55,7 @@ class nsTSubstringTuple_CharT
typedef nsTSubstringTuple_CharT self_type;
typedef nsTSubstring_CharT substring_type;
#ifdef MOZ_V1_STRING_ABI
typedef nsTAString_CharT base_string_type;
typedef nsTObsoleteAString_CharT obsolete_string_type;
#else
typedef nsTSubstring_CharT base_string_type;
#endif
typedef PRUint32 size_type;
public:

Просмотреть файл

@ -38,22 +38,11 @@
#define CharT char
#define CharT_is_char 1
#define nsTObsoleteAString_CharT nsObsoleteACString
#define nsTObsoleteAStringThunk_CharT nsObsoleteACStringThunk
#ifdef MOZ_V1_STRING_ABI
#define nsTAString_CharT nsACString
#else
#define nsTAString_CharT nsCSubstring_base
#endif
#define nsTAString_IncompatibleCharT nsAString
#define nsTString_CharT nsCString
#define nsTFixedString_CharT nsFixedCString
#define nsTAutoString_CharT nsCAutoString
#ifdef MOZ_V1_STRING_ABI
#define nsTSubstring_CharT nsCSubstring
#else
#define nsTSubstring_CharT nsACString
#endif
#define nsTSubstringTuple_CharT nsCSubstringTuple
#define nsTStringComparator_CharT nsCStringComparator
#define nsTDefaultStringComparator_CharT nsDefaultCStringComparator

Просмотреть файл

@ -38,22 +38,11 @@
#define CharT PRUnichar
#define CharT_is_PRUnichar 1
#define nsTObsoleteAString_CharT nsObsoleteAString
#define nsTObsoleteAStringThunk_CharT nsObsoleteAStringThunk
#ifdef MOZ_V1_STRING_ABI
#define nsTAString_CharT nsAString
#else
#define nsTAString_CharT nsSubstring_base
#endif
#define nsTAString_IncompatibleCharT nsACString
#define nsTString_CharT nsString
#define nsTFixedString_CharT nsFixedString
#define nsTAutoString_CharT nsAutoString
#ifdef MOZ_V1_STRING_ABI
#define nsTSubstring_CharT nsSubstring
#else
#define nsTSubstring_CharT nsAString
#endif
#define nsTSubstringTuple_CharT nsSubstringTuple
#define nsTStringComparator_CharT nsStringComparator
#define nsTDefaultStringComparator_CharT nsDefaultStringComparator

Просмотреть файл

@ -39,9 +39,6 @@
#undef CharT
#undef CharT_is_PRUnichar
#undef CharT_is_char
#undef nsTObsoleteAString_CharT
#undef nsTObsoleteAStringThunk_CharT
#undef nsTAString_CharT
#undef nsTAString_IncompatibleCharT
#undef nsTString_CharT
#undef nsTFixedString_CharT

Просмотреть файл

@ -65,13 +65,6 @@ CPPSRCS = \
nsStringObsolete.cpp \
$(NULL)
ifdef MOZ_V1_STRING_ABI
CPPSRCS += \
nsAString.cpp \
nsObsoleteAStringThunk.cpp \
$(NULL)
endif
# we don't want the shared lib, but we want to force the creation of a
# static lib.
FORCE_STATIC_LIB = 1

Просмотреть файл

@ -1,51 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is IBM Corporation.
* Portions created by IBM Corporation are Copyright (C) 2003
* IBM Corporation. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@meer.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsAString.h"
#include "nsObsoleteAString.h"
#include "nsString.h"
// define nsAString
#include "string-template-def-unichar.h"
#include "nsTAString.cpp"
#include "string-template-undef.h"
// define nsACString
#include "string-template-def-char.h"
#include "nsTAString.cpp"
#include "string-template-undef.h"

Просмотреть файл

@ -1,52 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is IBM Corporation.
* Portions created by IBM Corporation are Copyright (C) 2003
* IBM Corporation. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@meer.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsObsoleteAString.h"
#include "nsString.h"
// define nsObsoleteAStringThunk
#include "string-template-def-unichar.h"
#include "nsTObsoleteAStringThunk.cpp"
#include "string-template-undef.h"
// define nsObsoleteACStringThunk
#include "string-template-def-char.h"
#include "nsTObsoleteAStringThunk.cpp"
#include "string-template-undef.h"

Просмотреть файл

@ -652,17 +652,6 @@ class ConvertToUpperCase
}
};
#ifdef MOZ_V1_STRING_ABI
NS_COM
void
ToUpperCase( nsACString& aCString )
{
nsACString::iterator fromBegin, fromEnd;
ConvertToUpperCase converter;
copy_string(aCString.BeginWriting(fromBegin), aCString.EndWriting(fromEnd), converter);
}
#endif
NS_COM
void
ToUpperCase( nsCSubstring& aCString )
@ -744,17 +733,6 @@ class ConvertToLowerCase
}
};
#ifdef MOZ_V1_STRING_ABI
NS_COM
void
ToLowerCase( nsACString& aCString )
{
nsACString::iterator fromBegin, fromEnd;
ConvertToLowerCase converter;
copy_string(aCString.BeginWriting(fromBegin), aCString.EndWriting(fromEnd), converter);
}
#endif
NS_COM
void
ToLowerCase( nsCSubstring& aCString )

Просмотреть файл

@ -138,9 +138,6 @@ class nsAStringAccessor : public nsAString
nsAStringAccessor(); // NOT IMPLEMENTED
public:
#ifdef MOZ_V1_STRING_ABI
const void *vtable() const { return mVTable; }
#endif
char_type *data() const { return mData; }
size_type length() const { return mLength; }
PRUint32 flags() const { return mFlags; }
@ -160,9 +157,6 @@ class nsACStringAccessor : public nsACString
nsACStringAccessor(); // NOT IMPLEMENTED
public:
#ifdef MOZ_V1_STRING_ABI
const void *vtable() const { return mVTable; }
#endif
char_type *data() const { return mData; }
size_type length() const { return mLength; }
PRUint32 flags() const { return mFlags; }
@ -249,10 +243,6 @@ nsStringBuffer::FromString(const nsAString& str)
const nsAStringAccessor* accessor =
static_cast<const nsAStringAccessor*>(&str);
#ifdef MOZ_V1_STRING_ABI
if (accessor->vtable() != nsObsoleteAString::sCanonicalVTable)
return nsnull;
#endif
if (!(accessor->flags() & nsSubstring::F_SHARED))
return nsnull;
@ -265,10 +255,6 @@ nsStringBuffer::FromString(const nsACString& str)
const nsACStringAccessor* accessor =
static_cast<const nsACStringAccessor*>(&str);
#ifdef MOZ_V1_STRING_ABI
if (accessor->vtable() != nsObsoleteACString::sCanonicalVTable)
return nsnull;
#endif
if (!(accessor->flags() & nsCSubstring::F_SHARED))
return nsnull;
@ -281,13 +267,6 @@ nsStringBuffer::ToString(PRUint32 len, nsAString &str)
PRUnichar* data = static_cast<PRUnichar*>(Data());
nsAStringAccessor* accessor = static_cast<nsAStringAccessor*>(&str);
#ifdef MOZ_V1_STRING_ABI
if (accessor->vtable() != nsObsoleteAString::sCanonicalVTable)
{
str.Assign(data, len);
return;
}
#endif
NS_ASSERTION(data[len] == PRUnichar(0), "data should be null terminated");
// preserve class flags
@ -304,13 +283,6 @@ nsStringBuffer::ToString(PRUint32 len, nsACString &str)
char* data = static_cast<char*>(Data());
nsACStringAccessor* accessor = static_cast<nsACStringAccessor*>(&str);
#ifdef MOZ_V1_STRING_ABI
if (accessor->vtable() != nsObsoleteACString::sCanonicalVTable)
{
str.Assign(data, len);
return;
}
#endif
NS_ASSERTION(data[len] == char(0), "data should be null terminated");
// preserve class flags

Просмотреть файл

@ -38,24 +38,8 @@
#include "nsSubstringTuple.h"
#if 0
// convert fragment to |const string_base_type&|
#define TO_SUBSTRING(_v) \
( (ptrdiff_t(_v) & 0x1) \
? reinterpret_cast<const abstract_string_type*>( \
((unsigned long)_v & ~0x1))->ToSubstring() \
: *reinterpret_cast<const substring_type*>((_v)) )
#endif
// convert fragment to |const substring_type&|
#ifdef MOZ_V1_STRING_ABI
#define TO_SUBSTRING(_v) \
( (_v)->mVTable == obsolete_string_type::sCanonicalVTable \
? *(_v)->AsSubstring() \
: (_v)->ToSubstring() )
#else
#define TO_SUBSTRING(_v) (*(_v))
#endif
// define nsSubstringTuple
#include "string-template-def-unichar.h"

Просмотреть файл

@ -1,524 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is IBM Corporation.
* Portions created by IBM Corporation are Copyright (C) 2003
* IBM Corporation. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@meer.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* Some comments on this implementation...
*
* This class is a bridge between the old string implementation and the new
* string implementation. If mVTable points to the canonical vtable for the
* new string implementation, then we can cast directly to the new string
* classes (helped by the AsSubstring() methods). However, if mVTable is not
* ours, then we need to call through the vtable to satisfy the nsTAString
* methods.
*
* In most cases we will avoid the vtable.
*/
nsTAString_CharT::~nsTAString_CharT()
{
NS_ASSERTION(mVTable, "mVTable is null! Is this a static string instance?!");
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Finalize();
else
AsObsoleteString()->~nsTObsoleteAString_CharT();
}
nsTAString_CharT::size_type
nsTAString_CharT::Length() const
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
return AsSubstring()->Length();
return AsObsoleteString()->Length();
}
PRBool
nsTAString_CharT::Equals( const self_type& readable ) const
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
return AsSubstring()->Equals(readable);
return ToSubstring().Equals(readable);
}
PRBool
nsTAString_CharT::Equals( const self_type& readable, const comparator_type& comparator ) const
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
return AsSubstring()->Equals(readable, comparator);
return ToSubstring().Equals(readable, comparator);
}
PRBool
nsTAString_CharT::Equals( const char_type* data ) const
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
return AsSubstring()->Equals(data);
return ToSubstring().Equals(data);
}
PRBool
nsTAString_CharT::Equals( const char_type* data, const comparator_type& comparator ) const
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
return AsSubstring()->Equals(data, comparator);
return ToSubstring().Equals(data, comparator);
}
PRBool
nsTAString_CharT::EqualsASCII( const char* data, size_type len ) const
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
return AsSubstring()->EqualsASCII(data, len);
return ToSubstring().EqualsASCII(data, len);
}
PRBool
nsTAString_CharT::EqualsASCII( const char* data ) const
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
return AsSubstring()->EqualsASCII(data);
return ToSubstring().EqualsASCII(data);
}
PRBool
nsTAString_CharT::LowerCaseEqualsASCII( const char* data, size_type len ) const
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
return AsSubstring()->LowerCaseEqualsASCII(data, len);
return ToSubstring().LowerCaseEqualsASCII(data, len);
}
PRBool
nsTAString_CharT::LowerCaseEqualsASCII( const char* data ) const
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
return AsSubstring()->LowerCaseEqualsASCII(data);
return ToSubstring().LowerCaseEqualsASCII(data);
}
PRBool
nsTAString_CharT::IsVoid() const
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
return AsSubstring()->IsVoid();
return AsObsoleteString()->IsVoid();
}
void
nsTAString_CharT::SetIsVoid( PRBool val )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->SetIsVoid(val);
else
AsObsoleteString()->SetIsVoid(val);
}
PRBool
nsTAString_CharT::IsTerminated() const
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
return AsSubstring()->IsTerminated();
return AsObsoleteString()->GetFlatBufferHandle() != nsnull;
}
CharT
nsTAString_CharT::First() const
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
return AsSubstring()->First();
return ToSubstring().First();
}
CharT
nsTAString_CharT::Last() const
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
return AsSubstring()->Last();
return ToSubstring().Last();
}
nsTAString_CharT::size_type
nsTAString_CharT::CountChar( char_type c ) const
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
return AsSubstring()->CountChar(c);
return ToSubstring().CountChar(c);
}
PRInt32
nsTAString_CharT::FindChar( char_type c, index_type offset ) const
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
return AsSubstring()->FindChar(c, offset);
return ToSubstring().FindChar(c, offset);
}
void
nsTAString_CharT::SetCapacity( size_type size )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->SetCapacity(size);
else
AsObsoleteString()->SetCapacity(size);
}
void
nsTAString_CharT::SetLength( size_type size )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->SetLength(size);
else
AsObsoleteString()->SetLength(size);
}
void
nsTAString_CharT::Assign( const self_type& readable )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Assign(readable);
else
AsObsoleteString()->do_AssignFromReadable(readable);
}
void
nsTAString_CharT::Assign( const substring_tuple_type& tuple )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Assign(tuple);
else
AsObsoleteString()->do_AssignFromReadable(nsTAutoString_CharT(tuple));
}
void
nsTAString_CharT::Assign( const char_type* data )
{
// null check and SetLength(0) cases needed for backwards compat
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Assign(data);
else if (data)
AsObsoleteString()->do_AssignFromElementPtr(data);
else
AsObsoleteString()->SetLength(0);
}
void
nsTAString_CharT::Assign( const char_type* data, size_type length )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Assign(data, length);
else
AsObsoleteString()->do_AssignFromElementPtrLength(data, length);
}
void
nsTAString_CharT::AssignASCII( const char* data )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->AssignASCII(data);
else
{
#ifdef CharT_is_char
AsObsoleteString()->do_AssignFromElementPtr(data);
#else
nsTAutoString_CharT temp;
temp.AssignASCII(data);
AsObsoleteString()->do_AssignFromReadable(temp);
#endif
}
}
void
nsTAString_CharT::AssignASCII( const char* data, size_type length )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->AssignASCII(data, length);
else
{
#ifdef CharT_is_char
AsObsoleteString()->do_AssignFromElementPtrLength(data, length);
#else
nsTAutoString_CharT temp;
temp.AssignASCII(data, length);
AsObsoleteString()->do_AssignFromReadable(temp);
#endif
}
}
void
nsTAString_CharT::Assign( char_type c )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Assign(c);
else
AsObsoleteString()->do_AssignFromElement(c);
}
void
nsTAString_CharT::Append( const self_type& readable )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Append(readable);
else
AsObsoleteString()->do_AppendFromReadable(readable);
}
void
nsTAString_CharT::Append( const substring_tuple_type& tuple )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Append(tuple);
else
AsObsoleteString()->do_AppendFromReadable(nsTAutoString_CharT(tuple));
}
void
nsTAString_CharT::Append( const char_type* data )
{
// null check case needed for backwards compat
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Append(data);
else if (data)
AsObsoleteString()->do_AppendFromElementPtr(data);
}
void
nsTAString_CharT::Append( const char_type* data, size_type length )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Append(data, length);
else
AsObsoleteString()->do_AppendFromElementPtrLength(data, length);
}
void
nsTAString_CharT::AppendASCII( const char* data )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->AppendASCII(data);
else
{
#ifdef CharT_is_char
AsObsoleteString()->do_AppendFromElementPtr(data);
#else
nsTAutoString_CharT temp;
temp.AssignASCII(data);
AsObsoleteString()->do_AppendFromReadable(temp);
#endif
}
}
void
nsTAString_CharT::AppendASCII( const char* data, size_type length )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->AppendASCII(data, length);
else
{
#ifdef CharT_is_char
AsObsoleteString()->do_AppendFromElementPtrLength(data, length);
#else
nsTAutoString_CharT temp;
temp.AssignASCII(data, length);
AsObsoleteString()->do_AppendFromReadable(temp);
#endif
}
}
void
nsTAString_CharT::Append( char_type c )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Append(c);
else
AsObsoleteString()->do_AppendFromElement(c);
}
void
nsTAString_CharT::Insert( const self_type& readable, index_type pos )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Insert(readable, pos);
else
AsObsoleteString()->do_InsertFromReadable(readable, pos);
}
void
nsTAString_CharT::Insert( const substring_tuple_type& tuple, index_type pos )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Insert(tuple, pos);
else
AsObsoleteString()->do_InsertFromReadable(nsTAutoString_CharT(tuple), pos);
}
void
nsTAString_CharT::Insert( const char_type* data, index_type pos )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Insert(data, pos);
else
AsObsoleteString()->do_InsertFromElementPtr(data, pos);
}
void
nsTAString_CharT::Insert( const char_type* data, index_type pos, size_type length )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Insert(data, pos, length);
else
AsObsoleteString()->do_InsertFromElementPtrLength(data, pos, length);
}
void
nsTAString_CharT::Insert( char_type c, index_type pos )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Insert(c, pos);
else
AsObsoleteString()->do_InsertFromElement(c, pos);
}
void
nsTAString_CharT::Cut( index_type cutStart, size_type cutLength )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Cut(cutStart, cutLength);
else
AsObsoleteString()->Cut(cutStart, cutLength);
}
void
nsTAString_CharT::Replace( index_type cutStart, size_type cutLength, const self_type& readable )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Replace(cutStart, cutLength, readable);
else
AsObsoleteString()->do_ReplaceFromReadable(cutStart, cutLength, readable);
}
void
nsTAString_CharT::Replace( index_type cutStart, size_type cutLength, const substring_tuple_type& tuple )
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
AsSubstring()->Replace(cutStart, cutLength, tuple);
else
AsObsoleteString()->do_ReplaceFromReadable(cutStart, cutLength, nsTAutoString_CharT(tuple));
}
nsTAString_CharT::size_type
nsTAString_CharT::GetReadableBuffer( const char_type **data ) const
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
{
const substring_type* str = AsSubstring();
*data = str->mData;
return str->mLength;
}
obsolete_string_type::const_fragment_type frag;
AsObsoleteString()->GetReadableFragment(frag, obsolete_string_type::kFirstFragment, 0);
*data = frag.mStart;
return (frag.mEnd - frag.mStart);
}
nsTAString_CharT::size_type
nsTAString_CharT::GetWritableBuffer(char_type** data, size_type size)
{
if (mVTable == obsolete_string_type::sCanonicalVTable)
return AsSubstring()->GetMutableData(data, size);
if (size != size_type(-1) && size != AsObsoleteString()->Length())
{
AsObsoleteString()->SetLength(size);
if (AsObsoleteString()->Length() != size) {
*data = nsnull;
return 0;
}
}
size_type len = AsObsoleteString()->Length();
obsolete_string_type::fragment_type frag;
AsObsoleteString()->GetWritableFragment(frag, obsolete_string_type::kFirstFragment, 0);
if (size_type(frag.mEnd - frag.mStart) != len)
{
*data = nsnull;
return 0;
}
*data = frag.mStart;
return len;
}
PRBool
nsTAString_CharT::IsDependentOn(const char_type* start, const char_type *end) const
{
// this is an optimization...
if (mVTable == obsolete_string_type::sCanonicalVTable)
return AsSubstring()->IsDependentOn(start, end);
return ToSubstring().IsDependentOn(start, end);
}
const nsTAString_CharT::substring_type
nsTAString_CharT::ToSubstring() const
{
const char_type* data;
size_type length = GetReadableBuffer(&data);
return substring_type(const_cast<char_type*>(data), length, 0);
}

Просмотреть файл

@ -36,25 +36,6 @@
*
* ***** END LICENSE BLOCK ***** */
#ifdef MOZ_V1_STRING_ABI
void
nsTDependentSubstring_CharT::Rebind( const abstract_string_type& readable, PRUint32 startPos, PRUint32 length )
{
// If we currently own a buffer, release it.
Finalize();
size_type strLength = readable.GetReadableBuffer((const char_type**) &mData);
if (startPos > strLength)
startPos = strLength;
mData += startPos;
mLength = NS_MIN(length, strLength - startPos);
SetDataFlags(F_NONE);
}
#endif
void
nsTDependentSubstring_CharT::Rebind( const substring_type& str, PRUint32 startPos, PRUint32 length )
{

Просмотреть файл

@ -1,235 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is IBM Corporation.
* Portions created by IBM Corporation are Copyright (C) 2003
* IBM Corporation. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@meer.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
class nsTObsoleteAStringThunk_CharT : public nsTObsoleteAString_CharT
{
public:
typedef nsTObsoleteAStringThunk_CharT self_type;
typedef nsTSubstring_CharT substring_type;
public:
nsTObsoleteAStringThunk_CharT() {}
static const void* get_vptr()
{
const void* result;
new (&result) self_type();
return result;
}
/**
* we are a nsTSubstring in disguise!
*/
substring_type* concrete_self() { return reinterpret_cast<substring_type*>(this); }
const substring_type* concrete_self() const { return reinterpret_cast<const substring_type*>(this); }
/**
* all virtual methods need to be redirected to appropriate nsString methods
*/
virtual ~nsTObsoleteAStringThunk_CharT()
{
concrete_self()->Finalize();
}
virtual PRUint32 GetImplementationFlags() const
{
return 0;
}
virtual const buffer_handle_type* GetFlatBufferHandle() const
{
return (const buffer_handle_type*) (concrete_self()->IsTerminated() != PR_FALSE);
}
virtual const buffer_handle_type* GetBufferHandle() const
{
return 0;
}
virtual const shared_buffer_handle_type* GetSharedBufferHandle() const
{
return 0;
}
virtual size_type Length() const
{
return concrete_self()->Length();
}
virtual PRBool IsVoid() const
{
return concrete_self()->IsVoid();
}
virtual void SetIsVoid(PRBool val)
{
concrete_self()->SetIsVoid(val);
}
virtual void SetCapacity(size_type size)
{
concrete_self()->SetCapacity(size);
}
virtual void SetLength(size_type size)
{
concrete_self()->SetLength(size);
}
virtual void Cut(index_type cutStart, size_type cutLength)
{
concrete_self()->Cut(cutStart, cutLength);
}
virtual void do_AssignFromReadable(const abstract_string_type &s)
{
concrete_self()->Assign(s);
}
virtual void do_AssignFromElementPtr(const char_type *data)
{
concrete_self()->Assign(data);
}
virtual void do_AssignFromElementPtrLength(const char_type *data, size_type length)
{
concrete_self()->Assign(data, length);
}
virtual void do_AssignFromElement(char_type c)
{
concrete_self()->Assign(c);
}
virtual void do_AppendFromReadable(const abstract_string_type &s)
{
concrete_self()->Append(s);
}
virtual void do_AppendFromElementPtr(const char_type *data)
{
concrete_self()->Append(data);
}
virtual void do_AppendFromElementPtrLength(const char_type *data, size_type length)
{
concrete_self()->Append(data, length);
}
virtual void do_AppendFromElement(char_type c)
{
concrete_self()->Append(c);
}
virtual void do_InsertFromReadable(const abstract_string_type &s, index_type pos)
{
concrete_self()->Insert(s, pos);
}
virtual void do_InsertFromElementPtr(const char_type *data, index_type pos)
{
concrete_self()->Insert(data, pos);
}
virtual void do_InsertFromElementPtrLength(const char_type *data, index_type pos, size_type length)
{
concrete_self()->Insert(data, pos, length);
}
virtual void do_InsertFromElement(char_type c, index_type pos)
{
concrete_self()->Insert(c, pos);
}
virtual void do_ReplaceFromReadable(index_type cutStart, size_type cutLength, const abstract_string_type &s)
{
concrete_self()->Replace(cutStart, cutLength, s);
}
virtual const char_type *GetReadableFragment(const_fragment_type& frag, nsFragmentRequest which, PRUint32 offset) const
{
const substring_type* s = concrete_self();
switch (which)
{
case kFirstFragment:
case kLastFragment:
case kFragmentAt:
frag.mStart = s->Data();
frag.mEnd = frag.mStart + s->Length();
return frag.mStart + offset;
case kPrevFragment:
case kNextFragment:
default:
return 0;
}
}
virtual char_type *GetWritableFragment(fragment_type& frag, nsFragmentRequest which, PRUint32 offset)
{
substring_type* s = concrete_self();
switch (which)
{
case kFirstFragment:
case kLastFragment:
case kFragmentAt:
char_type* start;
s->BeginWriting(start);
frag.mStart = start;
frag.mEnd = start + s->Length();
return frag.mStart + offset;
case kPrevFragment:
case kNextFragment:
default:
return 0;
}
}
};
/**
* initialize the pointer to the canonical vtable...
*/
const void *nsTObsoleteAString_CharT::sCanonicalVTable = nsTObsoleteAStringThunk_CharT::get_vptr();

Просмотреть файл

@ -39,12 +39,6 @@
void
nsTPromiseFlatString_CharT::Init(const substring_type& str)
{
#ifdef MOZ_V1_STRING_ABI
// we have to manually set this here since we are being called on an
// unitialized object.
mVTable = nsTObsoleteAString_CharT::sCanonicalVTable;
#endif
if (str.IsTerminated())
{
mData = const_cast<char_type*>(str.Data());
@ -56,15 +50,3 @@ nsTPromiseFlatString_CharT::Init(const substring_type& str)
Assign(str);
}
}
// this function is non-inline to minimize codesize
#ifdef MOZ_V1_STRING_ABI
void
nsTPromiseFlatString_CharT::Init(const abstract_string_type& readable)
{
if (readable.mVTable == nsTObsoleteAString_CharT::sCanonicalVTable)
Init(*readable.AsSubstring());
else
Init(readable.ToSubstring());
}
#endif

Просмотреть файл

@ -39,12 +39,12 @@
NS_COM int NS_FASTCALL
Compare( const nsTSubstring_CharT::base_string_type& lhs, const nsTSubstring_CharT::base_string_type& rhs, const nsTStringComparator_CharT& comp )
{
typedef nsTAString_CharT::size_type size_type;
typedef nsTSubstring_CharT::size_type size_type;
if ( &lhs == &rhs )
return 0;
nsTAString_CharT::const_iterator leftIter, rightIter;
nsTSubstring_CharT::const_iterator leftIter, rightIter;
lhs.BeginReading(leftIter);
rhs.BeginReading(rightIter);

Просмотреть файл

@ -38,13 +38,9 @@
nsTSubstring_CharT::nsTSubstring_CharT( char_type *data, size_type length,
PRUint32 flags)
#ifdef MOZ_V1_STRING_ABI
: abstract_string_type(data, length, flags)
#else
: mData(data),
mLength(length),
mFlags(flags)
#endif
{
if (flags & F_OWNED) {
STRING_STAT_INCREMENT(Adopt);
@ -55,42 +51,25 @@ nsTSubstring_CharT::nsTSubstring_CharT( char_type *data, size_type length,
}
nsTSubstring_CharT::nsTSubstring_CharT(const substring_tuple_type& tuple)
#ifdef MOZ_V1_STRING_ABI
: abstract_string_type(nsnull, 0, F_NONE)
#else
: mData(nsnull),
mLength(0),
mFlags(F_NONE)
#endif
{
Assign(tuple);
}
nsTSubstring_CharT::nsTSubstring_CharT()
#ifdef MOZ_V1_STRING_ABI
: abstract_string_type(
const_cast<char_type*>(char_traits::sEmptyBuffer), 0, F_TERMINATED) {}
#else
: mData(const_cast<char_type*>(char_traits::sEmptyBuffer)),
mLength(0),
mFlags(F_TERMINATED) {}
#endif
nsTSubstring_CharT::nsTSubstring_CharT( PRUint32 flags )
#ifdef MOZ_V1_STRING_ABI
: abstract_string_type(flags) {}
#else
: mFlags(flags) {}
#endif
nsTSubstring_CharT::nsTSubstring_CharT( const self_type& str )
#ifdef MOZ_V1_STRING_ABI
: abstract_string_type(str.mData, str.mLength, str.mFlags & (F_TERMINATED | F_VOIDED)) {}
#else
: mData(str.mData),
mLength(str.mLength),
mFlags(str.mFlags & (F_TERMINATED | F_VOIDED)) {}
#endif
/**
* helper function for down-casting a nsTSubstring to a nsTFixedString.
@ -227,12 +206,10 @@ nsTSubstring_CharT::Finalize()
// mData, mLength, and mFlags are purposefully left dangling
}
#ifndef MOZ_V1_STRING_ABI
nsTSubstring_CharT::~nsTSubstring_CharT()
{
Finalize();
}
#endif
PRBool
nsTSubstring_CharT::ReplacePrep( index_type cutStart, size_type cutLen, size_type fragLen )
@ -461,20 +438,6 @@ nsTSubstring_CharT::Assign( const substring_tuple_type& tuple )
tuple.WriteTo(mData, length);
}
// this is non-inline to reduce codesize at the callsite
#ifdef MOZ_V1_STRING_ABI
void
nsTSubstring_CharT::Assign( const abstract_string_type& readable )
{
// promote to string if possible to take advantage of sharing
if (readable.mVTable == nsTObsoleteAString_CharT::sCanonicalVTable)
Assign(*readable.AsSubstring());
else
Assign(readable.ToSubstring());
}
#endif
void
nsTSubstring_CharT::Adopt( char_type* data, size_type length )
{
@ -582,14 +545,6 @@ nsTSubstring_CharT::Replace( index_type cutStart, size_type cutLength, const sub
tuple.WriteTo(mData + cutStart, length);
}
#ifdef MOZ_V1_STRING_ABI
void
nsTSubstring_CharT::Replace( index_type cutStart, size_type cutLength, const abstract_string_type& readable )
{
Replace(cutStart, cutLength, readable.ToSubstring());
}
#endif
void
nsTSubstring_CharT::SetCapacity( size_type capacity )
{
@ -676,26 +631,6 @@ nsTSubstring_CharT::Equals( const self_type& str, const comparator_type& comp )
return mLength == str.mLength && comp(mData, str.mData, mLength) == 0;
}
#ifdef MOZ_V1_STRING_ABI
PRBool
nsTSubstring_CharT::Equals( const abstract_string_type& readable ) const
{
const char_type* data;
size_type length = readable.GetReadableBuffer(&data);
return mLength == length && char_traits::compare(mData, data, mLength) == 0;
}
PRBool
nsTSubstring_CharT::Equals( const abstract_string_type& readable, const comparator_type& comp ) const
{
const char_type* data;
size_type length = readable.GetReadableBuffer(&data);
return mLength == length && comp(mData, data, mLength) == 0;
}
#endif
PRBool
nsTSubstring_CharT::Equals( const char_type* data ) const
{

Просмотреть файл

@ -62,7 +62,4 @@
/* Define to either <new> or <new.h> */
#undef NEW_H
/* Define if binary compatibility with Mozilla 1.x string code is desired */
#undef MOZ_V1_STRING_ABI
#endif /* _XPCOM_CONFIG_H_ */