mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-26 23:23:33 +00:00
Bug 995730 - Change xpcom/string/ to use 2 space indentation
This also removes trailing whitespace in reindented files.
This commit is contained in:
parent
51bcf8d525
commit
bb0fa6ae4c
@ -1,5 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
@ -18,41 +18,41 @@
|
||||
|
||||
#define kNotFound -1
|
||||
|
||||
// declare nsAString
|
||||
// declare nsAString
|
||||
#include "string-template-def-unichar.h"
|
||||
#include "nsTSubstring.h"
|
||||
#include "string-template-undef.h"
|
||||
|
||||
// declare nsACString
|
||||
// declare nsACString
|
||||
#include "string-template-def-char.h"
|
||||
#include "nsTSubstring.h"
|
||||
#include "string-template-undef.h"
|
||||
|
||||
|
||||
/**
|
||||
* ASCII case-insensitive comparator. (for Unicode case-insensitive
|
||||
* comparision, see nsUnicharUtils.h)
|
||||
*/
|
||||
/**
|
||||
* ASCII case-insensitive comparator. (for Unicode case-insensitive
|
||||
* comparision, see nsUnicharUtils.h)
|
||||
*/
|
||||
class nsCaseInsensitiveCStringComparator
|
||||
: public nsCStringComparator
|
||||
{
|
||||
public:
|
||||
nsCaseInsensitiveCStringComparator() {}
|
||||
typedef char char_type;
|
||||
: public nsCStringComparator
|
||||
{
|
||||
public:
|
||||
nsCaseInsensitiveCStringComparator() {}
|
||||
typedef char char_type;
|
||||
|
||||
virtual int operator()( const char_type*, const char_type*, uint32_t, uint32_t ) const;
|
||||
};
|
||||
virtual int operator()( const char_type*, const char_type*, uint32_t, uint32_t ) const;
|
||||
};
|
||||
|
||||
class nsCaseInsensitiveCStringArrayComparator
|
||||
{
|
||||
public:
|
||||
template<class A, class B>
|
||||
bool Equals(const A& a, const B& b) const {
|
||||
return a.Equals(b, nsCaseInsensitiveCStringComparator());
|
||||
}
|
||||
};
|
||||
{
|
||||
public:
|
||||
template<class A, class B>
|
||||
bool Equals(const A& a, const B& b) const {
|
||||
return a.Equals(b, nsCaseInsensitiveCStringComparator());
|
||||
}
|
||||
};
|
||||
|
||||
// included here for backwards compatibility
|
||||
// included here for backwards compatibility
|
||||
#ifndef nsSubstringTuple_h___
|
||||
#include "nsSubstringTuple.h"
|
||||
#endif
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
@ -12,9 +13,9 @@ template <class T>
|
||||
inline
|
||||
T
|
||||
NS_ROUNDUP( const T& a, const T& b )
|
||||
{
|
||||
return ((a + (b - 1)) / b) * b;
|
||||
}
|
||||
{
|
||||
return ((a + (b - 1)) / b) * b;
|
||||
}
|
||||
|
||||
// We use these instead of std::min/max because we can't include the algorithm
|
||||
// header in all of XPCOM because the stl wrappers will error out when included
|
||||
@ -23,18 +24,18 @@ template <class T>
|
||||
inline
|
||||
const T&
|
||||
XPCOM_MIN( const T& a, const T& b )
|
||||
{
|
||||
return b < a ? b : a;
|
||||
}
|
||||
{
|
||||
return b < a ? b : a;
|
||||
}
|
||||
|
||||
// Must return b when a == b in case a is -0
|
||||
template <class T>
|
||||
inline
|
||||
const T&
|
||||
XPCOM_MAX( const T& a, const T& b )
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
@ -42,10 +43,10 @@ template <class T>
|
||||
inline
|
||||
const T&
|
||||
clamped( const T& a, const T& min, const T& max )
|
||||
{
|
||||
NS_ABORT_IF_FALSE(max >= min, "clamped(): max must be greater than or equal to min");
|
||||
return XPCOM_MIN(XPCOM_MAX(a, min), max);
|
||||
}
|
||||
{
|
||||
NS_ABORT_IF_FALSE(max >= min, "clamped(): max must be greater than or equal to min");
|
||||
return XPCOM_MIN(XPCOM_MAX(a, min), max);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -53,24 +54,24 @@ template <class InputIterator, class T>
|
||||
inline
|
||||
uint32_t
|
||||
NS_COUNT( InputIterator& first, const InputIterator& last, const T& value )
|
||||
{
|
||||
uint32_t result = 0;
|
||||
for ( ; first != last; ++first )
|
||||
if ( *first == value )
|
||||
++result;
|
||||
return result;
|
||||
}
|
||||
{
|
||||
uint32_t result = 0;
|
||||
for ( ; first != last; ++first )
|
||||
if ( *first == value )
|
||||
++result;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class InputIterator, class OutputIterator>
|
||||
inline
|
||||
OutputIterator&
|
||||
copy_string( const InputIterator& first, const InputIterator& last, OutputIterator& result )
|
||||
{
|
||||
typedef nsCharSourceTraits<InputIterator> source_traits;
|
||||
typedef nsCharSinkTraits<OutputIterator> sink_traits;
|
||||
{
|
||||
typedef nsCharSourceTraits<InputIterator> source_traits;
|
||||
typedef nsCharSinkTraits<OutputIterator> sink_traits;
|
||||
|
||||
sink_traits::write(result, source_traits::read(first), source_traits::readable_distance(first, last));
|
||||
return result;
|
||||
}
|
||||
sink_traits::write(result, source_traits::read(first), source_traits::readable_distance(first, last));
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif // !defined(nsAlgorithm_h___)
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
@ -61,15 +62,15 @@
|
||||
|
||||
// Extract surrogates from a UCS4 char
|
||||
// Reference: the Unicode standard 4.0, section 3.9
|
||||
// Since (c - 0x10000) >> 10 == (c >> 10) - 0x0080 and
|
||||
// Since (c - 0x10000) >> 10 == (c >> 10) - 0x0080 and
|
||||
// 0xD7C0 == 0xD800 - 0x0080,
|
||||
// ((c - 0x10000) >> 10) + 0xD800 can be simplified to
|
||||
#define H_SURROGATE(c) char16_t(char16_t(uint32_t(c) >> 10) + \
|
||||
char16_t(0xD7C0))
|
||||
char16_t(0xD7C0))
|
||||
// where it's to be noted that 0xD7C0 is not bitwise-OR'd
|
||||
// but added.
|
||||
|
||||
// Since 0x10000 & 0x03FF == 0,
|
||||
// Since 0x10000 & 0x03FF == 0,
|
||||
// (c - 0x10000) & 0x03FF == c & 0x03FF so that
|
||||
// ((c - 0x10000) & 0x03FF) | 0xDC00 is equivalent to
|
||||
#define L_SURROGATE(c) char16_t(char16_t(uint32_t(c) & uint32_t(0x03FF)) | \
|
||||
@ -86,517 +87,517 @@ template <class CharT> struct nsCharTraits {};
|
||||
|
||||
template <>
|
||||
struct nsCharTraits<char16_t>
|
||||
{
|
||||
typedef char16_t char_type;
|
||||
typedef uint16_t unsigned_char_type;
|
||||
typedef char incompatible_char_type;
|
||||
|
||||
static char_type* const sEmptyBuffer;
|
||||
|
||||
static
|
||||
void
|
||||
assign( char_type& lhs, char_type rhs )
|
||||
{
|
||||
typedef char16_t char_type;
|
||||
typedef uint16_t unsigned_char_type;
|
||||
typedef char incompatible_char_type;
|
||||
|
||||
static char_type* const sEmptyBuffer;
|
||||
|
||||
static
|
||||
void
|
||||
assign( char_type& lhs, char_type rhs )
|
||||
{
|
||||
lhs = rhs;
|
||||
}
|
||||
lhs = rhs;
|
||||
}
|
||||
|
||||
|
||||
// integer representation of characters:
|
||||
typedef int int_type;
|
||||
// integer representation of characters:
|
||||
typedef int int_type;
|
||||
|
||||
static
|
||||
char_type
|
||||
to_char_type( int_type c )
|
||||
{
|
||||
return char_type(c);
|
||||
}
|
||||
static
|
||||
char_type
|
||||
to_char_type( int_type c )
|
||||
{
|
||||
return char_type(c);
|
||||
}
|
||||
|
||||
static
|
||||
int_type
|
||||
to_int_type( char_type c )
|
||||
{
|
||||
return int_type( static_cast<unsigned_char_type>(c) );
|
||||
}
|
||||
static
|
||||
int_type
|
||||
to_int_type( char_type c )
|
||||
{
|
||||
return int_type( static_cast<unsigned_char_type>(c) );
|
||||
}
|
||||
|
||||
static
|
||||
bool
|
||||
eq_int_type( int_type lhs, int_type rhs )
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
static
|
||||
bool
|
||||
eq_int_type( int_type lhs, int_type rhs )
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
|
||||
|
||||
// |char_type| comparisons:
|
||||
// |char_type| comparisons:
|
||||
|
||||
static
|
||||
bool
|
||||
eq( char_type lhs, char_type rhs )
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
static
|
||||
bool
|
||||
eq( char_type lhs, char_type rhs )
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
|
||||
static
|
||||
bool
|
||||
lt( char_type lhs, char_type rhs )
|
||||
{
|
||||
return lhs < rhs;
|
||||
}
|
||||
static
|
||||
bool
|
||||
lt( char_type lhs, char_type rhs )
|
||||
{
|
||||
return lhs < rhs;
|
||||
}
|
||||
|
||||
|
||||
// operations on s[n] arrays:
|
||||
// operations on s[n] arrays:
|
||||
|
||||
static
|
||||
char_type*
|
||||
move( char_type* s1, const char_type* s2, size_t n )
|
||||
{
|
||||
return static_cast<char_type*>(memmove(s1, s2, n * sizeof(char_type)));
|
||||
}
|
||||
static
|
||||
char_type*
|
||||
move( char_type* s1, const char_type* s2, size_t n )
|
||||
{
|
||||
return static_cast<char_type*>(memmove(s1, s2, n * sizeof(char_type)));
|
||||
}
|
||||
|
||||
static
|
||||
char_type*
|
||||
copy( char_type* s1, const char_type* s2, size_t n )
|
||||
{
|
||||
return static_cast<char_type*>(memcpy(s1, s2, n * sizeof(char_type)));
|
||||
}
|
||||
static
|
||||
char_type*
|
||||
copy( char_type* s1, const char_type* s2, size_t n )
|
||||
{
|
||||
return static_cast<char_type*>(memcpy(s1, s2, n * sizeof(char_type)));
|
||||
}
|
||||
|
||||
static
|
||||
char_type*
|
||||
copyASCII( char_type* s1, const char* s2, size_t n )
|
||||
{
|
||||
for (char_type* s = s1; n--; ++s, ++s2) {
|
||||
NS_ASSERTION(!(*s2 & ~0x7F), "Unexpected non-ASCII character");
|
||||
*s = *s2;
|
||||
}
|
||||
return s1;
|
||||
}
|
||||
static
|
||||
char_type*
|
||||
copyASCII( char_type* s1, const char* s2, size_t n )
|
||||
{
|
||||
for (char_type* s = s1; n--; ++s, ++s2) {
|
||||
NS_ASSERTION(!(*s2 & ~0x7F), "Unexpected non-ASCII character");
|
||||
*s = *s2;
|
||||
}
|
||||
return s1;
|
||||
}
|
||||
|
||||
static
|
||||
char_type*
|
||||
assign( char_type* s, size_t n, char_type c )
|
||||
{
|
||||
char_type* result = s;
|
||||
while ( n-- )
|
||||
assign(*s++, c);
|
||||
return result;
|
||||
}
|
||||
static
|
||||
char_type*
|
||||
assign( char_type* s, size_t n, char_type c )
|
||||
{
|
||||
char_type* result = s;
|
||||
while ( n-- )
|
||||
assign(*s++, c);
|
||||
return result;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
compare( const char_type* s1, const char_type* s2, size_t n )
|
||||
{
|
||||
for ( ; n--; ++s1, ++s2 )
|
||||
{
|
||||
if ( !eq(*s1, *s2) )
|
||||
return to_int_type(*s1) - to_int_type(*s2);
|
||||
}
|
||||
static
|
||||
int
|
||||
compare( const char_type* s1, const char_type* s2, size_t n )
|
||||
{
|
||||
for ( ; n--; ++s1, ++s2 )
|
||||
{
|
||||
if ( !eq(*s1, *s2) )
|
||||
return to_int_type(*s1) - to_int_type(*s2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
compareASCII( const char_type* s1, const char* s2, size_t n )
|
||||
{
|
||||
for ( ; n--; ++s1, ++s2 )
|
||||
{
|
||||
NS_ASSERTION(!(*s2 & ~0x7F), "Unexpected non-ASCII character");
|
||||
if ( !eq_int_type(to_int_type(*s1), to_int_type(*s2)) )
|
||||
return to_int_type(*s1) - to_int_type(*s2);
|
||||
}
|
||||
static
|
||||
int
|
||||
compareASCII( const char_type* s1, const char* s2, size_t n )
|
||||
{
|
||||
for ( ; n--; ++s1, ++s2 )
|
||||
{
|
||||
NS_ASSERTION(!(*s2 & ~0x7F), "Unexpected non-ASCII character");
|
||||
if ( !eq_int_type(to_int_type(*s1), to_int_type(*s2)) )
|
||||
return to_int_type(*s1) - to_int_type(*s2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// this version assumes that s2 is null-terminated and s1 has length n.
|
||||
// if s1 is shorter than s2 then we return -1; if s1 is longer than s2,
|
||||
// we return 1.
|
||||
static
|
||||
int
|
||||
compareASCIINullTerminated( const char_type* s1, size_t n, const char* s2 )
|
||||
{
|
||||
for ( ; n--; ++s1, ++s2 )
|
||||
{
|
||||
if ( !*s2 )
|
||||
return 1;
|
||||
NS_ASSERTION(!(*s2 & ~0x7F), "Unexpected non-ASCII character");
|
||||
if ( !eq_int_type(to_int_type(*s1), to_int_type(*s2)) )
|
||||
return to_int_type(*s1) - to_int_type(*s2);
|
||||
}
|
||||
// this version assumes that s2 is null-terminated and s1 has length n.
|
||||
// if s1 is shorter than s2 then we return -1; if s1 is longer than s2,
|
||||
// we return 1.
|
||||
static
|
||||
int
|
||||
compareASCIINullTerminated( const char_type* s1, size_t n, const char* s2 )
|
||||
{
|
||||
for ( ; n--; ++s1, ++s2 )
|
||||
{
|
||||
if ( !*s2 )
|
||||
return 1;
|
||||
NS_ASSERTION(!(*s2 & ~0x7F), "Unexpected non-ASCII character");
|
||||
if ( !eq_int_type(to_int_type(*s1), to_int_type(*s2)) )
|
||||
return to_int_type(*s1) - to_int_type(*s2);
|
||||
}
|
||||
|
||||
if ( *s2 )
|
||||
return -1;
|
||||
if ( *s2 )
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert c to its lower-case form, but only if c is in the ASCII
|
||||
* range. Otherwise leave it alone.
|
||||
*/
|
||||
static
|
||||
char_type
|
||||
ASCIIToLower( char_type c )
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
return char_type(c + ('a' - 'A'));
|
||||
|
||||
return c;
|
||||
}
|
||||
/**
|
||||
* Convert c to its lower-case form, but only if c is in the ASCII
|
||||
* range. Otherwise leave it alone.
|
||||
*/
|
||||
static
|
||||
char_type
|
||||
ASCIIToLower( char_type c )
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
return char_type(c + ('a' - 'A'));
|
||||
|
||||
static
|
||||
int
|
||||
compareLowerCaseToASCII( const char_type* s1, const char* s2, size_t n )
|
||||
{
|
||||
for ( ; n--; ++s1, ++s2 )
|
||||
{
|
||||
NS_ASSERTION(!(*s2 & ~0x7F), "Unexpected non-ASCII character");
|
||||
NS_ASSERTION(!(*s2 >= 'A' && *s2 <= 'Z'),
|
||||
"Unexpected uppercase character");
|
||||
char_type lower_s1 = ASCIIToLower(*s1);
|
||||
if ( lower_s1 != to_char_type(*s2) )
|
||||
return to_int_type(lower_s1) - to_int_type(*s2);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
static
|
||||
int
|
||||
compareLowerCaseToASCII( const char_type* s1, const char* s2, size_t n )
|
||||
{
|
||||
for ( ; n--; ++s1, ++s2 )
|
||||
{
|
||||
NS_ASSERTION(!(*s2 & ~0x7F), "Unexpected non-ASCII character");
|
||||
NS_ASSERTION(!(*s2 >= 'A' && *s2 <= 'Z'),
|
||||
"Unexpected uppercase character");
|
||||
char_type lower_s1 = ASCIIToLower(*s1);
|
||||
if ( lower_s1 != to_char_type(*s2) )
|
||||
return to_int_type(lower_s1) - to_int_type(*s2);
|
||||
}
|
||||
|
||||
// this version assumes that s2 is null-terminated and s1 has length n.
|
||||
// if s1 is shorter than s2 then we return -1; if s1 is longer than s2,
|
||||
// we return 1.
|
||||
static
|
||||
int
|
||||
compareLowerCaseToASCIINullTerminated( const char_type* s1, size_t n, const char* s2 )
|
||||
{
|
||||
for ( ; n--; ++s1, ++s2 )
|
||||
{
|
||||
if ( !*s2 )
|
||||
return 1;
|
||||
NS_ASSERTION(!(*s2 & ~0x7F), "Unexpected non-ASCII character");
|
||||
NS_ASSERTION(!(*s2 >= 'A' && *s2 <= 'Z'),
|
||||
"Unexpected uppercase character");
|
||||
char_type lower_s1 = ASCIIToLower(*s1);
|
||||
if ( lower_s1 != to_char_type(*s2) )
|
||||
return to_int_type(lower_s1) - to_int_type(*s2);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( *s2 )
|
||||
return -1;
|
||||
// this version assumes that s2 is null-terminated and s1 has length n.
|
||||
// if s1 is shorter than s2 then we return -1; if s1 is longer than s2,
|
||||
// we return 1.
|
||||
static
|
||||
int
|
||||
compareLowerCaseToASCIINullTerminated( const char_type* s1, size_t n, const char* s2 )
|
||||
{
|
||||
for ( ; n--; ++s1, ++s2 )
|
||||
{
|
||||
if ( !*s2 )
|
||||
return 1;
|
||||
NS_ASSERTION(!(*s2 & ~0x7F), "Unexpected non-ASCII character");
|
||||
NS_ASSERTION(!(*s2 >= 'A' && *s2 <= 'Z'),
|
||||
"Unexpected uppercase character");
|
||||
char_type lower_s1 = ASCIIToLower(*s1);
|
||||
if ( lower_s1 != to_char_type(*s2) )
|
||||
return to_int_type(lower_s1) - to_int_type(*s2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
if ( *s2 )
|
||||
return -1;
|
||||
|
||||
static
|
||||
size_t
|
||||
length( const char_type* s )
|
||||
{
|
||||
size_t result = 0;
|
||||
while ( !eq(*s++, char_type(0)) )
|
||||
++result;
|
||||
return result;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
const char_type*
|
||||
find( const char_type* s, size_t n, char_type c )
|
||||
{
|
||||
while ( n-- )
|
||||
{
|
||||
if ( eq(*s, c) )
|
||||
return s;
|
||||
++s;
|
||||
}
|
||||
static
|
||||
size_t
|
||||
length( const char_type* s )
|
||||
{
|
||||
size_t result = 0;
|
||||
while ( !eq(*s++, char_type(0)) )
|
||||
++result;
|
||||
return result;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
static
|
||||
const char_type*
|
||||
find( const char_type* s, size_t n, char_type c )
|
||||
{
|
||||
while ( n-- )
|
||||
{
|
||||
if ( eq(*s, c) )
|
||||
return s;
|
||||
++s;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct nsCharTraits<char>
|
||||
{
|
||||
typedef char char_type;
|
||||
typedef unsigned char unsigned_char_type;
|
||||
typedef char16_t incompatible_char_type;
|
||||
|
||||
static char_type* const sEmptyBuffer;
|
||||
|
||||
static
|
||||
void
|
||||
assign( char_type& lhs, char_type rhs )
|
||||
{
|
||||
typedef char char_type;
|
||||
typedef unsigned char unsigned_char_type;
|
||||
typedef char16_t incompatible_char_type;
|
||||
|
||||
static char_type* const sEmptyBuffer;
|
||||
|
||||
static
|
||||
void
|
||||
assign( char_type& lhs, char_type rhs )
|
||||
{
|
||||
lhs = rhs;
|
||||
}
|
||||
lhs = rhs;
|
||||
}
|
||||
|
||||
|
||||
// integer representation of characters:
|
||||
// integer representation of characters:
|
||||
|
||||
typedef int int_type;
|
||||
typedef int int_type;
|
||||
|
||||
static
|
||||
char_type
|
||||
to_char_type( int_type c )
|
||||
{
|
||||
return char_type(c);
|
||||
}
|
||||
static
|
||||
char_type
|
||||
to_char_type( int_type c )
|
||||
{
|
||||
return char_type(c);
|
||||
}
|
||||
|
||||
static
|
||||
int_type
|
||||
to_int_type( char_type c )
|
||||
{
|
||||
return int_type( static_cast<unsigned_char_type>(c) );
|
||||
}
|
||||
static
|
||||
int_type
|
||||
to_int_type( char_type c )
|
||||
{
|
||||
return int_type( static_cast<unsigned_char_type>(c) );
|
||||
}
|
||||
|
||||
static
|
||||
bool
|
||||
eq_int_type( int_type lhs, int_type rhs )
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
static
|
||||
bool
|
||||
eq_int_type( int_type lhs, int_type rhs )
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
|
||||
|
||||
// |char_type| comparisons:
|
||||
// |char_type| comparisons:
|
||||
|
||||
static
|
||||
bool
|
||||
eq( char_type lhs, char_type rhs )
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
static
|
||||
bool
|
||||
eq( char_type lhs, char_type rhs )
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
|
||||
static
|
||||
bool
|
||||
lt( char_type lhs, char_type rhs )
|
||||
{
|
||||
return lhs < rhs;
|
||||
}
|
||||
static
|
||||
bool
|
||||
lt( char_type lhs, char_type rhs )
|
||||
{
|
||||
return lhs < rhs;
|
||||
}
|
||||
|
||||
|
||||
// operations on s[n] arrays:
|
||||
// operations on s[n] arrays:
|
||||
|
||||
static
|
||||
char_type*
|
||||
move( char_type* s1, const char_type* s2, size_t n )
|
||||
{
|
||||
return static_cast<char_type*>(memmove(s1, s2, n * sizeof(char_type)));
|
||||
}
|
||||
static
|
||||
char_type*
|
||||
move( char_type* s1, const char_type* s2, size_t n )
|
||||
{
|
||||
return static_cast<char_type*>(memmove(s1, s2, n * sizeof(char_type)));
|
||||
}
|
||||
|
||||
static
|
||||
char_type*
|
||||
copy( char_type* s1, const char_type* s2, size_t n )
|
||||
{
|
||||
return static_cast<char_type*>(memcpy(s1, s2, n * sizeof(char_type)));
|
||||
}
|
||||
static
|
||||
char_type*
|
||||
copy( char_type* s1, const char_type* s2, size_t n )
|
||||
{
|
||||
return static_cast<char_type*>(memcpy(s1, s2, n * sizeof(char_type)));
|
||||
}
|
||||
|
||||
static
|
||||
char_type*
|
||||
copyASCII( char_type* s1, const char* s2, size_t n )
|
||||
{
|
||||
return copy(s1, s2, n);
|
||||
}
|
||||
static
|
||||
char_type*
|
||||
copyASCII( char_type* s1, const char* s2, size_t n )
|
||||
{
|
||||
return copy(s1, s2, n);
|
||||
}
|
||||
|
||||
static
|
||||
char_type*
|
||||
assign( char_type* s, size_t n, char_type c )
|
||||
{
|
||||
return static_cast<char_type*>(memset(s, to_int_type(c), n));
|
||||
}
|
||||
static
|
||||
char_type*
|
||||
assign( char_type* s, size_t n, char_type c )
|
||||
{
|
||||
return static_cast<char_type*>(memset(s, to_int_type(c), n));
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
compare( const char_type* s1, const char_type* s2, size_t n )
|
||||
{
|
||||
return memcmp(s1, s2, n);
|
||||
}
|
||||
static
|
||||
int
|
||||
compare( const char_type* s1, const char_type* s2, size_t n )
|
||||
{
|
||||
return memcmp(s1, s2, n);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
compareASCII( const char_type* s1, const char* s2, size_t n )
|
||||
{
|
||||
static
|
||||
int
|
||||
compareASCII( const char_type* s1, const char* s2, size_t n )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
NS_ASSERTION(!(s2[i] & ~0x7F), "Unexpected non-ASCII character");
|
||||
}
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
NS_ASSERTION(!(s2[i] & ~0x7F), "Unexpected non-ASCII character");
|
||||
}
|
||||
#endif
|
||||
return compare(s1, s2, n);
|
||||
}
|
||||
return compare(s1, s2, n);
|
||||
}
|
||||
|
||||
// this version assumes that s2 is null-terminated and s1 has length n.
|
||||
// if s1 is shorter than s2 then we return -1; if s1 is longer than s2,
|
||||
// we return 1.
|
||||
static
|
||||
int
|
||||
compareASCIINullTerminated( const char_type* s1, size_t n, const char* s2 )
|
||||
{
|
||||
// can't use strcmp here because we don't want to stop when s1
|
||||
// contains a null
|
||||
for ( ; n--; ++s1, ++s2 )
|
||||
{
|
||||
if ( !*s2 )
|
||||
return 1;
|
||||
NS_ASSERTION(!(*s2 & ~0x7F), "Unexpected non-ASCII character");
|
||||
if ( *s1 != *s2 )
|
||||
return to_int_type(*s1) - to_int_type(*s2);
|
||||
}
|
||||
// this version assumes that s2 is null-terminated and s1 has length n.
|
||||
// if s1 is shorter than s2 then we return -1; if s1 is longer than s2,
|
||||
// we return 1.
|
||||
static
|
||||
int
|
||||
compareASCIINullTerminated( const char_type* s1, size_t n, const char* s2 )
|
||||
{
|
||||
// can't use strcmp here because we don't want to stop when s1
|
||||
// contains a null
|
||||
for ( ; n--; ++s1, ++s2 )
|
||||
{
|
||||
if ( !*s2 )
|
||||
return 1;
|
||||
NS_ASSERTION(!(*s2 & ~0x7F), "Unexpected non-ASCII character");
|
||||
if ( *s1 != *s2 )
|
||||
return to_int_type(*s1) - to_int_type(*s2);
|
||||
}
|
||||
|
||||
if ( *s2 )
|
||||
return -1;
|
||||
if ( *s2 )
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert c to its lower-case form, but only if c is ASCII.
|
||||
*/
|
||||
static
|
||||
char_type
|
||||
ASCIIToLower( char_type c )
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
return char_type(c + ('a' - 'A'));
|
||||
/**
|
||||
* Convert c to its lower-case form, but only if c is ASCII.
|
||||
*/
|
||||
static
|
||||
char_type
|
||||
ASCIIToLower( char_type c )
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
return char_type(c + ('a' - 'A'));
|
||||
|
||||
return c;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
compareLowerCaseToASCII( const char_type* s1, const char* s2, size_t n )
|
||||
{
|
||||
for ( ; n--; ++s1, ++s2 )
|
||||
{
|
||||
NS_ASSERTION(!(*s2 & ~0x7F), "Unexpected non-ASCII character");
|
||||
NS_ASSERTION(!(*s2 >= 'A' && *s2 <= 'Z'),
|
||||
"Unexpected uppercase character");
|
||||
char_type lower_s1 = ASCIIToLower(*s1);
|
||||
if ( lower_s1 != *s2 )
|
||||
return to_int_type(lower_s1) - to_int_type(*s2);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static
|
||||
int
|
||||
compareLowerCaseToASCII( const char_type* s1, const char* s2, size_t n )
|
||||
{
|
||||
for ( ; n--; ++s1, ++s2 )
|
||||
{
|
||||
NS_ASSERTION(!(*s2 & ~0x7F), "Unexpected non-ASCII character");
|
||||
NS_ASSERTION(!(*s2 >= 'A' && *s2 <= 'Z'),
|
||||
"Unexpected uppercase character");
|
||||
char_type lower_s1 = ASCIIToLower(*s1);
|
||||
if ( lower_s1 != *s2 )
|
||||
return to_int_type(lower_s1) - to_int_type(*s2);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// this version assumes that s2 is null-terminated and s1 has length n.
|
||||
// if s1 is shorter than s2 then we return -1; if s1 is longer than s2,
|
||||
// we return 1.
|
||||
static
|
||||
int
|
||||
compareLowerCaseToASCIINullTerminated( const char_type* s1, size_t n, const char* s2 )
|
||||
{
|
||||
for ( ; n--; ++s1, ++s2 )
|
||||
{
|
||||
if ( !*s2 )
|
||||
return 1;
|
||||
NS_ASSERTION(!(*s2 & ~0x7F), "Unexpected non-ASCII character");
|
||||
NS_ASSERTION(!(*s2 >= 'A' && *s2 <= 'Z'),
|
||||
"Unexpected uppercase character");
|
||||
char_type lower_s1 = ASCIIToLower(*s1);
|
||||
if ( lower_s1 != *s2 )
|
||||
return to_int_type(lower_s1) - to_int_type(*s2);
|
||||
}
|
||||
// this version assumes that s2 is null-terminated and s1 has length n.
|
||||
// if s1 is shorter than s2 then we return -1; if s1 is longer than s2,
|
||||
// we return 1.
|
||||
static
|
||||
int
|
||||
compareLowerCaseToASCIINullTerminated( const char_type* s1, size_t n, const char* s2 )
|
||||
{
|
||||
for ( ; n--; ++s1, ++s2 )
|
||||
{
|
||||
if ( !*s2 )
|
||||
return 1;
|
||||
NS_ASSERTION(!(*s2 & ~0x7F), "Unexpected non-ASCII character");
|
||||
NS_ASSERTION(!(*s2 >= 'A' && *s2 <= 'Z'),
|
||||
"Unexpected uppercase character");
|
||||
char_type lower_s1 = ASCIIToLower(*s1);
|
||||
if ( lower_s1 != *s2 )
|
||||
return to_int_type(lower_s1) - to_int_type(*s2);
|
||||
}
|
||||
|
||||
if ( *s2 )
|
||||
return -1;
|
||||
if ( *s2 )
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
size_t
|
||||
length( const char_type* s )
|
||||
{
|
||||
return strlen(s);
|
||||
}
|
||||
static
|
||||
size_t
|
||||
length( const char_type* s )
|
||||
{
|
||||
return strlen(s);
|
||||
}
|
||||
|
||||
static
|
||||
const char_type*
|
||||
find( const char_type* s, size_t n, char_type c )
|
||||
{
|
||||
return reinterpret_cast<const char_type*>(memchr(s, to_int_type(c), n));
|
||||
}
|
||||
};
|
||||
static
|
||||
const char_type*
|
||||
find( const char_type* s, size_t n, char_type c )
|
||||
{
|
||||
return reinterpret_cast<const char_type*>(memchr(s, to_int_type(c), n));
|
||||
}
|
||||
};
|
||||
|
||||
template <class InputIterator>
|
||||
struct nsCharSourceTraits
|
||||
{
|
||||
typedef typename InputIterator::difference_type difference_type;
|
||||
|
||||
static
|
||||
uint32_t
|
||||
readable_distance( const InputIterator& first, const InputIterator& last )
|
||||
{
|
||||
typedef typename InputIterator::difference_type difference_type;
|
||||
// assumes single fragment
|
||||
return uint32_t(last.get() - first.get());
|
||||
}
|
||||
|
||||
static
|
||||
uint32_t
|
||||
readable_distance( const InputIterator& first, const InputIterator& last )
|
||||
{
|
||||
// assumes single fragment
|
||||
return uint32_t(last.get() - first.get());
|
||||
}
|
||||
static
|
||||
const typename InputIterator::value_type*
|
||||
read( const InputIterator& iter )
|
||||
{
|
||||
return iter.get();
|
||||
}
|
||||
|
||||
static
|
||||
const typename InputIterator::value_type*
|
||||
read( const InputIterator& iter )
|
||||
{
|
||||
return iter.get();
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
advance( InputIterator& s, difference_type n )
|
||||
{
|
||||
s.advance(n);
|
||||
}
|
||||
};
|
||||
static
|
||||
void
|
||||
advance( InputIterator& s, difference_type n )
|
||||
{
|
||||
s.advance(n);
|
||||
}
|
||||
};
|
||||
|
||||
template <class CharT>
|
||||
struct nsCharSourceTraits<CharT*>
|
||||
{
|
||||
typedef ptrdiff_t difference_type;
|
||||
|
||||
static
|
||||
uint32_t
|
||||
readable_distance( CharT* s )
|
||||
{
|
||||
typedef ptrdiff_t difference_type;
|
||||
return uint32_t(nsCharTraits<CharT>::length(s));
|
||||
// return numeric_limits<uint32_t>::max();
|
||||
}
|
||||
|
||||
static
|
||||
uint32_t
|
||||
readable_distance( CharT* s )
|
||||
{
|
||||
return uint32_t(nsCharTraits<CharT>::length(s));
|
||||
// return numeric_limits<uint32_t>::max();
|
||||
}
|
||||
static
|
||||
uint32_t
|
||||
readable_distance( CharT* first, CharT* last )
|
||||
{
|
||||
return uint32_t(last-first);
|
||||
}
|
||||
|
||||
static
|
||||
uint32_t
|
||||
readable_distance( CharT* first, CharT* last )
|
||||
{
|
||||
return uint32_t(last-first);
|
||||
}
|
||||
static
|
||||
const CharT*
|
||||
read( CharT* s )
|
||||
{
|
||||
return s;
|
||||
}
|
||||
|
||||
static
|
||||
const CharT*
|
||||
read( CharT* s )
|
||||
{
|
||||
return s;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
advance( CharT*& s, difference_type n )
|
||||
{
|
||||
s += n;
|
||||
}
|
||||
};
|
||||
static
|
||||
void
|
||||
advance( CharT*& s, difference_type n )
|
||||
{
|
||||
s += n;
|
||||
}
|
||||
};
|
||||
|
||||
template <class OutputIterator>
|
||||
struct nsCharSinkTraits
|
||||
{
|
||||
static
|
||||
void
|
||||
write( OutputIterator& iter, const typename OutputIterator::value_type* s, uint32_t n )
|
||||
{
|
||||
static
|
||||
void
|
||||
write( OutputIterator& iter, const typename OutputIterator::value_type* s, uint32_t n )
|
||||
{
|
||||
iter.write(s, n);
|
||||
}
|
||||
};
|
||||
iter.write(s, n);
|
||||
}
|
||||
};
|
||||
|
||||
template <class CharT>
|
||||
struct nsCharSinkTraits<CharT*>
|
||||
{
|
||||
static
|
||||
void
|
||||
write( CharT*& iter, const CharT* s, uint32_t n )
|
||||
{
|
||||
static
|
||||
void
|
||||
write( CharT*& iter, const CharT* s, uint32_t n )
|
||||
{
|
||||
nsCharTraits<CharT>::move(iter, s, n);
|
||||
iter += n;
|
||||
}
|
||||
};
|
||||
nsCharTraits<CharT>::move(iter, s, n);
|
||||
iter += n;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(nsCharTraits_h___)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
@ -10,12 +10,12 @@
|
||||
#include "nsString.h"
|
||||
#include "nsDebug.h"
|
||||
|
||||
// declare nsDependentString
|
||||
// declare nsDependentString
|
||||
#include "string-template-def-unichar.h"
|
||||
#include "nsTDependentString.h"
|
||||
#include "string-template-undef.h"
|
||||
|
||||
// declare nsDependentCString
|
||||
// declare nsDependentCString
|
||||
#include "string-template-def-char.h"
|
||||
#include "nsTDependentString.h"
|
||||
#include "string-template-undef.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
@ -9,12 +9,12 @@
|
||||
|
||||
#include "nsSubstring.h"
|
||||
|
||||
// declare nsDependentSubstring
|
||||
// declare nsDependentSubstring
|
||||
#include "string-template-def-unichar.h"
|
||||
#include "nsTDependentSubstring.h"
|
||||
#include "string-template-undef.h"
|
||||
|
||||
// declare nsDependentCSubstring
|
||||
// declare nsDependentCSubstring
|
||||
#include "string-template-def-char.h"
|
||||
#include "nsTDependentSubstring.h"
|
||||
#include "string-template-undef.h"
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
@ -9,12 +10,12 @@
|
||||
#include "nscore.h"
|
||||
#include "nsString.h"
|
||||
|
||||
// declare nsLiteralString
|
||||
// declare nsLiteralString
|
||||
#include "string-template-def-unichar.h"
|
||||
#include "nsTLiteralString.h"
|
||||
#include "string-template-undef.h"
|
||||
|
||||
// declare nsLiteralCString
|
||||
// declare nsLiteralCString
|
||||
#include "string-template-def-char.h"
|
||||
#include "nsTLiteralString.h"
|
||||
#include "string-template-undef.h"
|
||||
|
@ -1,11 +1,12 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
#ifndef nsPrintfCString_h___
|
||||
#define nsPrintfCString_h___
|
||||
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
@ -9,12 +9,12 @@
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
// declare nsPromiseFlatString
|
||||
// declare nsPromiseFlatString
|
||||
#include "string-template-def-unichar.h"
|
||||
#include "nsTPromiseFlatString.h"
|
||||
#include "string-template-undef.h"
|
||||
|
||||
// declare nsPromiseFlatCString
|
||||
// declare nsPromiseFlatCString
|
||||
#include "string-template-def-char.h"
|
||||
#include "nsTPromiseFlatString.h"
|
||||
#include "string-template-undef.h"
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
@ -7,23 +8,23 @@
|
||||
#ifndef nsReadableUtils_h___
|
||||
#define nsReadableUtils_h___
|
||||
|
||||
/**
|
||||
* I guess all the routines in this file are all mis-named.
|
||||
* According to our conventions, they should be |NS_xxx|.
|
||||
*/
|
||||
/**
|
||||
* I guess all the routines in this file are all mis-named.
|
||||
* According to our conventions, they should be |NS_xxx|.
|
||||
*/
|
||||
|
||||
#include "nsAString.h"
|
||||
|
||||
#include "nsTArrayForwardDeclare.h"
|
||||
|
||||
inline size_t Distance( const nsReadingIterator<char16_t>& start, const nsReadingIterator<char16_t>& end )
|
||||
{
|
||||
return end.get() - start.get();
|
||||
}
|
||||
{
|
||||
return end.get() - start.get();
|
||||
}
|
||||
inline size_t Distance( const nsReadingIterator<char>& start, const nsReadingIterator<char>& end )
|
||||
{
|
||||
return end.get() - start.get();
|
||||
}
|
||||
{
|
||||
return end.get() - start.get();
|
||||
}
|
||||
|
||||
void LossyCopyUTF16toASCII( const nsAString& aSource, nsACString& aDest );
|
||||
void CopyASCIItoUTF16( const nsACString& aSource, nsAString& aDest );
|
||||
@ -57,231 +58,231 @@ void AppendUTF8toUTF16( const char* aSource, nsAString& aDest );
|
||||
|
||||
#ifdef MOZ_USE_CHAR16_WRAPPER
|
||||
inline void AppendUTF16toUTF8( char16ptr_t aSource, nsACString& aDest )
|
||||
{
|
||||
return AppendUTF16toUTF8(static_cast<const char16_t*>(aSource), aDest);
|
||||
}
|
||||
{
|
||||
return AppendUTF16toUTF8(static_cast<const char16_t*>(aSource), aDest);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns a new |char| buffer containing a zero-terminated copy of |aSource|.
|
||||
*
|
||||
* Allocates and returns a new |char| buffer which you must free with |nsMemory::Free|.
|
||||
* Performs a lossy encoding conversion by chopping 16-bit wide characters down to 8-bits wide while copying |aSource| to your new buffer.
|
||||
* This conversion is not well defined; but it reproduces legacy string behavior.
|
||||
* The new buffer is zero-terminated, but that may not help you if |aSource| contains embedded nulls.
|
||||
*
|
||||
* @param aSource a 16-bit wide string
|
||||
* @return a new |char| buffer you must free with |nsMemory::Free|.
|
||||
*/
|
||||
/**
|
||||
* Returns a new |char| buffer containing a zero-terminated copy of |aSource|.
|
||||
*
|
||||
* Allocates and returns a new |char| buffer which you must free with |nsMemory::Free|.
|
||||
* Performs a lossy encoding conversion by chopping 16-bit wide characters down to 8-bits wide while copying |aSource| to your new buffer.
|
||||
* This conversion is not well defined; but it reproduces legacy string behavior.
|
||||
* The new buffer is zero-terminated, but that may not help you if |aSource| contains embedded nulls.
|
||||
*
|
||||
* @param aSource a 16-bit wide string
|
||||
* @return a new |char| buffer you must free with |nsMemory::Free|.
|
||||
*/
|
||||
char* ToNewCString( const nsAString& aSource );
|
||||
|
||||
|
||||
/**
|
||||
* Returns a new |char| buffer containing a zero-terminated copy of |aSource|.
|
||||
*
|
||||
* Allocates and returns a new |char| buffer which you must free with |nsMemory::Free|.
|
||||
* The new buffer is zero-terminated, but that may not help you if |aSource| contains embedded nulls.
|
||||
*
|
||||
* @param aSource an 8-bit wide string
|
||||
* @return a new |char| buffer you must free with |nsMemory::Free|.
|
||||
*/
|
||||
/**
|
||||
* Returns a new |char| buffer containing a zero-terminated copy of |aSource|.
|
||||
*
|
||||
* Allocates and returns a new |char| buffer which you must free with |nsMemory::Free|.
|
||||
* The new buffer is zero-terminated, but that may not help you if |aSource| contains embedded nulls.
|
||||
*
|
||||
* @param aSource an 8-bit wide string
|
||||
* @return a new |char| buffer you must free with |nsMemory::Free|.
|
||||
*/
|
||||
char* ToNewCString( const nsACString& aSource );
|
||||
|
||||
/**
|
||||
* Returns a new |char| buffer containing a zero-terminated copy of |aSource|.
|
||||
*
|
||||
* Allocates and returns a new |char| buffer which you must free with
|
||||
* |nsMemory::Free|.
|
||||
* Performs an encoding conversion from a UTF-16 string to a UTF-8 string
|
||||
* copying |aSource| to your new buffer.
|
||||
* The new buffer is zero-terminated, but that may not help you if |aSource|
|
||||
* contains embedded nulls.
|
||||
*
|
||||
* @param aSource a UTF-16 string (made of char16_t's)
|
||||
* @param aUTF8Count the number of 8-bit units that was returned
|
||||
* @return a new |char| buffer you must free with |nsMemory::Free|.
|
||||
*/
|
||||
/**
|
||||
* Returns a new |char| buffer containing a zero-terminated copy of |aSource|.
|
||||
*
|
||||
* Allocates and returns a new |char| buffer which you must free with
|
||||
* |nsMemory::Free|.
|
||||
* Performs an encoding conversion from a UTF-16 string to a UTF-8 string
|
||||
* copying |aSource| to your new buffer.
|
||||
* The new buffer is zero-terminated, but that may not help you if |aSource|
|
||||
* contains embedded nulls.
|
||||
*
|
||||
* @param aSource a UTF-16 string (made of char16_t's)
|
||||
* @param aUTF8Count the number of 8-bit units that was returned
|
||||
* @return a new |char| buffer you must free with |nsMemory::Free|.
|
||||
*/
|
||||
|
||||
char* ToNewUTF8String( const nsAString& aSource, uint32_t *aUTF8Count = nullptr );
|
||||
|
||||
|
||||
/**
|
||||
* Returns a new |char16_t| buffer containing a zero-terminated copy of
|
||||
* |aSource|.
|
||||
*
|
||||
* Allocates and returns a new |char16_t| buffer which you must free with
|
||||
* |nsMemory::Free|.
|
||||
* The new buffer is zero-terminated, but that may not help you if |aSource|
|
||||
* contains embedded nulls.
|
||||
*
|
||||
* @param aSource a UTF-16 string
|
||||
* @return a new |char16_t| buffer you must free with |nsMemory::Free|.
|
||||
*/
|
||||
/**
|
||||
* Returns a new |char16_t| buffer containing a zero-terminated copy of
|
||||
* |aSource|.
|
||||
*
|
||||
* Allocates and returns a new |char16_t| buffer which you must free with
|
||||
* |nsMemory::Free|.
|
||||
* The new buffer is zero-terminated, but that may not help you if |aSource|
|
||||
* contains embedded nulls.
|
||||
*
|
||||
* @param aSource a UTF-16 string
|
||||
* @return a new |char16_t| buffer you must free with |nsMemory::Free|.
|
||||
*/
|
||||
char16_t* ToNewUnicode( const nsAString& aSource );
|
||||
|
||||
|
||||
/**
|
||||
* Returns a new |char16_t| buffer containing a zero-terminated copy of |aSource|.
|
||||
*
|
||||
* Allocates and returns a new |char16_t| buffer which you must free with |nsMemory::Free|.
|
||||
* Performs an encoding conversion by 0-padding 8-bit wide characters up to 16-bits wide while copying |aSource| to your new buffer.
|
||||
* This conversion is not well defined; but it reproduces legacy string behavior.
|
||||
* The new buffer is zero-terminated, but that may not help you if |aSource| contains embedded nulls.
|
||||
*
|
||||
* @param aSource an 8-bit wide string (a C-string, NOT UTF-8)
|
||||
* @return a new |char16_t| buffer you must free with |nsMemory::Free|.
|
||||
*/
|
||||
/**
|
||||
* Returns a new |char16_t| buffer containing a zero-terminated copy of |aSource|.
|
||||
*
|
||||
* Allocates and returns a new |char16_t| buffer which you must free with |nsMemory::Free|.
|
||||
* Performs an encoding conversion by 0-padding 8-bit wide characters up to 16-bits wide while copying |aSource| to your new buffer.
|
||||
* This conversion is not well defined; but it reproduces legacy string behavior.
|
||||
* The new buffer is zero-terminated, but that may not help you if |aSource| contains embedded nulls.
|
||||
*
|
||||
* @param aSource an 8-bit wide string (a C-string, NOT UTF-8)
|
||||
* @return a new |char16_t| buffer you must free with |nsMemory::Free|.
|
||||
*/
|
||||
char16_t* ToNewUnicode( const nsACString& aSource );
|
||||
|
||||
/**
|
||||
* Returns the required length for a char16_t buffer holding
|
||||
* a copy of aSource, using UTF-8 to UTF-16 conversion.
|
||||
* The length does NOT include any space for zero-termination.
|
||||
*
|
||||
* @param aSource an 8-bit wide string, UTF-8 encoded
|
||||
* @return length of UTF-16 encoded string copy, not zero-terminated
|
||||
*/
|
||||
/**
|
||||
* Returns the required length for a char16_t buffer holding
|
||||
* a copy of aSource, using UTF-8 to UTF-16 conversion.
|
||||
* The length does NOT include any space for zero-termination.
|
||||
*
|
||||
* @param aSource an 8-bit wide string, UTF-8 encoded
|
||||
* @return length of UTF-16 encoded string copy, not zero-terminated
|
||||
*/
|
||||
uint32_t CalcUTF8ToUnicodeLength( const nsACString& aSource );
|
||||
|
||||
/**
|
||||
* Copies the source string into the specified buffer, converting UTF-8 to
|
||||
* UTF-16 in the process. The conversion is well defined for valid UTF-8
|
||||
* strings.
|
||||
* The copied string will be zero-terminated! Any embedded nulls will be
|
||||
* copied nonetheless. It is the caller's responsiblity to ensure the buffer
|
||||
* is large enough to hold the string copy plus one char16_t for
|
||||
* zero-termination!
|
||||
*
|
||||
* @see CalcUTF8ToUnicodeLength( const nsACString& )
|
||||
* @see UTF8ToNewUnicode( const nsACString&, uint32_t* )
|
||||
*
|
||||
* @param aSource an 8-bit wide string, UTF-8 encoded
|
||||
* @param aBuffer the buffer holding the converted string copy
|
||||
* @param aUTF16Count receiving optionally the number of 16-bit units that
|
||||
* were copied
|
||||
* @return aBuffer pointer, for convenience
|
||||
*/
|
||||
/**
|
||||
* Copies the source string into the specified buffer, converting UTF-8 to
|
||||
* UTF-16 in the process. The conversion is well defined for valid UTF-8
|
||||
* strings.
|
||||
* The copied string will be zero-terminated! Any embedded nulls will be
|
||||
* copied nonetheless. It is the caller's responsiblity to ensure the buffer
|
||||
* is large enough to hold the string copy plus one char16_t for
|
||||
* zero-termination!
|
||||
*
|
||||
* @see CalcUTF8ToUnicodeLength( const nsACString& )
|
||||
* @see UTF8ToNewUnicode( const nsACString&, uint32_t* )
|
||||
*
|
||||
* @param aSource an 8-bit wide string, UTF-8 encoded
|
||||
* @param aBuffer the buffer holding the converted string copy
|
||||
* @param aUTF16Count receiving optionally the number of 16-bit units that
|
||||
* were copied
|
||||
* @return aBuffer pointer, for convenience
|
||||
*/
|
||||
char16_t* UTF8ToUnicodeBuffer( const nsACString& aSource,
|
||||
char16_t *aBuffer,
|
||||
uint32_t *aUTF16Count = nullptr );
|
||||
char16_t *aBuffer,
|
||||
uint32_t *aUTF16Count = nullptr );
|
||||
|
||||
/**
|
||||
* Returns a new |char16_t| buffer containing a zero-terminated copy
|
||||
* of |aSource|.
|
||||
*
|
||||
* Allocates and returns a new |char| buffer which you must free with
|
||||
* |nsMemory::Free|. Performs an encoding conversion from UTF-8 to UTF-16
|
||||
* while copying |aSource| to your new buffer. This conversion is well defined
|
||||
* for a valid UTF-8 string. The new buffer is zero-terminated, but that
|
||||
* may not help you if |aSource| contains embedded nulls.
|
||||
*
|
||||
* @param aSource an 8-bit wide string, UTF-8 encoded
|
||||
* @param aUTF16Count the number of 16-bit units that was returned
|
||||
* @return a new |char16_t| buffer you must free with |nsMemory::Free|.
|
||||
* (UTF-16 encoded)
|
||||
*/
|
||||
/**
|
||||
* Returns a new |char16_t| buffer containing a zero-terminated copy
|
||||
* of |aSource|.
|
||||
*
|
||||
* Allocates and returns a new |char| buffer which you must free with
|
||||
* |nsMemory::Free|. Performs an encoding conversion from UTF-8 to UTF-16
|
||||
* while copying |aSource| to your new buffer. This conversion is well defined
|
||||
* for a valid UTF-8 string. The new buffer is zero-terminated, but that
|
||||
* may not help you if |aSource| contains embedded nulls.
|
||||
*
|
||||
* @param aSource an 8-bit wide string, UTF-8 encoded
|
||||
* @param aUTF16Count the number of 16-bit units that was returned
|
||||
* @return a new |char16_t| buffer you must free with |nsMemory::Free|.
|
||||
* (UTF-16 encoded)
|
||||
*/
|
||||
char16_t* UTF8ToNewUnicode( const nsACString& aSource, uint32_t *aUTF16Count = nullptr );
|
||||
|
||||
/**
|
||||
* Copies |aLength| 16-bit code units from the start of |aSource| to the
|
||||
* |char16_t| buffer |aDest|.
|
||||
*
|
||||
* After this operation |aDest| is not null terminated.
|
||||
*
|
||||
* @param aSource a UTF-16 string
|
||||
* @param aSrcOffset start offset in the source string
|
||||
* @param aDest a |char16_t| buffer
|
||||
* @param aLength the number of 16-bit code units to copy
|
||||
* @return pointer to destination buffer - identical to |aDest|
|
||||
*/
|
||||
/**
|
||||
* Copies |aLength| 16-bit code units from the start of |aSource| to the
|
||||
* |char16_t| buffer |aDest|.
|
||||
*
|
||||
* After this operation |aDest| is not null terminated.
|
||||
*
|
||||
* @param aSource a UTF-16 string
|
||||
* @param aSrcOffset start offset in the source string
|
||||
* @param aDest a |char16_t| buffer
|
||||
* @param aLength the number of 16-bit code units to copy
|
||||
* @return pointer to destination buffer - identical to |aDest|
|
||||
*/
|
||||
char16_t* CopyUnicodeTo( const nsAString& aSource,
|
||||
uint32_t aSrcOffset,
|
||||
char16_t* aDest,
|
||||
uint32_t aLength );
|
||||
uint32_t aSrcOffset,
|
||||
char16_t* aDest,
|
||||
uint32_t aLength );
|
||||
|
||||
|
||||
/**
|
||||
* Copies 16-bit characters between iterators |aSrcStart| and
|
||||
* |aSrcEnd| to the writable string |aDest|. Similar to the
|
||||
* |nsString::Mid| method.
|
||||
*
|
||||
* After this operation |aDest| is not null terminated.
|
||||
*
|
||||
* @param aSrcStart start source iterator
|
||||
* @param aSrcEnd end source iterator
|
||||
* @param aDest destination for the copy
|
||||
*/
|
||||
/**
|
||||
* Copies 16-bit characters between iterators |aSrcStart| and
|
||||
* |aSrcEnd| to the writable string |aDest|. Similar to the
|
||||
* |nsString::Mid| method.
|
||||
*
|
||||
* After this operation |aDest| is not null terminated.
|
||||
*
|
||||
* @param aSrcStart start source iterator
|
||||
* @param aSrcEnd end source iterator
|
||||
* @param aDest destination for the copy
|
||||
*/
|
||||
void CopyUnicodeTo( const nsAString::const_iterator& aSrcStart,
|
||||
const nsAString::const_iterator& aSrcEnd,
|
||||
nsAString& aDest );
|
||||
const nsAString::const_iterator& aSrcEnd,
|
||||
nsAString& aDest );
|
||||
|
||||
/**
|
||||
* Appends 16-bit characters between iterators |aSrcStart| and
|
||||
* |aSrcEnd| to the writable string |aDest|.
|
||||
*
|
||||
* After this operation |aDest| is not null terminated.
|
||||
*
|
||||
* @param aSrcStart start source iterator
|
||||
* @param aSrcEnd end source iterator
|
||||
* @param aDest destination for the copy
|
||||
*/
|
||||
/**
|
||||
* Appends 16-bit characters between iterators |aSrcStart| and
|
||||
* |aSrcEnd| to the writable string |aDest|.
|
||||
*
|
||||
* After this operation |aDest| is not null terminated.
|
||||
*
|
||||
* @param aSrcStart start source iterator
|
||||
* @param aSrcEnd end source iterator
|
||||
* @param aDest destination for the copy
|
||||
*/
|
||||
void AppendUnicodeTo( const nsAString::const_iterator& aSrcStart,
|
||||
const nsAString::const_iterator& aSrcEnd,
|
||||
nsAString& aDest );
|
||||
const nsAString::const_iterator& aSrcEnd,
|
||||
nsAString& aDest );
|
||||
|
||||
/**
|
||||
* Returns |true| if |aString| contains only ASCII characters, that is, characters in the range (0x00, 0x7F).
|
||||
*
|
||||
* @param aString a 16-bit wide string to scan
|
||||
*/
|
||||
/**
|
||||
* Returns |true| if |aString| contains only ASCII characters, that is, characters in the range (0x00, 0x7F).
|
||||
*
|
||||
* @param aString a 16-bit wide string to scan
|
||||
*/
|
||||
bool IsASCII( const nsAString& aString );
|
||||
|
||||
/**
|
||||
* Returns |true| if |aString| contains only ASCII characters, that is, characters in the range (0x00, 0x7F).
|
||||
*
|
||||
* @param aString a 8-bit wide string to scan
|
||||
*/
|
||||
/**
|
||||
* Returns |true| if |aString| contains only ASCII characters, that is, characters in the range (0x00, 0x7F).
|
||||
*
|
||||
* @param aString a 8-bit wide string to scan
|
||||
*/
|
||||
bool IsASCII( const nsACString& aString );
|
||||
|
||||
/**
|
||||
* Returns |true| if |aString| is a valid UTF-8 string.
|
||||
* XXX This is not bullet-proof and nor an all-purpose UTF-8 validator.
|
||||
* It is mainly written to replace and roughly equivalent to
|
||||
*
|
||||
* str.Equals(NS_ConvertUTF16toUTF8(NS_ConvertUTF8toUTF16(str)))
|
||||
*
|
||||
* (see bug 191541)
|
||||
* As such, it does not check for non-UTF-8 7bit encodings such as
|
||||
* ISO-2022-JP and HZ.
|
||||
*
|
||||
* It rejects sequences with the following errors:
|
||||
*
|
||||
* byte sequences that cannot be decoded into characters according to
|
||||
* UTF-8's rules (including cases where the input is part of a valid
|
||||
* UTF-8 sequence but starts or ends mid-character)
|
||||
* overlong sequences (i.e., cases where a character was encoded
|
||||
* non-canonically by using more bytes than necessary)
|
||||
* surrogate codepoints (i.e., the codepoints reserved for
|
||||
representing astral characters in UTF-16)
|
||||
* codepoints above the unicode range (i.e., outside the first 17
|
||||
* planes; higher than U+10FFFF), in accordance with
|
||||
* http://tools.ietf.org/html/rfc3629
|
||||
* when aRejectNonChar is true (the default), any codepoint whose low
|
||||
* 16 bits are 0xFFFE or 0xFFFF
|
||||
/**
|
||||
* Returns |true| if |aString| is a valid UTF-8 string.
|
||||
* XXX This is not bullet-proof and nor an all-purpose UTF-8 validator.
|
||||
* It is mainly written to replace and roughly equivalent to
|
||||
*
|
||||
* str.Equals(NS_ConvertUTF16toUTF8(NS_ConvertUTF8toUTF16(str)))
|
||||
*
|
||||
* (see bug 191541)
|
||||
* As such, it does not check for non-UTF-8 7bit encodings such as
|
||||
* ISO-2022-JP and HZ.
|
||||
*
|
||||
* It rejects sequences with the following errors:
|
||||
*
|
||||
* byte sequences that cannot be decoded into characters according to
|
||||
* UTF-8's rules (including cases where the input is part of a valid
|
||||
* UTF-8 sequence but starts or ends mid-character)
|
||||
* overlong sequences (i.e., cases where a character was encoded
|
||||
* non-canonically by using more bytes than necessary)
|
||||
* surrogate codepoints (i.e., the codepoints reserved for
|
||||
representing astral characters in UTF-16)
|
||||
* codepoints above the unicode range (i.e., outside the first 17
|
||||
* planes; higher than U+10FFFF), in accordance with
|
||||
* http://tools.ietf.org/html/rfc3629
|
||||
* when aRejectNonChar is true (the default), any codepoint whose low
|
||||
* 16 bits are 0xFFFE or 0xFFFF
|
||||
|
||||
*
|
||||
* @param aString an 8-bit wide string to scan
|
||||
* @param aRejectNonChar a boolean to control the rejection of utf-8
|
||||
* non characters
|
||||
*/
|
||||
*
|
||||
* @param aString an 8-bit wide string to scan
|
||||
* @param aRejectNonChar a boolean to control the rejection of utf-8
|
||||
* non characters
|
||||
*/
|
||||
bool IsUTF8( const nsACString& aString, bool aRejectNonChar = true );
|
||||
|
||||
bool ParseString(const nsACString& aAstring, char aDelimiter,
|
||||
nsTArray<nsCString>& aArray);
|
||||
bool ParseString(const nsACString& aAstring, char aDelimiter,
|
||||
nsTArray<nsCString>& aArray);
|
||||
|
||||
/**
|
||||
* Converts case in place in the argument string.
|
||||
*/
|
||||
/**
|
||||
* Converts case in place in the argument string.
|
||||
*/
|
||||
void ToUpperCase( nsACString& );
|
||||
|
||||
void ToLowerCase( nsACString& );
|
||||
@ -290,22 +291,22 @@ void ToUpperCase( nsCSubstring& );
|
||||
|
||||
void ToLowerCase( nsCSubstring& );
|
||||
|
||||
/**
|
||||
* Converts case from string aSource to aDest.
|
||||
*/
|
||||
/**
|
||||
* Converts case from string aSource to aDest.
|
||||
*/
|
||||
void ToUpperCase( const nsACString& aSource, nsACString& aDest );
|
||||
|
||||
void ToLowerCase( const nsACString& aSource, nsACString& aDest );
|
||||
|
||||
/**
|
||||
* Finds the leftmost occurrence of |aPattern|, if any in the range |aSearchStart|..|aSearchEnd|.
|
||||
*
|
||||
* Returns |true| if a match was found, and adjusts |aSearchStart| and |aSearchEnd| to
|
||||
* point to the match. If no match was found, returns |false| and makes |aSearchStart == aSearchEnd|.
|
||||
*
|
||||
* Currently, this is equivalent to the O(m*n) implementation previously on |ns[C]String|.
|
||||
* If we need something faster, then we can implement that later.
|
||||
*/
|
||||
/**
|
||||
* Finds the leftmost occurrence of |aPattern|, if any in the range |aSearchStart|..|aSearchEnd|.
|
||||
*
|
||||
* Returns |true| if a match was found, and adjusts |aSearchStart| and |aSearchEnd| to
|
||||
* point to the match. If no match was found, returns |false| and makes |aSearchStart == aSearchEnd|.
|
||||
*
|
||||
* Currently, this is equivalent to the O(m*n) implementation previously on |ns[C]String|.
|
||||
* If we need something faster, then we can implement that later.
|
||||
*/
|
||||
|
||||
bool FindInReadable( const nsAString& aPattern, nsAString::const_iterator&, nsAString::const_iterator&, const nsStringComparator& = nsDefaultStringComparator() );
|
||||
bool FindInReadable( const nsACString& aPattern, nsACString::const_iterator&, nsACString::const_iterator&, const nsCStringComparator& = nsDefaultCStringComparator() );
|
||||
@ -331,50 +332,50 @@ inline bool FindInReadable( const nsACString& aPattern, const nsACString& aSourc
|
||||
|
||||
bool CaseInsensitiveFindInReadable( const nsACString& aPattern, nsACString::const_iterator&, nsACString::const_iterator& );
|
||||
|
||||
/**
|
||||
* Finds the rightmost occurrence of |aPattern|
|
||||
* Returns |true| if a match was found, and adjusts |aSearchStart| and |aSearchEnd| to
|
||||
* point to the match. If no match was found, returns |false| and makes |aSearchStart == aSearchEnd|.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* Finds the rightmost occurrence of |aPattern|
|
||||
* Returns |true| if a match was found, and adjusts |aSearchStart| and |aSearchEnd| to
|
||||
* point to the match. If no match was found, returns |false| and makes |aSearchStart == aSearchEnd|.
|
||||
*
|
||||
*/
|
||||
bool RFindInReadable( const nsAString& aPattern, nsAString::const_iterator&, nsAString::const_iterator&, const nsStringComparator& = nsDefaultStringComparator() );
|
||||
bool RFindInReadable( const nsACString& aPattern, nsACString::const_iterator&, nsACString::const_iterator&, const nsCStringComparator& = nsDefaultCStringComparator() );
|
||||
|
||||
/**
|
||||
* Finds the leftmost occurrence of |aChar|, if any in the range
|
||||
* |aSearchStart|..|aSearchEnd|.
|
||||
*
|
||||
* Returns |true| if a match was found, and adjusts |aSearchStart| to
|
||||
* point to the match. If no match was found, returns |false| and
|
||||
* makes |aSearchStart == aSearchEnd|.
|
||||
*/
|
||||
/**
|
||||
* Finds the leftmost occurrence of |aChar|, if any in the range
|
||||
* |aSearchStart|..|aSearchEnd|.
|
||||
*
|
||||
* Returns |true| if a match was found, and adjusts |aSearchStart| to
|
||||
* point to the match. If no match was found, returns |false| and
|
||||
* makes |aSearchStart == aSearchEnd|.
|
||||
*/
|
||||
bool FindCharInReadable( char16_t aChar, nsAString::const_iterator& aSearchStart, const nsAString::const_iterator& aSearchEnd );
|
||||
bool FindCharInReadable( char aChar, nsACString::const_iterator& aSearchStart, const nsACString::const_iterator& aSearchEnd );
|
||||
|
||||
/**
|
||||
* Finds the number of occurences of |aChar| in the string |aStr|
|
||||
*/
|
||||
/**
|
||||
* Finds the number of occurences of |aChar| in the string |aStr|
|
||||
*/
|
||||
uint32_t CountCharInReadable( const nsAString& aStr,
|
||||
char16_t aChar );
|
||||
char16_t aChar );
|
||||
uint32_t CountCharInReadable( const nsACString& aStr,
|
||||
char aChar );
|
||||
char aChar );
|
||||
|
||||
bool
|
||||
StringBeginsWith( const nsAString& aSource, const nsAString& aSubstring,
|
||||
const nsStringComparator& aComparator =
|
||||
nsDefaultStringComparator() );
|
||||
nsDefaultStringComparator() );
|
||||
bool
|
||||
StringBeginsWith( const nsACString& aSource, const nsACString& aSubstring,
|
||||
const nsCStringComparator& aComparator =
|
||||
nsDefaultCStringComparator() );
|
||||
nsDefaultCStringComparator() );
|
||||
bool
|
||||
StringEndsWith( const nsAString& aSource, const nsAString& aSubstring,
|
||||
const nsStringComparator& aComparator =
|
||||
nsDefaultStringComparator() );
|
||||
nsDefaultStringComparator() );
|
||||
bool
|
||||
StringEndsWith( const nsACString& aSource, const nsACString& aSubstring,
|
||||
const nsCStringComparator& aComparator =
|
||||
nsDefaultCStringComparator() );
|
||||
nsDefaultCStringComparator() );
|
||||
|
||||
const nsAFlatString& EmptyString();
|
||||
const nsAFlatCString& EmptyCString();
|
||||
@ -382,14 +383,14 @@ const nsAFlatCString& EmptyCString();
|
||||
const nsAFlatString& NullString();
|
||||
const nsAFlatCString& NullCString();
|
||||
|
||||
/**
|
||||
* Compare a UTF-8 string to an UTF-16 string.
|
||||
*
|
||||
* Returns 0 if the strings are equal, -1 if aUTF8String is less
|
||||
* than aUTF16Count, and 1 in the reverse case. In case of fatal
|
||||
* error (eg the strings are not valid UTF8 and UTF16 respectively),
|
||||
* this method will return INT32_MIN.
|
||||
*/
|
||||
/**
|
||||
* Compare a UTF-8 string to an UTF-16 string.
|
||||
*
|
||||
* Returns 0 if the strings are equal, -1 if aUTF8String is less
|
||||
* than aUTF16Count, and 1 in the reverse case. In case of fatal
|
||||
* error (eg the strings are not valid UTF8 and UTF16 respectively),
|
||||
* this method will return INT32_MIN.
|
||||
*/
|
||||
int32_t
|
||||
CompareUTF8toUTF16(const nsASingleFragmentCString& aUTF8String,
|
||||
const nsASingleFragmentString& aUTF16String);
|
||||
@ -400,8 +401,8 @@ AppendUCS4ToUTF16(const uint32_t aSource, nsAString& aDest);
|
||||
template<class T>
|
||||
inline bool EnsureStringLength(T& aStr, uint32_t aLen)
|
||||
{
|
||||
aStr.SetLength(aLen);
|
||||
return (aStr.Length() == aLen);
|
||||
aStr.SetLength(aLen);
|
||||
return (aStr.Length() == aLen);
|
||||
}
|
||||
|
||||
#endif // !defined(nsReadableUtils_h___)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
@ -15,13 +15,13 @@
|
||||
|
||||
#include <new>
|
||||
|
||||
// enable support for the obsolete string API if not explicitly disabled
|
||||
// enable support for the obsolete string API if not explicitly disabled
|
||||
#ifndef MOZ_STRING_WITH_OBSOLETE_API
|
||||
#define MOZ_STRING_WITH_OBSOLETE_API 1
|
||||
#endif
|
||||
|
||||
#if MOZ_STRING_WITH_OBSOLETE_API
|
||||
// radix values for ToInteger/AppendInt
|
||||
// radix values for ToInteger/AppendInt
|
||||
#define kRadix10 (10)
|
||||
#define kRadix16 (16)
|
||||
#define kAutoDetect (100)
|
||||
@ -30,12 +30,12 @@
|
||||
#endif
|
||||
|
||||
|
||||
// declare nsString, et. al.
|
||||
// declare nsString, et. al.
|
||||
#include "string-template-def-unichar.h"
|
||||
#include "nsTString.h"
|
||||
#include "string-template-undef.h"
|
||||
|
||||
// declare nsCString, et. al.
|
||||
// declare nsCString, et. al.
|
||||
#include "string-template-def-char.h"
|
||||
#include "nsTString.h"
|
||||
#include "string-template-undef.h"
|
||||
@ -49,130 +49,130 @@ static_assert(sizeof(nsCString::char_type) == 1,
|
||||
"size of nsCString::char_type must be 1");
|
||||
|
||||
|
||||
/**
|
||||
* A helper class that converts a UTF-16 string to ASCII in a lossy manner
|
||||
*/
|
||||
/**
|
||||
* A helper class that converts a UTF-16 string to ASCII in a lossy manner
|
||||
*/
|
||||
class NS_LossyConvertUTF16toASCII : public nsAutoCString
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
NS_LossyConvertUTF16toASCII( const char16_t* aString )
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
NS_LossyConvertUTF16toASCII( const char16_t* aString )
|
||||
{
|
||||
LossyAppendUTF16toASCII(aString, *this);
|
||||
}
|
||||
LossyAppendUTF16toASCII(aString, *this);
|
||||
}
|
||||
|
||||
NS_LossyConvertUTF16toASCII( const char16_t* aString, uint32_t aLength )
|
||||
{
|
||||
LossyAppendUTF16toASCII(Substring(aString, aLength), *this);
|
||||
}
|
||||
NS_LossyConvertUTF16toASCII( const char16_t* aString, uint32_t aLength )
|
||||
{
|
||||
LossyAppendUTF16toASCII(Substring(aString, aLength), *this);
|
||||
}
|
||||
|
||||
#ifdef MOZ_USE_CHAR16_WRAPPER
|
||||
explicit
|
||||
NS_LossyConvertUTF16toASCII( char16ptr_t aString )
|
||||
: NS_LossyConvertUTF16toASCII(static_cast<const char16_t*>(aString)) {}
|
||||
explicit
|
||||
NS_LossyConvertUTF16toASCII( char16ptr_t aString )
|
||||
: NS_LossyConvertUTF16toASCII(static_cast<const char16_t*>(aString)) {}
|
||||
|
||||
NS_LossyConvertUTF16toASCII( char16ptr_t aString, uint32_t aLength )
|
||||
: NS_LossyConvertUTF16toASCII(static_cast<const char16_t*>(aString), aLength) {}
|
||||
NS_LossyConvertUTF16toASCII( char16ptr_t aString, uint32_t aLength )
|
||||
: NS_LossyConvertUTF16toASCII(static_cast<const char16_t*>(aString), aLength) {}
|
||||
#endif
|
||||
|
||||
explicit
|
||||
NS_LossyConvertUTF16toASCII( const nsAString& aString )
|
||||
{
|
||||
LossyAppendUTF16toASCII(aString, *this);
|
||||
}
|
||||
explicit
|
||||
NS_LossyConvertUTF16toASCII( const nsAString& aString )
|
||||
{
|
||||
LossyAppendUTF16toASCII(aString, *this);
|
||||
}
|
||||
|
||||
private:
|
||||
// NOT TO BE IMPLEMENTED
|
||||
NS_LossyConvertUTF16toASCII( char );
|
||||
};
|
||||
private:
|
||||
// NOT TO BE IMPLEMENTED
|
||||
NS_LossyConvertUTF16toASCII( char );
|
||||
};
|
||||
|
||||
|
||||
class NS_ConvertASCIItoUTF16 : public nsAutoString
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
NS_ConvertASCIItoUTF16( const char* aCString )
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
NS_ConvertASCIItoUTF16( const char* aCString )
|
||||
{
|
||||
AppendASCIItoUTF16(aCString, *this);
|
||||
}
|
||||
AppendASCIItoUTF16(aCString, *this);
|
||||
}
|
||||
|
||||
NS_ConvertASCIItoUTF16( const char* aCString, uint32_t aLength )
|
||||
{
|
||||
AppendASCIItoUTF16(Substring(aCString, aLength), *this);
|
||||
}
|
||||
NS_ConvertASCIItoUTF16( const char* aCString, uint32_t aLength )
|
||||
{
|
||||
AppendASCIItoUTF16(Substring(aCString, aLength), *this);
|
||||
}
|
||||
|
||||
explicit
|
||||
NS_ConvertASCIItoUTF16( const nsACString& aCString )
|
||||
{
|
||||
AppendASCIItoUTF16(aCString, *this);
|
||||
}
|
||||
explicit
|
||||
NS_ConvertASCIItoUTF16( const nsACString& aCString )
|
||||
{
|
||||
AppendASCIItoUTF16(aCString, *this);
|
||||
}
|
||||
|
||||
private:
|
||||
// NOT TO BE IMPLEMENTED
|
||||
NS_ConvertASCIItoUTF16( char16_t );
|
||||
};
|
||||
private:
|
||||
// NOT TO BE IMPLEMENTED
|
||||
NS_ConvertASCIItoUTF16( char16_t );
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* A helper class that converts a UTF-16 string to UTF-8
|
||||
*/
|
||||
/**
|
||||
* A helper class that converts a UTF-16 string to UTF-8
|
||||
*/
|
||||
class NS_ConvertUTF16toUTF8 : public nsAutoCString
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
NS_ConvertUTF16toUTF8( const char16_t* aString )
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
NS_ConvertUTF16toUTF8( const char16_t* aString )
|
||||
{
|
||||
AppendUTF16toUTF8(aString, *this);
|
||||
}
|
||||
AppendUTF16toUTF8(aString, *this);
|
||||
}
|
||||
|
||||
NS_ConvertUTF16toUTF8( const char16_t* aString, uint32_t aLength )
|
||||
{
|
||||
AppendUTF16toUTF8(Substring(aString, aLength), *this);
|
||||
}
|
||||
NS_ConvertUTF16toUTF8( const char16_t* aString, uint32_t aLength )
|
||||
{
|
||||
AppendUTF16toUTF8(Substring(aString, aLength), *this);
|
||||
}
|
||||
|
||||
#ifdef MOZ_USE_CHAR16_WRAPPER
|
||||
NS_ConvertUTF16toUTF8( char16ptr_t aString ) : NS_ConvertUTF16toUTF8(static_cast<const char16_t*>(aString)) {}
|
||||
NS_ConvertUTF16toUTF8( char16ptr_t aString ) : NS_ConvertUTF16toUTF8(static_cast<const char16_t*>(aString)) {}
|
||||
|
||||
NS_ConvertUTF16toUTF8( char16ptr_t aString, uint32_t aLength )
|
||||
: NS_ConvertUTF16toUTF8(static_cast<const char16_t*>(aString), aLength) {}
|
||||
NS_ConvertUTF16toUTF8( char16ptr_t aString, uint32_t aLength )
|
||||
: NS_ConvertUTF16toUTF8(static_cast<const char16_t*>(aString), aLength) {}
|
||||
#endif
|
||||
|
||||
explicit
|
||||
NS_ConvertUTF16toUTF8( const nsAString& aString )
|
||||
{
|
||||
AppendUTF16toUTF8(aString, *this);
|
||||
}
|
||||
explicit
|
||||
NS_ConvertUTF16toUTF8( const nsAString& aString )
|
||||
{
|
||||
AppendUTF16toUTF8(aString, *this);
|
||||
}
|
||||
|
||||
private:
|
||||
// NOT TO BE IMPLEMENTED
|
||||
NS_ConvertUTF16toUTF8( char );
|
||||
};
|
||||
private:
|
||||
// NOT TO BE IMPLEMENTED
|
||||
NS_ConvertUTF16toUTF8( char );
|
||||
};
|
||||
|
||||
|
||||
class NS_ConvertUTF8toUTF16 : public nsAutoString
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
NS_ConvertUTF8toUTF16( const char* aCString )
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
NS_ConvertUTF8toUTF16( const char* aCString )
|
||||
{
|
||||
AppendUTF8toUTF16(aCString, *this);
|
||||
}
|
||||
AppendUTF8toUTF16(aCString, *this);
|
||||
}
|
||||
|
||||
NS_ConvertUTF8toUTF16( const char* aCString, uint32_t aLength )
|
||||
{
|
||||
AppendUTF8toUTF16(Substring(aCString, aLength), *this);
|
||||
}
|
||||
NS_ConvertUTF8toUTF16( const char* aCString, uint32_t aLength )
|
||||
{
|
||||
AppendUTF8toUTF16(Substring(aCString, aLength), *this);
|
||||
}
|
||||
|
||||
explicit
|
||||
NS_ConvertUTF8toUTF16( const nsACString& aCString )
|
||||
{
|
||||
AppendUTF8toUTF16(aCString, *this);
|
||||
}
|
||||
explicit
|
||||
NS_ConvertUTF8toUTF16( const nsACString& aCString )
|
||||
{
|
||||
AppendUTF8toUTF16(aCString, *this);
|
||||
}
|
||||
|
||||
private:
|
||||
// NOT TO BE IMPLEMENTED
|
||||
NS_ConvertUTF8toUTF16( char16_t );
|
||||
};
|
||||
private:
|
||||
// NOT TO BE IMPLEMENTED
|
||||
NS_ConvertUTF8toUTF16( char16_t );
|
||||
};
|
||||
|
||||
|
||||
#ifdef MOZ_USE_CHAR16_WRAPPER
|
||||
@ -180,13 +180,13 @@ class NS_ConvertUTF8toUTF16 : public nsAutoString
|
||||
inline char16_t*
|
||||
wwc(wchar_t *str)
|
||||
{
|
||||
return reinterpret_cast<char16_t*>(str);
|
||||
return reinterpret_cast<char16_t*>(str);
|
||||
}
|
||||
|
||||
inline wchar_t*
|
||||
wwc(char16_t *str)
|
||||
{
|
||||
return reinterpret_cast<wchar_t*>(str);
|
||||
return reinterpret_cast<wchar_t*>(str);
|
||||
}
|
||||
|
||||
#else
|
||||
@ -194,7 +194,7 @@ wwc(char16_t *str)
|
||||
inline char16_t*
|
||||
wwc(char16_t *str)
|
||||
{
|
||||
return str;
|
||||
return str;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
@ -22,147 +22,147 @@ template<class T> struct already_AddRefed;
|
||||
* count is 1.
|
||||
*/
|
||||
class nsStringBuffer
|
||||
{
|
||||
private:
|
||||
friend class CheckStaticAtomSizes;
|
||||
|
||||
mozilla::Atomic<int32_t> mRefCount;
|
||||
uint32_t mStorageSize;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Allocates a new string buffer, with given size in bytes and a
|
||||
* reference count of one. When the string buffer is no longer needed,
|
||||
* it should be released via Release.
|
||||
*
|
||||
* It is up to the caller to set the bytes corresponding to the string
|
||||
* buffer by calling the Data method to fetch the raw data pointer. Care
|
||||
* must be taken to properly null terminate the character array. The
|
||||
* storage size can be greater than the length of the actual string
|
||||
* (i.e., it is not required that the null terminator appear in the last
|
||||
* storage unit of the string buffer's data).
|
||||
*
|
||||
* @return new string buffer or null if out of memory.
|
||||
*/
|
||||
static already_AddRefed<nsStringBuffer> Alloc(size_t storageSize);
|
||||
|
||||
/**
|
||||
* Resizes the given string buffer to the specified storage size. This
|
||||
* method must not be called on a readonly string buffer. Use this API
|
||||
* carefully!!
|
||||
*
|
||||
* This method behaves like the ANSI-C realloc function. (i.e., If the
|
||||
* allocation fails, null will be returned and the given string buffer
|
||||
* will remain unmodified.)
|
||||
*
|
||||
* @see IsReadonly
|
||||
*/
|
||||
static nsStringBuffer* Realloc(nsStringBuffer* buf, size_t storageSize);
|
||||
|
||||
/**
|
||||
* Increment the reference count on this string buffer.
|
||||
*/
|
||||
void NS_FASTCALL AddRef();
|
||||
|
||||
/**
|
||||
* Decrement the reference count on this string buffer. The string
|
||||
* buffer will be destroyed when its reference count reaches zero.
|
||||
*/
|
||||
void NS_FASTCALL Release();
|
||||
|
||||
/**
|
||||
* This method returns the string buffer corresponding to the given data
|
||||
* pointer. The data pointer must have been returned previously by a
|
||||
* call to the nsStringBuffer::Data method.
|
||||
*/
|
||||
static nsStringBuffer* FromData(void* data)
|
||||
{
|
||||
private:
|
||||
friend class CheckStaticAtomSizes;
|
||||
return reinterpret_cast<nsStringBuffer*> (data) - 1;
|
||||
}
|
||||
|
||||
mozilla::Atomic<int32_t> mRefCount;
|
||||
uint32_t mStorageSize;
|
||||
/**
|
||||
* This method returns the data pointer for this string buffer.
|
||||
*/
|
||||
void* Data() const
|
||||
{
|
||||
return const_cast<char*> (reinterpret_cast<const char*> (this + 1));
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Allocates a new string buffer, with given size in bytes and a
|
||||
* reference count of one. When the string buffer is no longer needed,
|
||||
* it should be released via Release.
|
||||
*
|
||||
* It is up to the caller to set the bytes corresponding to the string
|
||||
* buffer by calling the Data method to fetch the raw data pointer. Care
|
||||
* must be taken to properly null terminate the character array. The
|
||||
* storage size can be greater than the length of the actual string
|
||||
* (i.e., it is not required that the null terminator appear in the last
|
||||
* storage unit of the string buffer's data).
|
||||
*
|
||||
* @return new string buffer or null if out of memory.
|
||||
*/
|
||||
static already_AddRefed<nsStringBuffer> Alloc(size_t storageSize);
|
||||
/**
|
||||
* This function returns the storage size of a string buffer in bytes.
|
||||
* This value is the same value that was originally passed to Alloc (or
|
||||
* Realloc).
|
||||
*/
|
||||
uint32_t StorageSize() const
|
||||
{
|
||||
return mStorageSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resizes the given string buffer to the specified storage size. This
|
||||
* method must not be called on a readonly string buffer. Use this API
|
||||
* carefully!!
|
||||
*
|
||||
* This method behaves like the ANSI-C realloc function. (i.e., If the
|
||||
* allocation fails, null will be returned and the given string buffer
|
||||
* will remain unmodified.)
|
||||
*
|
||||
* @see IsReadonly
|
||||
*/
|
||||
static nsStringBuffer* Realloc(nsStringBuffer* buf, size_t storageSize);
|
||||
/**
|
||||
* If this method returns false, then the caller can be sure that their
|
||||
* reference to the string buffer is the only reference to the string
|
||||
* buffer, and therefore it has exclusive access to the string buffer and
|
||||
* associated data. However, if this function returns true, then other
|
||||
* consumers may rely on the data in this buffer being immutable and
|
||||
* other threads may access this buffer simultaneously.
|
||||
*/
|
||||
bool IsReadonly() const
|
||||
{
|
||||
return mRefCount > 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the reference count on this string buffer.
|
||||
*/
|
||||
void NS_FASTCALL AddRef();
|
||||
/**
|
||||
* The FromString methods return a string buffer for the given string
|
||||
* object or null if the string object does not have a string buffer.
|
||||
* The reference count of the string buffer is NOT incremented by these
|
||||
* methods. If the caller wishes to hold onto the returned value, then
|
||||
* the returned string buffer must have its reference count incremented
|
||||
* via a call to the AddRef method.
|
||||
*/
|
||||
static nsStringBuffer* FromString(const nsAString &str);
|
||||
static nsStringBuffer* FromString(const nsACString &str);
|
||||
|
||||
/**
|
||||
* Decrement the reference count on this string buffer. The string
|
||||
* buffer will be destroyed when its reference count reaches zero.
|
||||
*/
|
||||
void NS_FASTCALL Release();
|
||||
/**
|
||||
* The ToString methods assign this string buffer to a given string
|
||||
* object. If the string object does not support sharable string
|
||||
* buffers, then its value will be set to a copy of the given string
|
||||
* buffer. Otherwise, these methods increment the reference count of the
|
||||
* given string buffer. It is important to specify the length (in
|
||||
* storage units) of the string contained in the string buffer since the
|
||||
* length of the string may be less than its storage size. The string
|
||||
* must have a null terminator at the offset specified by |len|.
|
||||
*
|
||||
* NOTE: storage size is measured in bytes even for wide strings;
|
||||
* however, string length is always measured in storage units
|
||||
* (2-byte units for wide strings).
|
||||
*/
|
||||
void ToString(uint32_t len, nsAString &str,
|
||||
bool aMoveOwnership = false);
|
||||
void ToString(uint32_t len, nsACString &str,
|
||||
bool aMoveOwnership = false);
|
||||
|
||||
/**
|
||||
* This method returns the string buffer corresponding to the given data
|
||||
* pointer. The data pointer must have been returned previously by a
|
||||
* call to the nsStringBuffer::Data method.
|
||||
*/
|
||||
static nsStringBuffer* FromData(void* data)
|
||||
{
|
||||
return reinterpret_cast<nsStringBuffer*> (data) - 1;
|
||||
}
|
||||
/**
|
||||
* This measures the size. It should only be used if the StringBuffer is
|
||||
* unshared. This is checked.
|
||||
*/
|
||||
size_t SizeOfIncludingThisMustBeUnshared(mozilla::MallocSizeOf aMallocSizeOf) const;
|
||||
|
||||
/**
|
||||
* This method returns the data pointer for this string buffer.
|
||||
*/
|
||||
void* Data() const
|
||||
{
|
||||
return const_cast<char*> (reinterpret_cast<const char*> (this + 1));
|
||||
}
|
||||
/**
|
||||
* This measures the size only if the StringBuffer is unshared.
|
||||
*/
|
||||
size_t SizeOfIncludingThisIfUnshared(mozilla::MallocSizeOf aMallocSizeOf) const;
|
||||
|
||||
/**
|
||||
* This function returns the storage size of a string buffer in bytes.
|
||||
* This value is the same value that was originally passed to Alloc (or
|
||||
* Realloc).
|
||||
*/
|
||||
uint32_t StorageSize() const
|
||||
{
|
||||
return mStorageSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this method returns false, then the caller can be sure that their
|
||||
* reference to the string buffer is the only reference to the string
|
||||
* buffer, and therefore it has exclusive access to the string buffer and
|
||||
* associated data. However, if this function returns true, then other
|
||||
* consumers may rely on the data in this buffer being immutable and
|
||||
* other threads may access this buffer simultaneously.
|
||||
*/
|
||||
bool IsReadonly() const
|
||||
{
|
||||
return mRefCount > 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* The FromString methods return a string buffer for the given string
|
||||
* object or null if the string object does not have a string buffer.
|
||||
* The reference count of the string buffer is NOT incremented by these
|
||||
* methods. If the caller wishes to hold onto the returned value, then
|
||||
* the returned string buffer must have its reference count incremented
|
||||
* via a call to the AddRef method.
|
||||
*/
|
||||
static nsStringBuffer* FromString(const nsAString &str);
|
||||
static nsStringBuffer* FromString(const nsACString &str);
|
||||
|
||||
/**
|
||||
* The ToString methods assign this string buffer to a given string
|
||||
* object. If the string object does not support sharable string
|
||||
* buffers, then its value will be set to a copy of the given string
|
||||
* buffer. Otherwise, these methods increment the reference count of the
|
||||
* given string buffer. It is important to specify the length (in
|
||||
* storage units) of the string contained in the string buffer since the
|
||||
* length of the string may be less than its storage size. The string
|
||||
* must have a null terminator at the offset specified by |len|.
|
||||
*
|
||||
* NOTE: storage size is measured in bytes even for wide strings;
|
||||
* however, string length is always measured in storage units
|
||||
* (2-byte units for wide strings).
|
||||
*/
|
||||
void ToString(uint32_t len, nsAString &str,
|
||||
bool aMoveOwnership = false);
|
||||
void ToString(uint32_t len, nsACString &str,
|
||||
bool aMoveOwnership = false);
|
||||
|
||||
/**
|
||||
* This measures the size. It should only be used if the StringBuffer is
|
||||
* unshared. This is checked.
|
||||
*/
|
||||
size_t SizeOfIncludingThisMustBeUnshared(mozilla::MallocSizeOf aMallocSizeOf) const;
|
||||
|
||||
/**
|
||||
* This measures the size only if the StringBuffer is unshared.
|
||||
*/
|
||||
size_t SizeOfIncludingThisIfUnshared(mozilla::MallocSizeOf aMallocSizeOf) const;
|
||||
|
||||
/**
|
||||
* This measures the size regardless of whether the StringBuffer is
|
||||
* unshared.
|
||||
*
|
||||
* WARNING: Only use this if you really know what you are doing, because
|
||||
* it can easily lead to double-counting strings. If you do use them,
|
||||
* please explain clearly in a comment why it's safe and won't lead to
|
||||
* double-counting.
|
||||
*/
|
||||
size_t SizeOfIncludingThisEvenIfShared(mozilla::MallocSizeOf aMallocSizeOf) const;
|
||||
};
|
||||
/**
|
||||
* This measures the size regardless of whether the StringBuffer is
|
||||
* unshared.
|
||||
*
|
||||
* WARNING: Only use this if you really know what you are doing, because
|
||||
* it can easily lead to double-counting strings. If you do use them,
|
||||
* please explain clearly in a comment why it's safe and won't lead to
|
||||
* double-counting.
|
||||
*/
|
||||
size_t SizeOfIncludingThisEvenIfShared(mozilla::MallocSizeOf aMallocSizeOf) const;
|
||||
};
|
||||
|
||||
#endif /* !defined(nsStringBuffer_h__ */
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
@ -14,9 +15,9 @@
|
||||
#error Internal string headers are not available from external-linkage code.
|
||||
#endif
|
||||
|
||||
/**
|
||||
* double-byte (char16_t) string types
|
||||
*/
|
||||
/**
|
||||
* double-byte (char16_t) string types
|
||||
*/
|
||||
|
||||
class nsAString;
|
||||
class nsSubstringTuple;
|
||||
@ -30,9 +31,9 @@ class nsDefaultStringComparator;
|
||||
class nsXPIDLString;
|
||||
|
||||
|
||||
/**
|
||||
* single-byte (char) string types
|
||||
*/
|
||||
/**
|
||||
* single-byte (char) string types
|
||||
*/
|
||||
|
||||
class nsACString;
|
||||
class nsCSubstringTuple;
|
||||
@ -46,9 +47,9 @@ class nsDefaultCStringComparator;
|
||||
class nsXPIDLCString;
|
||||
|
||||
|
||||
/**
|
||||
* typedefs for backwards compatibility
|
||||
*/
|
||||
/**
|
||||
* typedefs for backwards compatibility
|
||||
*/
|
||||
|
||||
typedef nsAString nsSubstring;
|
||||
typedef nsACString nsCSubstring;
|
||||
@ -59,5 +60,5 @@ typedef nsSubstring nsASingleFragmentString;
|
||||
typedef nsCString nsAFlatCString;
|
||||
typedef nsCSubstring nsASingleFragmentCString;
|
||||
|
||||
|
||||
|
||||
#endif /* !defined(nsStringFwd_h___) */
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
@ -10,318 +11,318 @@
|
||||
#include "nsAlgorithm.h"
|
||||
#include "nsDebug.h"
|
||||
|
||||
/**
|
||||
* @see nsTAString
|
||||
*/
|
||||
/**
|
||||
* @see nsTAString
|
||||
*/
|
||||
|
||||
template <class CharT>
|
||||
class nsReadingIterator
|
||||
{
|
||||
public:
|
||||
typedef nsReadingIterator<CharT> self_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef CharT value_type;
|
||||
typedef const CharT* pointer;
|
||||
typedef const CharT& reference;
|
||||
|
||||
private:
|
||||
friend class nsAString;
|
||||
friend class nsACString;
|
||||
|
||||
// unfortunately, the API for nsReadingIterator requires that the
|
||||
// iterator know its start and end positions. this was needed when
|
||||
// we supported multi-fragment strings, but now it is really just
|
||||
// extra baggage. we should remove mStart and mEnd at some point.
|
||||
|
||||
const CharT* mStart;
|
||||
const CharT* mEnd;
|
||||
const CharT* mPosition;
|
||||
|
||||
public:
|
||||
nsReadingIterator() { }
|
||||
// nsReadingIterator( const nsReadingIterator<CharT>& ); // auto-generated copy-constructor OK
|
||||
// nsReadingIterator<CharT>& operator=( const nsReadingIterator<CharT>& ); // auto-generated copy-assignment operator OK
|
||||
|
||||
inline void normalize_forward() {}
|
||||
inline void normalize_backward() {}
|
||||
|
||||
pointer
|
||||
start() const
|
||||
{
|
||||
public:
|
||||
typedef nsReadingIterator<CharT> self_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef CharT value_type;
|
||||
typedef const CharT* pointer;
|
||||
typedef const CharT& reference;
|
||||
return mStart;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class nsAString;
|
||||
friend class nsACString;
|
||||
pointer
|
||||
end() const
|
||||
{
|
||||
return mEnd;
|
||||
}
|
||||
|
||||
// unfortunately, the API for nsReadingIterator requires that the
|
||||
// iterator know its start and end positions. this was needed when
|
||||
// we supported multi-fragment strings, but now it is really just
|
||||
// extra baggage. we should remove mStart and mEnd at some point.
|
||||
pointer
|
||||
get() const
|
||||
{
|
||||
return mPosition;
|
||||
}
|
||||
|
||||
const CharT* mStart;
|
||||
const CharT* mEnd;
|
||||
const CharT* mPosition;
|
||||
|
||||
public:
|
||||
nsReadingIterator() { }
|
||||
// nsReadingIterator( const nsReadingIterator<CharT>& ); // auto-generated copy-constructor OK
|
||||
// nsReadingIterator<CharT>& operator=( const nsReadingIterator<CharT>& ); // auto-generated copy-assignment operator OK
|
||||
|
||||
inline void normalize_forward() {}
|
||||
inline void normalize_backward() {}
|
||||
|
||||
pointer
|
||||
start() const
|
||||
{
|
||||
return mStart;
|
||||
}
|
||||
|
||||
pointer
|
||||
end() const
|
||||
{
|
||||
return mEnd;
|
||||
}
|
||||
|
||||
pointer
|
||||
get() const
|
||||
{
|
||||
return mPosition;
|
||||
}
|
||||
|
||||
CharT
|
||||
operator*() const
|
||||
{
|
||||
return *get();
|
||||
}
|
||||
CharT
|
||||
operator*() const
|
||||
{
|
||||
return *get();
|
||||
}
|
||||
|
||||
#if 0
|
||||
// An iterator really deserves this, but some compilers (notably IBM VisualAge for OS/2)
|
||||
// don't like this when |CharT| is a type without members.
|
||||
pointer
|
||||
operator->() const
|
||||
{
|
||||
return get();
|
||||
}
|
||||
// An iterator really deserves this, but some compilers (notably IBM VisualAge for OS/2)
|
||||
// don't like this when |CharT| is a type without members.
|
||||
pointer
|
||||
operator->() const
|
||||
{
|
||||
return get();
|
||||
}
|
||||
#endif
|
||||
|
||||
self_type&
|
||||
operator++()
|
||||
{
|
||||
++mPosition;
|
||||
return *this;
|
||||
}
|
||||
self_type&
|
||||
operator++()
|
||||
{
|
||||
++mPosition;
|
||||
return *this;
|
||||
}
|
||||
|
||||
self_type
|
||||
operator++( int )
|
||||
{
|
||||
self_type result(*this);
|
||||
++mPosition;
|
||||
return result;
|
||||
}
|
||||
self_type
|
||||
operator++( int )
|
||||
{
|
||||
self_type result(*this);
|
||||
++mPosition;
|
||||
return result;
|
||||
}
|
||||
|
||||
self_type&
|
||||
operator--()
|
||||
{
|
||||
--mPosition;
|
||||
return *this;
|
||||
}
|
||||
self_type&
|
||||
operator--()
|
||||
{
|
||||
--mPosition;
|
||||
return *this;
|
||||
}
|
||||
|
||||
self_type
|
||||
operator--( int )
|
||||
{
|
||||
self_type result(*this);
|
||||
--mPosition;
|
||||
return result;
|
||||
}
|
||||
self_type
|
||||
operator--( int )
|
||||
{
|
||||
self_type result(*this);
|
||||
--mPosition;
|
||||
return result;
|
||||
}
|
||||
|
||||
difference_type
|
||||
size_forward() const
|
||||
{
|
||||
return mEnd - mPosition;
|
||||
}
|
||||
difference_type
|
||||
size_forward() const
|
||||
{
|
||||
return mEnd - mPosition;
|
||||
}
|
||||
|
||||
difference_type
|
||||
size_backward() const
|
||||
{
|
||||
return mPosition - mStart;
|
||||
}
|
||||
difference_type
|
||||
size_backward() const
|
||||
{
|
||||
return mPosition - mStart;
|
||||
}
|
||||
|
||||
self_type&
|
||||
advance( difference_type n )
|
||||
{
|
||||
if (n > 0)
|
||||
{
|
||||
difference_type step = XPCOM_MIN(n, size_forward());
|
||||
self_type&
|
||||
advance( difference_type n )
|
||||
{
|
||||
if (n > 0)
|
||||
{
|
||||
difference_type step = XPCOM_MIN(n, size_forward());
|
||||
|
||||
NS_ASSERTION(step>0, "can't advance a reading iterator beyond the end of a string");
|
||||
NS_ASSERTION(step>0, "can't advance a reading iterator beyond the end of a string");
|
||||
|
||||
mPosition += step;
|
||||
}
|
||||
else if (n < 0)
|
||||
{
|
||||
difference_type step = XPCOM_MAX(n, -size_backward());
|
||||
mPosition += step;
|
||||
}
|
||||
else if (n < 0)
|
||||
{
|
||||
difference_type step = XPCOM_MAX(n, -size_backward());
|
||||
|
||||
NS_ASSERTION(step<0, "can't advance (backward) a reading iterator beyond the end of a string");
|
||||
NS_ASSERTION(step<0, "can't advance (backward) a reading iterator beyond the end of a string");
|
||||
|
||||
mPosition += step;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
mPosition += step;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @see nsTAString
|
||||
*/
|
||||
/**
|
||||
* @see nsTAString
|
||||
*/
|
||||
|
||||
template <class CharT>
|
||||
class nsWritingIterator
|
||||
{
|
||||
public:
|
||||
typedef nsWritingIterator<CharT> self_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef CharT value_type;
|
||||
typedef CharT* pointer;
|
||||
typedef CharT& reference;
|
||||
|
||||
private:
|
||||
friend class nsAString;
|
||||
friend class nsACString;
|
||||
|
||||
// unfortunately, the API for nsWritingIterator requires that the
|
||||
// iterator know its start and end positions. this was needed when
|
||||
// we supported multi-fragment strings, but now it is really just
|
||||
// extra baggage. we should remove mStart and mEnd at some point.
|
||||
|
||||
CharT* mStart;
|
||||
CharT* mEnd;
|
||||
CharT* mPosition;
|
||||
|
||||
public:
|
||||
nsWritingIterator() { }
|
||||
// nsWritingIterator( const nsWritingIterator<CharT>& ); // auto-generated copy-constructor OK
|
||||
// nsWritingIterator<CharT>& operator=( const nsWritingIterator<CharT>& ); // auto-generated copy-assignment operator OK
|
||||
|
||||
inline void normalize_forward() {}
|
||||
inline void normalize_backward() {}
|
||||
|
||||
pointer
|
||||
start() const
|
||||
{
|
||||
public:
|
||||
typedef nsWritingIterator<CharT> self_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef CharT value_type;
|
||||
typedef CharT* pointer;
|
||||
typedef CharT& reference;
|
||||
return mStart;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class nsAString;
|
||||
friend class nsACString;
|
||||
pointer
|
||||
end() const
|
||||
{
|
||||
return mEnd;
|
||||
}
|
||||
|
||||
// unfortunately, the API for nsWritingIterator requires that the
|
||||
// iterator know its start and end positions. this was needed when
|
||||
// we supported multi-fragment strings, but now it is really just
|
||||
// extra baggage. we should remove mStart and mEnd at some point.
|
||||
pointer
|
||||
get() const
|
||||
{
|
||||
return mPosition;
|
||||
}
|
||||
|
||||
CharT* mStart;
|
||||
CharT* mEnd;
|
||||
CharT* mPosition;
|
||||
|
||||
public:
|
||||
nsWritingIterator() { }
|
||||
// nsWritingIterator( const nsWritingIterator<CharT>& ); // auto-generated copy-constructor OK
|
||||
// nsWritingIterator<CharT>& operator=( const nsWritingIterator<CharT>& ); // auto-generated copy-assignment operator OK
|
||||
|
||||
inline void normalize_forward() {}
|
||||
inline void normalize_backward() {}
|
||||
|
||||
pointer
|
||||
start() const
|
||||
{
|
||||
return mStart;
|
||||
}
|
||||
|
||||
pointer
|
||||
end() const
|
||||
{
|
||||
return mEnd;
|
||||
}
|
||||
|
||||
pointer
|
||||
get() const
|
||||
{
|
||||
return mPosition;
|
||||
}
|
||||
|
||||
reference
|
||||
operator*() const
|
||||
{
|
||||
return *get();
|
||||
}
|
||||
reference
|
||||
operator*() const
|
||||
{
|
||||
return *get();
|
||||
}
|
||||
|
||||
#if 0
|
||||
// An iterator really deserves this, but some compilers (notably IBM VisualAge for OS/2)
|
||||
// don't like this when |CharT| is a type without members.
|
||||
pointer
|
||||
operator->() const
|
||||
{
|
||||
return get();
|
||||
}
|
||||
// An iterator really deserves this, but some compilers (notably IBM VisualAge for OS/2)
|
||||
// don't like this when |CharT| is a type without members.
|
||||
pointer
|
||||
operator->() const
|
||||
{
|
||||
return get();
|
||||
}
|
||||
#endif
|
||||
|
||||
self_type&
|
||||
operator++()
|
||||
{
|
||||
++mPosition;
|
||||
return *this;
|
||||
}
|
||||
self_type&
|
||||
operator++()
|
||||
{
|
||||
++mPosition;
|
||||
return *this;
|
||||
}
|
||||
|
||||
self_type
|
||||
operator++( int )
|
||||
{
|
||||
self_type result(*this);
|
||||
++mPosition;
|
||||
return result;
|
||||
}
|
||||
self_type
|
||||
operator++( int )
|
||||
{
|
||||
self_type result(*this);
|
||||
++mPosition;
|
||||
return result;
|
||||
}
|
||||
|
||||
self_type&
|
||||
operator--()
|
||||
{
|
||||
--mPosition;
|
||||
return *this;
|
||||
}
|
||||
self_type&
|
||||
operator--()
|
||||
{
|
||||
--mPosition;
|
||||
return *this;
|
||||
}
|
||||
|
||||
self_type
|
||||
operator--( int )
|
||||
{
|
||||
self_type result(*this);
|
||||
--mPosition;
|
||||
return result;
|
||||
}
|
||||
self_type
|
||||
operator--( int )
|
||||
{
|
||||
self_type result(*this);
|
||||
--mPosition;
|
||||
return result;
|
||||
}
|
||||
|
||||
difference_type
|
||||
size_forward() const
|
||||
{
|
||||
return mEnd - mPosition;
|
||||
}
|
||||
difference_type
|
||||
size_forward() const
|
||||
{
|
||||
return mEnd - mPosition;
|
||||
}
|
||||
|
||||
difference_type
|
||||
size_backward() const
|
||||
{
|
||||
return mPosition - mStart;
|
||||
}
|
||||
difference_type
|
||||
size_backward() const
|
||||
{
|
||||
return mPosition - mStart;
|
||||
}
|
||||
|
||||
self_type&
|
||||
advance( difference_type n )
|
||||
{
|
||||
if (n > 0)
|
||||
{
|
||||
difference_type step = XPCOM_MIN(n, size_forward());
|
||||
self_type&
|
||||
advance( difference_type n )
|
||||
{
|
||||
if (n > 0)
|
||||
{
|
||||
difference_type step = XPCOM_MIN(n, size_forward());
|
||||
|
||||
NS_ASSERTION(step>0, "can't advance a writing iterator beyond the end of a string");
|
||||
NS_ASSERTION(step>0, "can't advance a writing iterator beyond the end of a string");
|
||||
|
||||
mPosition += step;
|
||||
}
|
||||
else if (n < 0)
|
||||
{
|
||||
difference_type step = XPCOM_MAX(n, -size_backward());
|
||||
mPosition += step;
|
||||
}
|
||||
else if (n < 0)
|
||||
{
|
||||
difference_type step = XPCOM_MAX(n, -size_backward());
|
||||
|
||||
NS_ASSERTION(step<0, "can't advance (backward) a writing iterator beyond the end of a string");
|
||||
NS_ASSERTION(step<0, "can't advance (backward) a writing iterator beyond the end of a string");
|
||||
|
||||
mPosition += step;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
mPosition += step;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
write( const value_type* s, uint32_t n )
|
||||
{
|
||||
NS_ASSERTION(size_forward() > 0, "You can't |write| into an |nsWritingIterator| with no space!");
|
||||
void
|
||||
write( const value_type* s, uint32_t n )
|
||||
{
|
||||
NS_ASSERTION(size_forward() > 0, "You can't |write| into an |nsWritingIterator| with no space!");
|
||||
|
||||
nsCharTraits<value_type>::move(mPosition, s, n);
|
||||
advance( difference_type(n) );
|
||||
}
|
||||
};
|
||||
nsCharTraits<value_type>::move(mPosition, s, n);
|
||||
advance( difference_type(n) );
|
||||
}
|
||||
};
|
||||
|
||||
template <class CharT>
|
||||
inline
|
||||
bool
|
||||
operator==( const nsReadingIterator<CharT>& lhs, const nsReadingIterator<CharT>& rhs )
|
||||
{
|
||||
return lhs.get() == rhs.get();
|
||||
}
|
||||
{
|
||||
return lhs.get() == rhs.get();
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
inline
|
||||
bool
|
||||
operator!=( const nsReadingIterator<CharT>& lhs, const nsReadingIterator<CharT>& rhs )
|
||||
{
|
||||
return lhs.get() != rhs.get();
|
||||
}
|
||||
{
|
||||
return lhs.get() != rhs.get();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// |nsWritingIterator|s
|
||||
//
|
||||
//
|
||||
// |nsWritingIterator|s
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
inline
|
||||
bool
|
||||
operator==( const nsWritingIterator<CharT>& lhs, const nsWritingIterator<CharT>& rhs )
|
||||
{
|
||||
return lhs.get() == rhs.get();
|
||||
}
|
||||
{
|
||||
return lhs.get() == rhs.get();
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
inline
|
||||
bool
|
||||
operator!=( const nsWritingIterator<CharT>& lhs, const nsWritingIterator<CharT>& rhs )
|
||||
{
|
||||
return lhs.get() != rhs.get();
|
||||
}
|
||||
{
|
||||
return lhs.get() != rhs.get();
|
||||
}
|
||||
|
||||
#endif /* !defined(nsStringIterator_h___) */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
@ -9,12 +9,12 @@
|
||||
|
||||
#include "nsSubstring.h"
|
||||
|
||||
// declare nsSubstringTuple
|
||||
// declare nsSubstringTuple
|
||||
#include "string-template-def-unichar.h"
|
||||
#include "nsTSubstringTuple.h"
|
||||
#include "string-template-undef.h"
|
||||
|
||||
// declare nsCSubstringTuple
|
||||
// declare nsCSubstringTuple
|
||||
#include "string-template-def-char.h"
|
||||
#include "nsTSubstringTuple.h"
|
||||
#include "string-template-undef.h"
|
||||
|
@ -1,98 +1,98 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
|
||||
/**
|
||||
* nsTDependentString_CharT
|
||||
*
|
||||
* Stores a null-terminated, immutable sequence of characters.
|
||||
*
|
||||
* Subclass of nsTString that restricts string value to an immutable
|
||||
* character sequence. This class does not own its data, so the creator
|
||||
* of objects of this type must take care to ensure that a
|
||||
* nsTDependentString continues to reference valid memory for the
|
||||
* duration of its use.
|
||||
*/
|
||||
/**
|
||||
* nsTDependentString_CharT
|
||||
*
|
||||
* Stores a null-terminated, immutable sequence of characters.
|
||||
*
|
||||
* Subclass of nsTString that restricts string value to an immutable
|
||||
* character sequence. This class does not own its data, so the creator
|
||||
* of objects of this type must take care to ensure that a
|
||||
* nsTDependentString continues to reference valid memory for the
|
||||
* duration of its use.
|
||||
*/
|
||||
class nsTDependentString_CharT : public nsTString_CharT
|
||||
{
|
||||
public:
|
||||
|
||||
typedef nsTDependentString_CharT self_type;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* constructors
|
||||
*/
|
||||
|
||||
nsTDependentString_CharT( const char_type* start, const char_type* end )
|
||||
: string_type(const_cast<char_type*>(start), uint32_t(end - start), F_TERMINATED)
|
||||
{
|
||||
public:
|
||||
AssertValidDepedentString();
|
||||
}
|
||||
|
||||
typedef nsTDependentString_CharT self_type;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* constructors
|
||||
*/
|
||||
|
||||
nsTDependentString_CharT( const char_type* start, const char_type* end )
|
||||
: string_type(const_cast<char_type*>(start), uint32_t(end - start), F_TERMINATED)
|
||||
{
|
||||
AssertValidDepedentString();
|
||||
}
|
||||
|
||||
nsTDependentString_CharT( const char_type* data, uint32_t length )
|
||||
: string_type(const_cast<char_type*>(data), length, F_TERMINATED)
|
||||
{
|
||||
AssertValidDepedentString();
|
||||
}
|
||||
nsTDependentString_CharT( const char_type* data, uint32_t length )
|
||||
: string_type(const_cast<char_type*>(data), length, F_TERMINATED)
|
||||
{
|
||||
AssertValidDepedentString();
|
||||
}
|
||||
|
||||
#if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER)
|
||||
nsTDependentString_CharT( char16ptr_t data, uint32_t length )
|
||||
: nsTDependentString_CharT(static_cast<const char16_t*>(data), length) {}
|
||||
nsTDependentString_CharT( char16ptr_t data, uint32_t length )
|
||||
: nsTDependentString_CharT(static_cast<const char16_t*>(data), length) {}
|
||||
#endif
|
||||
|
||||
explicit
|
||||
nsTDependentString_CharT( const char_type* data )
|
||||
: string_type(const_cast<char_type*>(data), uint32_t(char_traits::length(data)), F_TERMINATED)
|
||||
{
|
||||
AssertValidDepedentString();
|
||||
}
|
||||
explicit
|
||||
nsTDependentString_CharT( const char_type* data )
|
||||
: string_type(const_cast<char_type*>(data), uint32_t(char_traits::length(data)), F_TERMINATED)
|
||||
{
|
||||
AssertValidDepedentString();
|
||||
}
|
||||
|
||||
#if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER)
|
||||
explicit
|
||||
nsTDependentString_CharT( char16ptr_t data )
|
||||
: nsTDependentString_CharT( static_cast<const char16_t*>(data)) {}
|
||||
explicit
|
||||
nsTDependentString_CharT( char16ptr_t data )
|
||||
: nsTDependentString_CharT( static_cast<const char16_t*>(data)) {}
|
||||
#endif
|
||||
|
||||
nsTDependentString_CharT( const string_type& str, uint32_t startPos )
|
||||
: string_type()
|
||||
{
|
||||
Rebind(str, startPos);
|
||||
}
|
||||
nsTDependentString_CharT( const string_type& str, uint32_t startPos )
|
||||
: string_type()
|
||||
{
|
||||
Rebind(str, startPos);
|
||||
}
|
||||
|
||||
// Create a nsTDependentSubstring to be bound later
|
||||
nsTDependentString_CharT()
|
||||
: string_type() {}
|
||||
// Create a nsTDependentSubstring to be bound later
|
||||
nsTDependentString_CharT()
|
||||
: string_type() {}
|
||||
|
||||
// XXX are you sure??
|
||||
// auto-generated copy-constructor OK
|
||||
// auto-generated copy-assignment operator OK
|
||||
// auto-generated destructor OK
|
||||
// XXX are you sure??
|
||||
// auto-generated copy-constructor OK
|
||||
// auto-generated copy-assignment operator OK
|
||||
// auto-generated destructor OK
|
||||
|
||||
|
||||
/**
|
||||
* allow this class to be bound to a different string...
|
||||
*/
|
||||
/**
|
||||
* allow this class to be bound to a different string...
|
||||
*/
|
||||
|
||||
using nsTString_CharT::Rebind;
|
||||
void Rebind( const char_type* data )
|
||||
{
|
||||
Rebind(data, uint32_t(char_traits::length(data)));
|
||||
}
|
||||
using nsTString_CharT::Rebind;
|
||||
void Rebind( const char_type* data )
|
||||
{
|
||||
Rebind(data, uint32_t(char_traits::length(data)));
|
||||
}
|
||||
|
||||
void Rebind( const char_type* start, const char_type* end )
|
||||
{
|
||||
Rebind(start, uint32_t(end - start));
|
||||
}
|
||||
void Rebind( const char_type* start, const char_type* end )
|
||||
{
|
||||
Rebind(start, uint32_t(end - start));
|
||||
}
|
||||
|
||||
void Rebind( const string_type&, uint32_t startPos );
|
||||
void Rebind( const string_type&, uint32_t startPos );
|
||||
|
||||
private:
|
||||
|
||||
// NOT USED
|
||||
nsTDependentString_CharT( const substring_tuple_type& );
|
||||
};
|
||||
private:
|
||||
|
||||
// NOT USED
|
||||
nsTDependentString_CharT( const substring_tuple_type& );
|
||||
};
|
||||
|
@ -1,110 +1,110 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
// IWYU pragma: private, include "nsString.h"
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
public:
|
||||
|
||||
typedef nsTDependentSubstring_CharT self_type;
|
||||
|
||||
public:
|
||||
|
||||
void Rebind( const substring_type&, uint32_t startPos, uint32_t length = size_type(-1) );
|
||||
|
||||
void Rebind( const char_type* data, size_type length );
|
||||
|
||||
void Rebind( const char_type* start, const char_type* end )
|
||||
{
|
||||
public:
|
||||
Rebind(start, size_type(end - start));
|
||||
}
|
||||
|
||||
typedef nsTDependentSubstring_CharT self_type;
|
||||
nsTDependentSubstring_CharT( const substring_type& str, uint32_t startPos, uint32_t length = size_type(-1) )
|
||||
: substring_type()
|
||||
{
|
||||
Rebind(str, startPos, length);
|
||||
}
|
||||
|
||||
public:
|
||||
nsTDependentSubstring_CharT( const char_type* data, size_type length )
|
||||
: substring_type(const_cast<char_type*>(data), length, F_NONE) {}
|
||||
|
||||
void Rebind( const substring_type&, uint32_t startPos, uint32_t length = size_type(-1) );
|
||||
|
||||
void Rebind( const char_type* data, size_type length );
|
||||
|
||||
void Rebind( const char_type* start, const char_type* end )
|
||||
{
|
||||
Rebind(start, size_type(end - start));
|
||||
}
|
||||
|
||||
nsTDependentSubstring_CharT( const substring_type& str, uint32_t startPos, uint32_t length = size_type(-1) )
|
||||
: substring_type()
|
||||
{
|
||||
Rebind(str, startPos, length);
|
||||
}
|
||||
|
||||
nsTDependentSubstring_CharT( const char_type* data, size_type length )
|
||||
: substring_type(const_cast<char_type*>(data), length, F_NONE) {}
|
||||
|
||||
nsTDependentSubstring_CharT( const char_type* start, const char_type* end )
|
||||
: substring_type(const_cast<char_type*>(start), uint32_t(end - start), F_NONE) {}
|
||||
nsTDependentSubstring_CharT( const char_type* start, const char_type* end )
|
||||
: substring_type(const_cast<char_type*>(start), uint32_t(end - start), F_NONE) {}
|
||||
|
||||
#if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER)
|
||||
nsTDependentSubstring_CharT( char16ptr_t data, size_type length )
|
||||
: nsTDependentSubstring_CharT(static_cast<const char16_t*>(data), length) {}
|
||||
nsTDependentSubstring_CharT( char16ptr_t data, size_type length )
|
||||
: nsTDependentSubstring_CharT(static_cast<const char16_t*>(data), length) {}
|
||||
|
||||
nsTDependentSubstring_CharT( char16ptr_t start, char16ptr_t end )
|
||||
: nsTDependentSubstring_CharT(static_cast<const char16_t*>(start), static_cast<const char16_t*>(end)) {}
|
||||
nsTDependentSubstring_CharT( char16ptr_t start, char16ptr_t end )
|
||||
: nsTDependentSubstring_CharT(static_cast<const char16_t*>(start), static_cast<const char16_t*>(end)) {}
|
||||
#endif
|
||||
|
||||
nsTDependentSubstring_CharT( const const_iterator& start, const const_iterator& end )
|
||||
: substring_type(const_cast<char_type*>(start.get()), uint32_t(end.get() - start.get()), F_NONE) {}
|
||||
nsTDependentSubstring_CharT( const const_iterator& start, const const_iterator& end )
|
||||
: substring_type(const_cast<char_type*>(start.get()), uint32_t(end.get() - start.get()), F_NONE) {}
|
||||
|
||||
// Create a nsTDependentSubstring to be bound later
|
||||
nsTDependentSubstring_CharT()
|
||||
: substring_type() {}
|
||||
// Create a nsTDependentSubstring to be bound later
|
||||
nsTDependentSubstring_CharT()
|
||||
: substring_type() {}
|
||||
|
||||
// auto-generated copy-constructor OK (XXX really?? what about base class copy-ctor?)
|
||||
// auto-generated copy-constructor OK (XXX really?? what about base class copy-ctor?)
|
||||
|
||||
private:
|
||||
// NOT USED
|
||||
void operator=( const self_type& ); // we're immutable, you can't assign into a substring
|
||||
};
|
||||
private:
|
||||
// NOT USED
|
||||
void operator=( const self_type& ); // we're immutable, you can't assign into a substring
|
||||
};
|
||||
|
||||
inline
|
||||
const nsTDependentSubstring_CharT
|
||||
Substring( const nsTSubstring_CharT& str, uint32_t startPos, uint32_t length = uint32_t(-1) )
|
||||
{
|
||||
return nsTDependentSubstring_CharT(str, startPos, length);
|
||||
}
|
||||
{
|
||||
return nsTDependentSubstring_CharT(str, startPos, length);
|
||||
}
|
||||
|
||||
inline
|
||||
const nsTDependentSubstring_CharT
|
||||
Substring( const nsReadingIterator<CharT>& start, const nsReadingIterator<CharT>& end )
|
||||
{
|
||||
return nsTDependentSubstring_CharT(start.get(), end.get());
|
||||
}
|
||||
{
|
||||
return nsTDependentSubstring_CharT(start.get(), end.get());
|
||||
}
|
||||
|
||||
inline
|
||||
const nsTDependentSubstring_CharT
|
||||
Substring( const CharT* data, uint32_t length )
|
||||
{
|
||||
return nsTDependentSubstring_CharT(data, length);
|
||||
}
|
||||
{
|
||||
return nsTDependentSubstring_CharT(data, length);
|
||||
}
|
||||
|
||||
inline
|
||||
const nsTDependentSubstring_CharT
|
||||
Substring( const CharT* start, const CharT* end )
|
||||
{
|
||||
return nsTDependentSubstring_CharT(start, end);
|
||||
}
|
||||
{
|
||||
return nsTDependentSubstring_CharT(start, end);
|
||||
}
|
||||
|
||||
inline
|
||||
const nsTDependentSubstring_CharT
|
||||
StringHead( const nsTSubstring_CharT& str, uint32_t count )
|
||||
{
|
||||
return nsTDependentSubstring_CharT(str, 0, count);
|
||||
}
|
||||
{
|
||||
return nsTDependentSubstring_CharT(str, 0, count);
|
||||
}
|
||||
|
||||
inline
|
||||
const nsTDependentSubstring_CharT
|
||||
StringTail( const nsTSubstring_CharT& str, uint32_t count )
|
||||
{
|
||||
return nsTDependentSubstring_CharT(str, str.Length() - count, count);
|
||||
}
|
||||
{
|
||||
return nsTDependentSubstring_CharT(str, str.Length() - count, count);
|
||||
}
|
||||
|
@ -1,41 +1,41 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
|
||||
/**
|
||||
* nsTLiteralString_CharT
|
||||
*
|
||||
* Stores a null-terminated, immutable sequence of characters.
|
||||
*
|
||||
* Subclass of nsTString that restricts string value to a literal
|
||||
* character sequence. This class does not own its data. The data is
|
||||
* assumed to be permanent. In practice this is true because this code
|
||||
* is only usable by and for libxul.
|
||||
*/
|
||||
/**
|
||||
* nsTLiteralString_CharT
|
||||
*
|
||||
* Stores a null-terminated, immutable sequence of characters.
|
||||
*
|
||||
* Subclass of nsTString that restricts string value to a literal
|
||||
* character sequence. This class does not own its data. The data is
|
||||
* assumed to be permanent. In practice this is true because this code
|
||||
* is only usable by and for libxul.
|
||||
*/
|
||||
class nsTLiteralString_CharT : public nsTString_CharT
|
||||
{
|
||||
public:
|
||||
|
||||
typedef nsTLiteralString_CharT self_type;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*/
|
||||
|
||||
template<size_type N>
|
||||
nsTLiteralString_CharT( const char_type (&str)[N] )
|
||||
: string_type(const_cast<char_type*>(str), N - 1, F_TERMINATED | F_LITERAL)
|
||||
{
|
||||
public:
|
||||
}
|
||||
|
||||
typedef nsTLiteralString_CharT self_type;
|
||||
private:
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*/
|
||||
|
||||
template<size_type N>
|
||||
nsTLiteralString_CharT( const char_type (&str)[N] )
|
||||
: string_type(const_cast<char_type*>(str), N - 1, F_TERMINATED | F_LITERAL)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// NOT TO BE IMPLEMENTED
|
||||
template<size_type N>
|
||||
nsTLiteralString_CharT( char_type (&str)[N] ) MOZ_DELETE;
|
||||
};
|
||||
// NOT TO BE IMPLEMENTED
|
||||
template<size_type N>
|
||||
nsTLiteralString_CharT( char_type (&str)[N] ) MOZ_DELETE;
|
||||
};
|
||||
|
@ -1,106 +1,106 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
|
||||
/**
|
||||
* NOTE:
|
||||
*
|
||||
* Try to avoid flat strings. |PromiseFlat[C]String| will help you as a last
|
||||
* resort, and this may be necessary when dealing with legacy or OS calls,
|
||||
* but in general, requiring a null-terminated array of characters kills many
|
||||
* of the performance wins the string classes offer. Write your own code to
|
||||
* use |nsA[C]String&|s for parameters. Write your string proccessing
|
||||
* algorithms to exploit iterators. If you do this, you will benefit from
|
||||
* being able to chain operations without copying or allocating and your code
|
||||
* will be significantly more efficient. Remember, a function that takes an
|
||||
* |const nsA[C]String&| can always be passed a raw character pointer by
|
||||
* wrapping it (for free) in a |nsDependent[C]String|. But a function that
|
||||
* takes a character pointer always has the potential to force allocation and
|
||||
* copying.
|
||||
*
|
||||
*
|
||||
* How to use it:
|
||||
*
|
||||
* A |nsPromiseFlat[C]String| doesn't necessarily own the characters it
|
||||
* promises. You must never use it to promise characters out of a string
|
||||
* with a shorter lifespan. The typical use will be something like this:
|
||||
*
|
||||
* SomeOSFunction( PromiseFlatCString(aCSubstring).get() ); // GOOD
|
||||
*
|
||||
* Here's a BAD use:
|
||||
*
|
||||
* const char* buffer = PromiseFlatCString(aCSubstring).get();
|
||||
* SomeOSFunction(buffer); // BAD!! |buffer| is a dangling pointer
|
||||
*
|
||||
* The only way to make one is with the function |PromiseFlat[C]String|,
|
||||
* which produce a |const| instance. ``What if I need to keep a promise
|
||||
* around for a little while?'' you might ask. In that case, you can keep a
|
||||
* reference, like so
|
||||
*
|
||||
* const nsCString& flat = PromiseFlatString(aCSubstring);
|
||||
* // this reference holds the anonymous temporary alive, but remember,
|
||||
* // it must _still_ have a lifetime shorter than that of |aCSubstring|
|
||||
*
|
||||
* SomeOSFunction(flat.get());
|
||||
* SomeOtherOSFunction(flat.get());
|
||||
*
|
||||
*
|
||||
* How does it work?
|
||||
*
|
||||
* A |nsPromiseFlat[C]String| is just a wrapper for another string. If you
|
||||
* apply it to a string that happens to be flat, your promise is just a
|
||||
* dependent reference to the string's data. If you apply it to a non-flat
|
||||
* string, then a temporary flat string is created for you, by allocating and
|
||||
* copying. In the event that you end up assigning the result into a sharing
|
||||
* string (e.g., |nsTString|), the right thing happens.
|
||||
*/
|
||||
/**
|
||||
* NOTE:
|
||||
*
|
||||
* Try to avoid flat strings. |PromiseFlat[C]String| will help you as a last
|
||||
* resort, and this may be necessary when dealing with legacy or OS calls,
|
||||
* but in general, requiring a null-terminated array of characters kills many
|
||||
* of the performance wins the string classes offer. Write your own code to
|
||||
* use |nsA[C]String&|s for parameters. Write your string proccessing
|
||||
* algorithms to exploit iterators. If you do this, you will benefit from
|
||||
* being able to chain operations without copying or allocating and your code
|
||||
* will be significantly more efficient. Remember, a function that takes an
|
||||
* |const nsA[C]String&| can always be passed a raw character pointer by
|
||||
* wrapping it (for free) in a |nsDependent[C]String|. But a function that
|
||||
* takes a character pointer always has the potential to force allocation and
|
||||
* copying.
|
||||
*
|
||||
*
|
||||
* How to use it:
|
||||
*
|
||||
* A |nsPromiseFlat[C]String| doesn't necessarily own the characters it
|
||||
* promises. You must never use it to promise characters out of a string
|
||||
* with a shorter lifespan. The typical use will be something like this:
|
||||
*
|
||||
* SomeOSFunction( PromiseFlatCString(aCSubstring).get() ); // GOOD
|
||||
*
|
||||
* Here's a BAD use:
|
||||
*
|
||||
* const char* buffer = PromiseFlatCString(aCSubstring).get();
|
||||
* SomeOSFunction(buffer); // BAD!! |buffer| is a dangling pointer
|
||||
*
|
||||
* The only way to make one is with the function |PromiseFlat[C]String|,
|
||||
* which produce a |const| instance. ``What if I need to keep a promise
|
||||
* around for a little while?'' you might ask. In that case, you can keep a
|
||||
* reference, like so
|
||||
*
|
||||
* const nsCString& flat = PromiseFlatString(aCSubstring);
|
||||
* // this reference holds the anonymous temporary alive, but remember,
|
||||
* // it must _still_ have a lifetime shorter than that of |aCSubstring|
|
||||
*
|
||||
* SomeOSFunction(flat.get());
|
||||
* SomeOtherOSFunction(flat.get());
|
||||
*
|
||||
*
|
||||
* How does it work?
|
||||
*
|
||||
* A |nsPromiseFlat[C]String| is just a wrapper for another string. If you
|
||||
* apply it to a string that happens to be flat, your promise is just a
|
||||
* dependent reference to the string's data. If you apply it to a non-flat
|
||||
* string, then a temporary flat string is created for you, by allocating and
|
||||
* copying. In the event that you end up assigning the result into a sharing
|
||||
* string (e.g., |nsTString|), the right thing happens.
|
||||
*/
|
||||
|
||||
class nsTPromiseFlatString_CharT : public nsTString_CharT
|
||||
{
|
||||
public:
|
||||
|
||||
typedef nsTPromiseFlatString_CharT self_type;
|
||||
|
||||
private:
|
||||
|
||||
void Init( const substring_type& );
|
||||
|
||||
// NOT TO BE IMPLEMENTED
|
||||
void operator=( const self_type& ) MOZ_DELETE;
|
||||
|
||||
// NOT TO BE IMPLEMENTED
|
||||
nsTPromiseFlatString_CharT() MOZ_DELETE;
|
||||
|
||||
// NOT TO BE IMPLEMENTED
|
||||
nsTPromiseFlatString_CharT( const string_type& str ) MOZ_DELETE;
|
||||
|
||||
public:
|
||||
|
||||
explicit
|
||||
nsTPromiseFlatString_CharT( const substring_type& str )
|
||||
: string_type()
|
||||
{
|
||||
public:
|
||||
Init(str);
|
||||
}
|
||||
|
||||
typedef nsTPromiseFlatString_CharT self_type;
|
||||
|
||||
private:
|
||||
|
||||
void Init( const substring_type& );
|
||||
|
||||
// NOT TO BE IMPLEMENTED
|
||||
void operator=( const self_type& ) MOZ_DELETE;
|
||||
|
||||
// NOT TO BE IMPLEMENTED
|
||||
nsTPromiseFlatString_CharT() MOZ_DELETE;
|
||||
|
||||
// NOT TO BE IMPLEMENTED
|
||||
nsTPromiseFlatString_CharT( const string_type& str ) MOZ_DELETE;
|
||||
|
||||
public:
|
||||
|
||||
explicit
|
||||
nsTPromiseFlatString_CharT( const substring_type& str )
|
||||
: string_type()
|
||||
{
|
||||
Init(str);
|
||||
}
|
||||
|
||||
explicit
|
||||
nsTPromiseFlatString_CharT( const substring_tuple_type& tuple )
|
||||
: string_type()
|
||||
{
|
||||
// nothing else to do here except assign the value of the tuple
|
||||
// into ourselves.
|
||||
Assign(tuple);
|
||||
}
|
||||
};
|
||||
explicit
|
||||
nsTPromiseFlatString_CharT( const substring_tuple_type& tuple )
|
||||
: string_type()
|
||||
{
|
||||
// nothing else to do here except assign the value of the tuple
|
||||
// into ourselves.
|
||||
Assign(tuple);
|
||||
}
|
||||
};
|
||||
|
||||
// We template this so that the constructor is chosen based on the type of the
|
||||
// parameter. This allows us to reject attempts to promise a flat flat string.
|
||||
template<class T>
|
||||
const nsTPromiseFlatString_CharT
|
||||
TPromiseFlatString_CharT( const T& string )
|
||||
{
|
||||
return nsTPromiseFlatString_CharT(string);
|
||||
}
|
||||
{
|
||||
return nsTPromiseFlatString_CharT(string);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,78 +1,78 @@
|
||||
//* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
// IWYU pragma: private, include "nsString.h"
|
||||
|
||||
/**
|
||||
* nsTSubstringTuple_CharT
|
||||
*
|
||||
* Represents a tuple of string fragments. Built as a recursive binary tree.
|
||||
* It is used to implement the concatenation of two or more string objects.
|
||||
*
|
||||
* NOTE: This class is a private implementation detail and should never be
|
||||
* referenced outside the string code.
|
||||
*/
|
||||
/**
|
||||
* nsTSubstringTuple_CharT
|
||||
*
|
||||
* Represents a tuple of string fragments. Built as a recursive binary tree.
|
||||
* It is used to implement the concatenation of two or more string objects.
|
||||
*
|
||||
* NOTE: This class is a private implementation detail and should never be
|
||||
* referenced outside the string code.
|
||||
*/
|
||||
class nsTSubstringTuple_CharT
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
typedef CharT char_type;
|
||||
typedef nsCharTraits<char_type> char_traits;
|
||||
typedef CharT char_type;
|
||||
typedef nsCharTraits<char_type> char_traits;
|
||||
|
||||
typedef nsTSubstringTuple_CharT self_type;
|
||||
typedef nsTSubstring_CharT substring_type;
|
||||
typedef nsTSubstring_CharT base_string_type;
|
||||
typedef uint32_t size_type;
|
||||
typedef nsTSubstringTuple_CharT self_type;
|
||||
typedef nsTSubstring_CharT substring_type;
|
||||
typedef nsTSubstring_CharT base_string_type;
|
||||
typedef uint32_t size_type;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
nsTSubstringTuple_CharT(const base_string_type* a, const base_string_type* b)
|
||||
: mHead(nullptr)
|
||||
, mFragA(a)
|
||||
, mFragB(b) {}
|
||||
nsTSubstringTuple_CharT(const base_string_type* a, const base_string_type* b)
|
||||
: mHead(nullptr)
|
||||
, mFragA(a)
|
||||
, mFragB(b) {}
|
||||
|
||||
nsTSubstringTuple_CharT(const self_type& head, const base_string_type* b)
|
||||
: mHead(&head)
|
||||
, mFragA(nullptr) // this fragment is ignored when head != nullptr
|
||||
, mFragB(b) {}
|
||||
nsTSubstringTuple_CharT(const self_type& head, const base_string_type* b)
|
||||
: mHead(&head)
|
||||
, mFragA(nullptr) // this fragment is ignored when head != nullptr
|
||||
, mFragB(b) {}
|
||||
|
||||
/**
|
||||
* computes the aggregate string length
|
||||
*/
|
||||
size_type Length() const;
|
||||
/**
|
||||
* computes the aggregate string length
|
||||
*/
|
||||
size_type Length() const;
|
||||
|
||||
/**
|
||||
* writes the aggregate string to the given buffer. bufLen is assumed
|
||||
* to be equal to or greater than the value returned by the Length()
|
||||
* method. the string written to |buf| is not null-terminated.
|
||||
*/
|
||||
void WriteTo(char_type *buf, uint32_t bufLen) const;
|
||||
/**
|
||||
* writes the aggregate string to the given buffer. bufLen is assumed
|
||||
* to be equal to or greater than the value returned by the Length()
|
||||
* method. the string written to |buf| is not null-terminated.
|
||||
*/
|
||||
void WriteTo(char_type *buf, uint32_t bufLen) const;
|
||||
|
||||
/**
|
||||
* returns true if this tuple is dependent on (i.e., overlapping with)
|
||||
* the given char sequence.
|
||||
*/
|
||||
bool IsDependentOn(const char_type *start, const char_type *end) const;
|
||||
/**
|
||||
* returns true if this tuple is dependent on (i.e., overlapping with)
|
||||
* the given char sequence.
|
||||
*/
|
||||
bool IsDependentOn(const char_type *start, const char_type *end) const;
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
const self_type* mHead;
|
||||
const base_string_type* mFragA;
|
||||
const base_string_type* mFragB;
|
||||
};
|
||||
const self_type* mHead;
|
||||
const base_string_type* mFragA;
|
||||
const base_string_type* mFragB;
|
||||
};
|
||||
|
||||
inline
|
||||
const nsTSubstringTuple_CharT
|
||||
operator+(const nsTSubstringTuple_CharT::base_string_type& a, const nsTSubstringTuple_CharT::base_string_type& b)
|
||||
{
|
||||
return nsTSubstringTuple_CharT(&a, &b);
|
||||
}
|
||||
{
|
||||
return nsTSubstringTuple_CharT(&a, &b);
|
||||
}
|
||||
|
||||
inline
|
||||
const nsTSubstringTuple_CharT
|
||||
operator+(const nsTSubstringTuple_CharT& head, const nsTSubstringTuple_CharT::base_string_type& b)
|
||||
{
|
||||
return nsTSubstringTuple_CharT(head, &b);
|
||||
}
|
||||
{
|
||||
return nsTSubstringTuple_CharT(head, &b);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,5 @@
|
||||
/* vim:set ts=2 sw=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
@ -640,7 +641,7 @@ NS_CStringCopy
|
||||
*/
|
||||
inline NS_HIDDEN_(nsresult)
|
||||
NS_CStringAppendData(nsACString &aStr, const char *aData,
|
||||
uint32_t aDataLength = UINT32_MAX)
|
||||
uint32_t aDataLength = UINT32_MAX)
|
||||
{
|
||||
return NS_CStringSetDataRange(aStr, UINT32_MAX, 0, aData, aDataLength);
|
||||
}
|
||||
@ -665,7 +666,7 @@ NS_CStringAppendData(nsACString &aStr, const char *aData,
|
||||
*/
|
||||
inline NS_HIDDEN_(nsresult)
|
||||
NS_CStringInsertData(nsACString &aStr, uint32_t aOffset, const char *aData,
|
||||
uint32_t aDataLength = UINT32_MAX)
|
||||
uint32_t aDataLength = UINT32_MAX)
|
||||
{
|
||||
return NS_CStringSetDataRange(aStr, aOffset, 0, aData, aDataLength);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
@ -7,12 +7,12 @@
|
||||
#include "nsDependentString.h"
|
||||
#include "nsAlgorithm.h"
|
||||
|
||||
// define nsDependentString
|
||||
// define nsDependentString
|
||||
#include "string-template-def-unichar.h"
|
||||
#include "nsTDependentString.cpp"
|
||||
#include "string-template-undef.h"
|
||||
|
||||
// define nsDependentCString
|
||||
// define nsDependentCString
|
||||
#include "string-template-def-char.h"
|
||||
#include "nsTDependentString.cpp"
|
||||
#include "string-template-undef.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
@ -7,12 +7,12 @@
|
||||
#include "nsDependentSubstring.h"
|
||||
#include "nsAlgorithm.h"
|
||||
|
||||
// define nsDependentSubstring
|
||||
// define nsDependentSubstring
|
||||
#include "string-template-def-unichar.h"
|
||||
#include "nsTDependentSubstring.cpp"
|
||||
#include "string-template-undef.h"
|
||||
|
||||
// define nsDependentCSubstring
|
||||
// define nsDependentCSubstring
|
||||
#include "string-template-def-char.h"
|
||||
#include "nsTDependentSubstring.cpp"
|
||||
#include "string-template-undef.h"
|
||||
|
@ -1,17 +1,17 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
#include "nsPromiseFlatString.h"
|
||||
|
||||
// define nsPromiseFlatString
|
||||
// define nsPromiseFlatString
|
||||
#include "string-template-def-unichar.h"
|
||||
#include "nsTPromiseFlatString.cpp"
|
||||
#include "string-template-undef.h"
|
||||
|
||||
// define nsPromiseFlatCString
|
||||
// define nsPromiseFlatCString
|
||||
#include "string-template-def-char.h"
|
||||
#include "nsTPromiseFlatString.cpp"
|
||||
#include "string-template-undef.h"
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,17 +1,17 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
// define nsString
|
||||
// define nsString
|
||||
#include "string-template-def-unichar.h"
|
||||
#include "nsTString.cpp"
|
||||
#include "string-template-undef.h"
|
||||
|
||||
// define nsCString
|
||||
// define nsCString
|
||||
#include "string-template-def-char.h"
|
||||
#include "nsTString.cpp"
|
||||
#include "string-template-undef.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
@ -9,12 +9,12 @@
|
||||
#include "plstr.h"
|
||||
|
||||
|
||||
// define nsStringComparator
|
||||
// define nsStringComparator
|
||||
#include "string-template-def-unichar.h"
|
||||
#include "nsTStringComparator.cpp"
|
||||
#include "string-template-undef.h"
|
||||
|
||||
// define nsCStringComparator
|
||||
// define nsCStringComparator
|
||||
#include "string-template-def-char.h"
|
||||
#include "nsTStringComparator.cpp"
|
||||
#include "string-template-undef.h"
|
||||
@ -25,13 +25,13 @@ nsCaseInsensitiveCStringComparator::operator()( const char_type* lhs,
|
||||
const char_type* rhs,
|
||||
uint32_t lLength,
|
||||
uint32_t rLength ) const
|
||||
{
|
||||
if (lLength != rLength)
|
||||
return (lLength > rLength) ? 1 : -1;
|
||||
int32_t result=int32_t(PL_strncasecmp(lhs, rhs, lLength));
|
||||
//Egads. PL_strncasecmp is returning *very* negative numbers.
|
||||
//Some folks expect -1,0,1, so let's temper its enthusiasm.
|
||||
if (result<0)
|
||||
result=-1;
|
||||
return result;
|
||||
}
|
||||
{
|
||||
if (lLength != rLength)
|
||||
return (lLength > rLength) ? 1 : -1;
|
||||
int32_t result=int32_t(PL_strncasecmp(lhs, rhs, lLength));
|
||||
//Egads. PL_strncasecmp is returning *very* negative numbers.
|
||||
//Some folks expect -1,0,1, so let's temper its enthusiasm.
|
||||
if (result<0)
|
||||
result=-1;
|
||||
return result;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
@ -51,45 +51,45 @@ char16_t* const nsCharTraits<char16_t>::sEmptyBuffer =
|
||||
|
||||
#ifdef ENABLE_STRING_STATS
|
||||
class nsStringStats
|
||||
{
|
||||
public:
|
||||
nsStringStats()
|
||||
: mAllocCount(0), mReallocCount(0), mFreeCount(0), mShareCount(0) {}
|
||||
|
||||
~nsStringStats()
|
||||
{
|
||||
public:
|
||||
nsStringStats()
|
||||
: mAllocCount(0), mReallocCount(0), mFreeCount(0), mShareCount(0) {}
|
||||
// this is a hack to suppress duplicate string stats printing
|
||||
// in seamonkey as a result of the string code being linked
|
||||
// into seamonkey and libxpcom! :-(
|
||||
if (!mAllocCount && !mAdoptCount)
|
||||
return;
|
||||
|
||||
~nsStringStats()
|
||||
{
|
||||
// this is a hack to suppress duplicate string stats printing
|
||||
// in seamonkey as a result of the string code being linked
|
||||
// into seamonkey and libxpcom! :-(
|
||||
if (!mAllocCount && !mAdoptCount)
|
||||
return;
|
||||
printf("nsStringStats\n");
|
||||
printf(" => mAllocCount: % 10d\n", int(mAllocCount));
|
||||
printf(" => mReallocCount: % 10d\n", int(mReallocCount));
|
||||
printf(" => mFreeCount: % 10d", int(mFreeCount));
|
||||
if (mAllocCount > mFreeCount)
|
||||
printf(" -- LEAKED %d !!!\n", mAllocCount - mFreeCount);
|
||||
else
|
||||
printf("\n");
|
||||
printf(" => mShareCount: % 10d\n", int(mShareCount));
|
||||
printf(" => mAdoptCount: % 10d\n", int(mAdoptCount));
|
||||
printf(" => mAdoptFreeCount: % 10d", int(mAdoptFreeCount));
|
||||
if (mAdoptCount > mAdoptFreeCount)
|
||||
printf(" -- LEAKED %d !!!\n", mAdoptCount - mAdoptFreeCount);
|
||||
else
|
||||
printf("\n");
|
||||
printf(" => Process ID: %" PRIuPTR ", Thread ID: %" PRIuPTR "\n",
|
||||
uintptr_t(getpid()), uintptr_t(pthread_self()));
|
||||
}
|
||||
|
||||
printf("nsStringStats\n");
|
||||
printf(" => mAllocCount: % 10d\n", int(mAllocCount));
|
||||
printf(" => mReallocCount: % 10d\n", int(mReallocCount));
|
||||
printf(" => mFreeCount: % 10d", int(mFreeCount));
|
||||
if (mAllocCount > mFreeCount)
|
||||
printf(" -- LEAKED %d !!!\n", mAllocCount - mFreeCount);
|
||||
else
|
||||
printf("\n");
|
||||
printf(" => mShareCount: % 10d\n", int(mShareCount));
|
||||
printf(" => mAdoptCount: % 10d\n", int(mAdoptCount));
|
||||
printf(" => mAdoptFreeCount: % 10d", int(mAdoptFreeCount));
|
||||
if (mAdoptCount > mAdoptFreeCount)
|
||||
printf(" -- LEAKED %d !!!\n", mAdoptCount - mAdoptFreeCount);
|
||||
else
|
||||
printf("\n");
|
||||
printf(" => Process ID: %" PRIuPTR ", Thread ID: %" PRIuPTR "\n",
|
||||
uintptr_t(getpid()), uintptr_t(pthread_self()));
|
||||
}
|
||||
|
||||
Atomic<int32_t> mAllocCount;
|
||||
Atomic<int32_t> mReallocCount;
|
||||
Atomic<int32_t> mFreeCount;
|
||||
Atomic<int32_t> mShareCount;
|
||||
Atomic<int32_t> mAdoptCount;
|
||||
Atomic<int32_t> mAdoptFreeCount;
|
||||
};
|
||||
Atomic<int32_t> mAllocCount;
|
||||
Atomic<int32_t> mReallocCount;
|
||||
Atomic<int32_t> mFreeCount;
|
||||
Atomic<int32_t> mShareCount;
|
||||
Atomic<int32_t> mAdoptCount;
|
||||
Atomic<int32_t> mAdoptFreeCount;
|
||||
};
|
||||
static nsStringStats gStringStats;
|
||||
#define STRING_STAT_INCREMENT(_s) (gStringStats.m ## _s ## Count)++
|
||||
#else
|
||||
@ -100,234 +100,234 @@ static nsStringStats gStringStats;
|
||||
|
||||
inline void
|
||||
ReleaseData( void* data, uint32_t flags )
|
||||
{
|
||||
if (flags & nsSubstring::F_SHARED)
|
||||
{
|
||||
if (flags & nsSubstring::F_SHARED)
|
||||
{
|
||||
nsStringBuffer::FromData(data)->Release();
|
||||
}
|
||||
else if (flags & nsSubstring::F_OWNED)
|
||||
{
|
||||
nsMemory::Free(data);
|
||||
STRING_STAT_INCREMENT(AdoptFree);
|
||||
#ifdef NS_BUILD_REFCNT_LOGGING
|
||||
// Treat this as destruction of a "StringAdopt" object for leak
|
||||
// tracking purposes.
|
||||
NS_LogDtor(data, "StringAdopt", 1);
|
||||
#endif // NS_BUILD_REFCNT_LOGGING
|
||||
}
|
||||
// otherwise, nothing to do.
|
||||
nsStringBuffer::FromData(data)->Release();
|
||||
}
|
||||
else if (flags & nsSubstring::F_OWNED)
|
||||
{
|
||||
nsMemory::Free(data);
|
||||
STRING_STAT_INCREMENT(AdoptFree);
|
||||
#ifdef NS_BUILD_REFCNT_LOGGING
|
||||
// Treat this as destruction of a "StringAdopt" object for leak
|
||||
// tracking purposes.
|
||||
NS_LogDtor(data, "StringAdopt", 1);
|
||||
#endif // NS_BUILD_REFCNT_LOGGING
|
||||
}
|
||||
// otherwise, nothing to do.
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// XXX or we could make nsStringBuffer be a friend of nsTAString
|
||||
|
||||
class nsAStringAccessor : public nsAString
|
||||
{
|
||||
private:
|
||||
nsAStringAccessor(); // NOT IMPLEMENTED
|
||||
|
||||
public:
|
||||
char_type *data() const { return mData; }
|
||||
size_type length() const { return mLength; }
|
||||
uint32_t flags() const { return mFlags; }
|
||||
|
||||
void set(char_type *data, size_type len, uint32_t flags)
|
||||
{
|
||||
private:
|
||||
nsAStringAccessor(); // NOT IMPLEMENTED
|
||||
|
||||
public:
|
||||
char_type *data() const { return mData; }
|
||||
size_type length() const { return mLength; }
|
||||
uint32_t flags() const { return mFlags; }
|
||||
|
||||
void set(char_type *data, size_type len, uint32_t flags)
|
||||
{
|
||||
ReleaseData(mData, mFlags);
|
||||
mData = data;
|
||||
mLength = len;
|
||||
mFlags = flags;
|
||||
}
|
||||
};
|
||||
ReleaseData(mData, mFlags);
|
||||
mData = data;
|
||||
mLength = len;
|
||||
mFlags = flags;
|
||||
}
|
||||
};
|
||||
|
||||
class nsACStringAccessor : public nsACString
|
||||
{
|
||||
private:
|
||||
nsACStringAccessor(); // NOT IMPLEMENTED
|
||||
|
||||
public:
|
||||
char_type *data() const { return mData; }
|
||||
size_type length() const { return mLength; }
|
||||
uint32_t flags() const { return mFlags; }
|
||||
|
||||
void set(char_type *data, size_type len, uint32_t flags)
|
||||
{
|
||||
private:
|
||||
nsACStringAccessor(); // NOT IMPLEMENTED
|
||||
|
||||
public:
|
||||
char_type *data() const { return mData; }
|
||||
size_type length() const { return mLength; }
|
||||
uint32_t flags() const { return mFlags; }
|
||||
|
||||
void set(char_type *data, size_type len, uint32_t flags)
|
||||
{
|
||||
ReleaseData(mData, mFlags);
|
||||
mData = data;
|
||||
mLength = len;
|
||||
mFlags = flags;
|
||||
}
|
||||
};
|
||||
ReleaseData(mData, mFlags);
|
||||
mData = data;
|
||||
mLength = len;
|
||||
mFlags = flags;
|
||||
}
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
nsStringBuffer::AddRef()
|
||||
{
|
||||
++mRefCount;
|
||||
STRING_STAT_INCREMENT(Share);
|
||||
NS_LOG_ADDREF(this, mRefCount, "nsStringBuffer", sizeof(*this));
|
||||
}
|
||||
{
|
||||
++mRefCount;
|
||||
STRING_STAT_INCREMENT(Share);
|
||||
NS_LOG_ADDREF(this, mRefCount, "nsStringBuffer", sizeof(*this));
|
||||
}
|
||||
|
||||
void
|
||||
nsStringBuffer::Release()
|
||||
{
|
||||
int32_t count = --mRefCount;
|
||||
NS_LOG_RELEASE(this, count, "nsStringBuffer");
|
||||
if (count == 0)
|
||||
{
|
||||
int32_t count = --mRefCount;
|
||||
NS_LOG_RELEASE(this, count, "nsStringBuffer");
|
||||
if (count == 0)
|
||||
{
|
||||
STRING_STAT_INCREMENT(Free);
|
||||
free(this); // we were allocated with |malloc|
|
||||
}
|
||||
STRING_STAT_INCREMENT(Free);
|
||||
free(this); // we were allocated with |malloc|
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alloc returns a pointer to a new string header with set capacity.
|
||||
*/
|
||||
/**
|
||||
* Alloc returns a pointer to a new string header with set capacity.
|
||||
*/
|
||||
already_AddRefed<nsStringBuffer>
|
||||
nsStringBuffer::Alloc(size_t size)
|
||||
{
|
||||
NS_ASSERTION(size != 0, "zero capacity allocation not allowed");
|
||||
NS_ASSERTION(sizeof(nsStringBuffer) + size <= size_t(uint32_t(-1)) &&
|
||||
sizeof(nsStringBuffer) + size > size,
|
||||
"mStorageSize will truncate");
|
||||
|
||||
nsStringBuffer *hdr =
|
||||
(nsStringBuffer *) malloc(sizeof(nsStringBuffer) + size);
|
||||
if (hdr)
|
||||
{
|
||||
NS_ASSERTION(size != 0, "zero capacity allocation not allowed");
|
||||
NS_ASSERTION(sizeof(nsStringBuffer) + size <= size_t(uint32_t(-1)) &&
|
||||
sizeof(nsStringBuffer) + size > size,
|
||||
"mStorageSize will truncate");
|
||||
STRING_STAT_INCREMENT(Alloc);
|
||||
|
||||
nsStringBuffer *hdr =
|
||||
(nsStringBuffer *) malloc(sizeof(nsStringBuffer) + size);
|
||||
if (hdr)
|
||||
{
|
||||
STRING_STAT_INCREMENT(Alloc);
|
||||
|
||||
hdr->mRefCount = 1;
|
||||
hdr->mStorageSize = size;
|
||||
NS_LOG_ADDREF(hdr, 1, "nsStringBuffer", sizeof(*hdr));
|
||||
}
|
||||
return dont_AddRef(hdr);
|
||||
hdr->mRefCount = 1;
|
||||
hdr->mStorageSize = size;
|
||||
NS_LOG_ADDREF(hdr, 1, "nsStringBuffer", sizeof(*hdr));
|
||||
}
|
||||
return dont_AddRef(hdr);
|
||||
}
|
||||
|
||||
nsStringBuffer*
|
||||
nsStringBuffer::Realloc(nsStringBuffer* hdr, size_t size)
|
||||
{
|
||||
STRING_STAT_INCREMENT(Realloc);
|
||||
{
|
||||
STRING_STAT_INCREMENT(Realloc);
|
||||
|
||||
NS_ASSERTION(size != 0, "zero capacity allocation not allowed");
|
||||
NS_ASSERTION(sizeof(nsStringBuffer) + size <= size_t(uint32_t(-1)) &&
|
||||
sizeof(nsStringBuffer) + size > size,
|
||||
"mStorageSize will truncate");
|
||||
NS_ASSERTION(size != 0, "zero capacity allocation not allowed");
|
||||
NS_ASSERTION(sizeof(nsStringBuffer) + size <= size_t(uint32_t(-1)) &&
|
||||
sizeof(nsStringBuffer) + size > size,
|
||||
"mStorageSize will truncate");
|
||||
|
||||
// no point in trying to save ourselves if we hit this assertion
|
||||
NS_ASSERTION(!hdr->IsReadonly(), "|Realloc| attempted on readonly string");
|
||||
// no point in trying to save ourselves if we hit this assertion
|
||||
NS_ASSERTION(!hdr->IsReadonly(), "|Realloc| attempted on readonly string");
|
||||
|
||||
// Treat this as a release and addref for refcounting purposes, since we
|
||||
// just asserted that the refcount is 1. If we don't do that, refcount
|
||||
// logging will claim we've leaked all sorts of stuff.
|
||||
NS_LOG_RELEASE(hdr, 0, "nsStringBuffer");
|
||||
|
||||
hdr = (nsStringBuffer*) realloc(hdr, sizeof(nsStringBuffer) + size);
|
||||
if (hdr) {
|
||||
NS_LOG_ADDREF(hdr, 1, "nsStringBuffer", sizeof(*hdr));
|
||||
hdr->mStorageSize = size;
|
||||
}
|
||||
// Treat this as a release and addref for refcounting purposes, since we
|
||||
// just asserted that the refcount is 1. If we don't do that, refcount
|
||||
// logging will claim we've leaked all sorts of stuff.
|
||||
NS_LOG_RELEASE(hdr, 0, "nsStringBuffer");
|
||||
|
||||
return hdr;
|
||||
hdr = (nsStringBuffer*) realloc(hdr, sizeof(nsStringBuffer) + size);
|
||||
if (hdr) {
|
||||
NS_LOG_ADDREF(hdr, 1, "nsStringBuffer", sizeof(*hdr));
|
||||
hdr->mStorageSize = size;
|
||||
}
|
||||
|
||||
return hdr;
|
||||
}
|
||||
|
||||
nsStringBuffer*
|
||||
nsStringBuffer::FromString(const nsAString& str)
|
||||
{
|
||||
const nsAStringAccessor* accessor =
|
||||
static_cast<const nsAStringAccessor*>(&str);
|
||||
{
|
||||
const nsAStringAccessor* accessor =
|
||||
static_cast<const nsAStringAccessor*>(&str);
|
||||
|
||||
if (!(accessor->flags() & nsSubstring::F_SHARED))
|
||||
return nullptr;
|
||||
if (!(accessor->flags() & nsSubstring::F_SHARED))
|
||||
return nullptr;
|
||||
|
||||
return FromData(accessor->data());
|
||||
}
|
||||
return FromData(accessor->data());
|
||||
}
|
||||
|
||||
nsStringBuffer*
|
||||
nsStringBuffer::FromString(const nsACString& str)
|
||||
{
|
||||
const nsACStringAccessor* accessor =
|
||||
static_cast<const nsACStringAccessor*>(&str);
|
||||
{
|
||||
const nsACStringAccessor* accessor =
|
||||
static_cast<const nsACStringAccessor*>(&str);
|
||||
|
||||
if (!(accessor->flags() & nsCSubstring::F_SHARED))
|
||||
return nullptr;
|
||||
if (!(accessor->flags() & nsCSubstring::F_SHARED))
|
||||
return nullptr;
|
||||
|
||||
return FromData(accessor->data());
|
||||
}
|
||||
return FromData(accessor->data());
|
||||
}
|
||||
|
||||
void
|
||||
nsStringBuffer::ToString(uint32_t len, nsAString &str,
|
||||
bool aMoveOwnership)
|
||||
{
|
||||
char16_t* data = static_cast<char16_t*>(Data());
|
||||
{
|
||||
char16_t* data = static_cast<char16_t*>(Data());
|
||||
|
||||
nsAStringAccessor* accessor = static_cast<nsAStringAccessor*>(&str);
|
||||
NS_ASSERTION(data[len] == char16_t(0), "data should be null terminated");
|
||||
nsAStringAccessor* accessor = static_cast<nsAStringAccessor*>(&str);
|
||||
NS_ASSERTION(data[len] == char16_t(0), "data should be null terminated");
|
||||
|
||||
// preserve class flags
|
||||
uint32_t flags = accessor->flags();
|
||||
flags = (flags & 0xFFFF0000) | nsSubstring::F_SHARED | nsSubstring::F_TERMINATED;
|
||||
// preserve class flags
|
||||
uint32_t flags = accessor->flags();
|
||||
flags = (flags & 0xFFFF0000) | nsSubstring::F_SHARED | nsSubstring::F_TERMINATED;
|
||||
|
||||
if (!aMoveOwnership) {
|
||||
AddRef();
|
||||
}
|
||||
accessor->set(data, len, flags);
|
||||
if (!aMoveOwnership) {
|
||||
AddRef();
|
||||
}
|
||||
accessor->set(data, len, flags);
|
||||
}
|
||||
|
||||
void
|
||||
nsStringBuffer::ToString(uint32_t len, nsACString &str,
|
||||
bool aMoveOwnership)
|
||||
{
|
||||
char* data = static_cast<char*>(Data());
|
||||
{
|
||||
char* data = static_cast<char*>(Data());
|
||||
|
||||
nsACStringAccessor* accessor = static_cast<nsACStringAccessor*>(&str);
|
||||
NS_ASSERTION(data[len] == char(0), "data should be null terminated");
|
||||
nsACStringAccessor* accessor = static_cast<nsACStringAccessor*>(&str);
|
||||
NS_ASSERTION(data[len] == char(0), "data should be null terminated");
|
||||
|
||||
// preserve class flags
|
||||
uint32_t flags = accessor->flags();
|
||||
flags = (flags & 0xFFFF0000) | nsCSubstring::F_SHARED | nsCSubstring::F_TERMINATED;
|
||||
// preserve class flags
|
||||
uint32_t flags = accessor->flags();
|
||||
flags = (flags & 0xFFFF0000) | nsCSubstring::F_SHARED | nsCSubstring::F_TERMINATED;
|
||||
|
||||
if (!aMoveOwnership) {
|
||||
AddRef();
|
||||
}
|
||||
accessor->set(data, len, flags);
|
||||
if (!aMoveOwnership) {
|
||||
AddRef();
|
||||
}
|
||||
accessor->set(data, len, flags);
|
||||
}
|
||||
|
||||
size_t
|
||||
nsStringBuffer::SizeOfIncludingThisMustBeUnshared(mozilla::MallocSizeOf aMallocSizeOf) const
|
||||
{
|
||||
NS_ASSERTION(!IsReadonly(),
|
||||
"shared StringBuffer in SizeOfIncludingThisMustBeUnshared");
|
||||
return aMallocSizeOf(this);
|
||||
}
|
||||
{
|
||||
NS_ASSERTION(!IsReadonly(),
|
||||
"shared StringBuffer in SizeOfIncludingThisMustBeUnshared");
|
||||
return aMallocSizeOf(this);
|
||||
}
|
||||
|
||||
size_t
|
||||
nsStringBuffer::SizeOfIncludingThisIfUnshared(mozilla::MallocSizeOf aMallocSizeOf) const
|
||||
{
|
||||
if (!IsReadonly())
|
||||
{
|
||||
if (!IsReadonly())
|
||||
{
|
||||
return SizeOfIncludingThisMustBeUnshared(aMallocSizeOf);
|
||||
}
|
||||
return 0;
|
||||
return SizeOfIncludingThisMustBeUnshared(aMallocSizeOf);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t
|
||||
nsStringBuffer::SizeOfIncludingThisEvenIfShared(mozilla::MallocSizeOf aMallocSizeOf) const
|
||||
{
|
||||
return aMallocSizeOf(this);
|
||||
}
|
||||
{
|
||||
return aMallocSizeOf(this);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
// define nsSubstring
|
||||
// define nsSubstring
|
||||
#include "string-template-def-unichar.h"
|
||||
#include "nsTSubstring.cpp"
|
||||
#include "string-template-undef.h"
|
||||
|
||||
// define nsCSubstring
|
||||
// define nsCSubstring
|
||||
#include "string-template-def-char.h"
|
||||
#include "nsTSubstring.cpp"
|
||||
#include "string-template-undef.h"
|
||||
|
@ -1,20 +1,20 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
#include "nsSubstringTuple.h"
|
||||
|
||||
// convert fragment to |const substring_type&|
|
||||
// convert fragment to |const substring_type&|
|
||||
#define TO_SUBSTRING(_v) (*(_v))
|
||||
|
||||
// define nsSubstringTuple
|
||||
// define nsSubstringTuple
|
||||
#include "string-template-def-unichar.h"
|
||||
#include "nsTSubstringTuple.cpp"
|
||||
#include "string-template-undef.h"
|
||||
|
||||
// define nsCSubstringTuple
|
||||
// define nsCSubstringTuple
|
||||
#include "string-template-def-char.h"
|
||||
#include "nsTSubstringTuple.cpp"
|
||||
#include "string-template-undef.h"
|
||||
|
@ -1,24 +1,24 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
void
|
||||
nsTDependentString_CharT::Rebind( const string_type& str, uint32_t startPos )
|
||||
{
|
||||
NS_ABORT_IF_FALSE(str.Flags() & F_TERMINATED, "Unterminated flat string");
|
||||
{
|
||||
NS_ABORT_IF_FALSE(str.Flags() & F_TERMINATED, "Unterminated flat string");
|
||||
|
||||
// If we currently own a buffer, release it.
|
||||
Finalize();
|
||||
// If we currently own a buffer, release it.
|
||||
Finalize();
|
||||
|
||||
size_type strLength = str.Length();
|
||||
size_type strLength = str.Length();
|
||||
|
||||
if (startPos > strLength)
|
||||
startPos = strLength;
|
||||
if (startPos > strLength)
|
||||
startPos = strLength;
|
||||
|
||||
mData = const_cast<char_type*>(static_cast<const char_type*>(str.Data())) + startPos;
|
||||
mLength = strLength - startPos;
|
||||
mData = const_cast<char_type*>(static_cast<const char_type*>(str.Data())) + startPos;
|
||||
mLength = strLength - startPos;
|
||||
|
||||
SetDataFlags(str.Flags() & (F_TERMINATED | F_LITERAL));
|
||||
}
|
||||
SetDataFlags(str.Flags() & (F_TERMINATED | F_LITERAL));
|
||||
}
|
||||
|
@ -1,35 +1,35 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
void
|
||||
nsTDependentSubstring_CharT::Rebind( const substring_type& str, uint32_t startPos, uint32_t length )
|
||||
{
|
||||
// If we currently own a buffer, release it.
|
||||
Finalize();
|
||||
{
|
||||
// If we currently own a buffer, release it.
|
||||
Finalize();
|
||||
|
||||
size_type strLength = str.Length();
|
||||
size_type strLength = str.Length();
|
||||
|
||||
if (startPos > strLength)
|
||||
startPos = strLength;
|
||||
if (startPos > strLength)
|
||||
startPos = strLength;
|
||||
|
||||
mData = const_cast<char_type*>(static_cast<const char_type*>(str.Data())) + startPos;
|
||||
mLength = XPCOM_MIN(length, strLength - startPos);
|
||||
mData = const_cast<char_type*>(static_cast<const char_type*>(str.Data())) + startPos;
|
||||
mLength = XPCOM_MIN(length, strLength - startPos);
|
||||
|
||||
SetDataFlags(F_NONE);
|
||||
}
|
||||
SetDataFlags(F_NONE);
|
||||
}
|
||||
|
||||
void
|
||||
nsTDependentSubstring_CharT::Rebind( const char_type* data, size_type length )
|
||||
{
|
||||
NS_ASSERTION(data, "nsTDependentSubstring must wrap a non-NULL buffer");
|
||||
{
|
||||
NS_ASSERTION(data, "nsTDependentSubstring must wrap a non-NULL buffer");
|
||||
|
||||
// If we currently own a buffer, release it.
|
||||
Finalize();
|
||||
// If we currently own a buffer, release it.
|
||||
Finalize();
|
||||
|
||||
mData = const_cast<char_type*>(static_cast<const char_type*>(data));
|
||||
mLength = length;
|
||||
SetDataFlags(F_NONE);
|
||||
}
|
||||
mData = const_cast<char_type*>(static_cast<const char_type*>(data));
|
||||
mLength = length;
|
||||
SetDataFlags(F_NONE);
|
||||
}
|
||||
|
@ -1,21 +1,21 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
void
|
||||
nsTPromiseFlatString_CharT::Init(const substring_type& str)
|
||||
{
|
||||
if (str.IsTerminated())
|
||||
{
|
||||
if (str.IsTerminated())
|
||||
{
|
||||
mData = const_cast<char_type*>(static_cast<const char_type*>(str.Data()));
|
||||
mLength = str.Length();
|
||||
mFlags = str.mFlags & (F_TERMINATED | F_LITERAL);
|
||||
// does not promote F_VOIDED
|
||||
}
|
||||
else
|
||||
{
|
||||
Assign(str);
|
||||
}
|
||||
mData = const_cast<char_type*>(static_cast<const char_type*>(str.Data()));
|
||||
mLength = str.Length();
|
||||
mFlags = str.mFlags & (F_TERMINATED | F_LITERAL);
|
||||
// does not promote F_VOIDED
|
||||
}
|
||||
else
|
||||
{
|
||||
Assign(str);
|
||||
}
|
||||
}
|
||||
|
@ -1,50 +1,50 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
nsTAdoptingString_CharT&
|
||||
nsTAdoptingString_CharT::operator=( const self_type& str )
|
||||
{
|
||||
// This'll violate the constness of this argument, that's just
|
||||
// the nature of this class...
|
||||
self_type* mutable_str = const_cast<self_type*>(&str);
|
||||
|
||||
if (str.mFlags & F_OWNED)
|
||||
{
|
||||
// This'll violate the constness of this argument, that's just
|
||||
// the nature of this class...
|
||||
self_type* mutable_str = const_cast<self_type*>(&str);
|
||||
// We want to do what Adopt() does, but without actually incrementing
|
||||
// the Adopt count. Note that we can be a little more straightforward
|
||||
// about this than Adopt() is, because we know that str.mData is
|
||||
// non-null. Should we be able to assert that str is not void here?
|
||||
NS_ASSERTION(str.mData, "String with null mData?");
|
||||
Finalize();
|
||||
mData = str.mData;
|
||||
mLength = str.mLength;
|
||||
SetDataFlags(F_TERMINATED | F_OWNED);
|
||||
|
||||
if (str.mFlags & F_OWNED)
|
||||
{
|
||||
// We want to do what Adopt() does, but without actually incrementing
|
||||
// the Adopt count. Note that we can be a little more straightforward
|
||||
// about this than Adopt() is, because we know that str.mData is
|
||||
// non-null. Should we be able to assert that str is not void here?
|
||||
NS_ASSERTION(str.mData, "String with null mData?");
|
||||
Finalize();
|
||||
mData = str.mData;
|
||||
mLength = str.mLength;
|
||||
SetDataFlags(F_TERMINATED | F_OWNED);
|
||||
|
||||
// Make str forget the buffer we just took ownership of.
|
||||
new (mutable_str) self_type();
|
||||
}
|
||||
else
|
||||
{
|
||||
Assign(str);
|
||||
|
||||
mutable_str->Truncate();
|
||||
}
|
||||
|
||||
return *this;
|
||||
// Make str forget the buffer we just took ownership of.
|
||||
new (mutable_str) self_type();
|
||||
}
|
||||
else
|
||||
{
|
||||
Assign(str);
|
||||
|
||||
mutable_str->Truncate();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
nsTString_CharT::Rebind( const char_type* data, size_type length )
|
||||
{
|
||||
// If we currently own a buffer, release it.
|
||||
Finalize();
|
||||
{
|
||||
// If we currently own a buffer, release it.
|
||||
Finalize();
|
||||
|
||||
mData = const_cast<char_type*>(data);
|
||||
mLength = length;
|
||||
SetDataFlags(F_TERMINATED);
|
||||
AssertValidDepedentString();
|
||||
}
|
||||
mData = const_cast<char_type*>(data);
|
||||
mLength = length;
|
||||
SetDataFlags(F_TERMINATED);
|
||||
AssertValidDepedentString();
|
||||
}
|
||||
|
||||
|
@ -1,42 +1,42 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
int NS_FASTCALL
|
||||
Compare( const nsTSubstring_CharT::base_string_type& lhs, const nsTSubstring_CharT::base_string_type& rhs, const nsTStringComparator_CharT& comp )
|
||||
{
|
||||
typedef nsTSubstring_CharT::size_type size_type;
|
||||
|
||||
if ( &lhs == &rhs )
|
||||
return 0;
|
||||
|
||||
nsTSubstring_CharT::const_iterator leftIter, rightIter;
|
||||
lhs.BeginReading(leftIter);
|
||||
rhs.BeginReading(rightIter);
|
||||
|
||||
size_type lLength = leftIter.size_forward();
|
||||
size_type rLength = rightIter.size_forward();
|
||||
size_type lengthToCompare = XPCOM_MIN(lLength, rLength);
|
||||
|
||||
int result;
|
||||
if ( (result = comp(leftIter.get(), rightIter.get(), lengthToCompare, lengthToCompare)) == 0 )
|
||||
{
|
||||
typedef nsTSubstring_CharT::size_type size_type;
|
||||
|
||||
if ( &lhs == &rhs )
|
||||
return 0;
|
||||
|
||||
nsTSubstring_CharT::const_iterator leftIter, rightIter;
|
||||
lhs.BeginReading(leftIter);
|
||||
rhs.BeginReading(rightIter);
|
||||
|
||||
size_type lLength = leftIter.size_forward();
|
||||
size_type rLength = rightIter.size_forward();
|
||||
size_type lengthToCompare = XPCOM_MIN(lLength, rLength);
|
||||
|
||||
int result;
|
||||
if ( (result = comp(leftIter.get(), rightIter.get(), lengthToCompare, lengthToCompare)) == 0 )
|
||||
{
|
||||
if ( lLength < rLength )
|
||||
result = -1;
|
||||
else if ( rLength < lLength )
|
||||
result = 1;
|
||||
else
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
if ( lLength < rLength )
|
||||
result = -1;
|
||||
else if ( rLength < lLength )
|
||||
result = 1;
|
||||
else
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
nsTDefaultStringComparator_CharT::operator()( const char_type* lhs, const char_type* rhs, uint32_t lLength, uint32_t rLength) const
|
||||
{
|
||||
return (lLength == rLength) ? nsCharTraits<CharT>::compare(lhs, rhs, lLength) :
|
||||
(lLength > rLength) ? 1 : -1;
|
||||
}
|
||||
{
|
||||
return (lLength == rLength) ? nsCharTraits<CharT>::compare(lhs, rhs, lLength) :
|
||||
(lLength > rLength) ? 1 : -1;
|
||||
}
|
||||
|
@ -1,113 +1,113 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* nsTString::Find
|
||||
*
|
||||
* aOffset specifies starting index
|
||||
* aCount specifies number of string compares (iterations)
|
||||
*/
|
||||
/**
|
||||
* nsTString::Find
|
||||
*
|
||||
* aOffset specifies starting index
|
||||
* aCount specifies number of string compares (iterations)
|
||||
*/
|
||||
|
||||
int32_t
|
||||
nsTString_CharT::Find( const nsCString& aString, bool aIgnoreCase, int32_t aOffset, int32_t aCount) const
|
||||
{
|
||||
// this method changes the meaning of aOffset and aCount:
|
||||
Find_ComputeSearchRange(mLength, aString.Length(), aOffset, aCount);
|
||||
{
|
||||
// this method changes the meaning of aOffset and aCount:
|
||||
Find_ComputeSearchRange(mLength, aString.Length(), aOffset, aCount);
|
||||
|
||||
int32_t result = FindSubstring(mData + aOffset, aCount, aString.get(), aString.Length(), aIgnoreCase);
|
||||
if (result != kNotFound)
|
||||
result += aOffset;
|
||||
return result;
|
||||
}
|
||||
int32_t result = FindSubstring(mData + aOffset, aCount, aString.get(), aString.Length(), aIgnoreCase);
|
||||
if (result != kNotFound)
|
||||
result += aOffset;
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t
|
||||
nsTString_CharT::Find( const char* aString, bool aIgnoreCase, int32_t aOffset, int32_t aCount) const
|
||||
{
|
||||
return Find(nsDependentCString(aString), aIgnoreCase, aOffset, aCount);
|
||||
}
|
||||
{
|
||||
return Find(nsDependentCString(aString), aIgnoreCase, aOffset, aCount);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* nsTString::RFind
|
||||
*
|
||||
* aOffset specifies starting index
|
||||
* aCount specifies number of string compares (iterations)
|
||||
*/
|
||||
/**
|
||||
* nsTString::RFind
|
||||
*
|
||||
* aOffset specifies starting index
|
||||
* aCount specifies number of string compares (iterations)
|
||||
*/
|
||||
|
||||
int32_t
|
||||
nsTString_CharT::RFind( const nsCString& aString, bool aIgnoreCase, int32_t aOffset, int32_t aCount) const
|
||||
{
|
||||
// this method changes the meaning of aOffset and aCount:
|
||||
RFind_ComputeSearchRange(mLength, aString.Length(), aOffset, aCount);
|
||||
{
|
||||
// this method changes the meaning of aOffset and aCount:
|
||||
RFind_ComputeSearchRange(mLength, aString.Length(), aOffset, aCount);
|
||||
|
||||
int32_t result = RFindSubstring(mData + aOffset, aCount, aString.get(), aString.Length(), aIgnoreCase);
|
||||
if (result != kNotFound)
|
||||
result += aOffset;
|
||||
return result;
|
||||
}
|
||||
int32_t result = RFindSubstring(mData + aOffset, aCount, aString.get(), aString.Length(), aIgnoreCase);
|
||||
if (result != kNotFound)
|
||||
result += aOffset;
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t
|
||||
nsTString_CharT::RFind( const char* aString, bool aIgnoreCase, int32_t aOffset, int32_t aCount) const
|
||||
{
|
||||
return RFind(nsDependentCString(aString), aIgnoreCase, aOffset, aCount);
|
||||
}
|
||||
{
|
||||
return RFind(nsDependentCString(aString), aIgnoreCase, aOffset, aCount);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* nsTString::RFindChar
|
||||
*/
|
||||
/**
|
||||
* nsTString::RFindChar
|
||||
*/
|
||||
|
||||
int32_t
|
||||
nsTString_CharT::RFindChar( char16_t aChar, int32_t aOffset, int32_t aCount) const
|
||||
{
|
||||
return nsBufferRoutines<CharT>::rfind_char(mData, mLength, aOffset, aChar, aCount);
|
||||
}
|
||||
{
|
||||
return nsBufferRoutines<CharT>::rfind_char(mData, mLength, aOffset, aChar, aCount);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* nsTString::FindCharInSet
|
||||
*/
|
||||
/**
|
||||
* nsTString::FindCharInSet
|
||||
*/
|
||||
|
||||
int32_t
|
||||
nsTString_CharT::FindCharInSet( const char* aSet, int32_t aOffset ) const
|
||||
{
|
||||
if (aOffset < 0)
|
||||
aOffset = 0;
|
||||
else if (aOffset >= int32_t(mLength))
|
||||
return kNotFound;
|
||||
|
||||
int32_t result = ::FindCharInSet(mData + aOffset, mLength - aOffset, aSet);
|
||||
if (result != kNotFound)
|
||||
result += aOffset;
|
||||
return result;
|
||||
}
|
||||
{
|
||||
if (aOffset < 0)
|
||||
aOffset = 0;
|
||||
else if (aOffset >= int32_t(mLength))
|
||||
return kNotFound;
|
||||
|
||||
int32_t result = ::FindCharInSet(mData + aOffset, mLength - aOffset, aSet);
|
||||
if (result != kNotFound)
|
||||
result += aOffset;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* nsTString::RFindCharInSet
|
||||
*/
|
||||
/**
|
||||
* nsTString::RFindCharInSet
|
||||
*/
|
||||
|
||||
int32_t
|
||||
nsTString_CharT::RFindCharInSet( const CharT* aSet, int32_t aOffset ) const
|
||||
{
|
||||
// We want to pass a "data length" to ::RFindCharInSet
|
||||
if (aOffset < 0 || aOffset > int32_t(mLength))
|
||||
aOffset = mLength;
|
||||
else
|
||||
++aOffset;
|
||||
{
|
||||
// We want to pass a "data length" to ::RFindCharInSet
|
||||
if (aOffset < 0 || aOffset > int32_t(mLength))
|
||||
aOffset = mLength;
|
||||
else
|
||||
++aOffset;
|
||||
|
||||
return ::RFindCharInSet(mData, aOffset, aSet);
|
||||
}
|
||||
return ::RFindCharInSet(mData, aOffset, aSet);
|
||||
}
|
||||
|
||||
|
||||
// it's a shame to replicate this code. it was done this way in the past
|
||||
// to help performance. this function also gets to keep the rickg style
|
||||
// indentation :-/
|
||||
// it's a shame to replicate this code. it was done this way in the past
|
||||
// to help performance. this function also gets to keep the rickg style
|
||||
// indentation :-/
|
||||
int32_t
|
||||
nsTString_CharT::ToInteger( nsresult* aErrorCode, uint32_t aRadix ) const
|
||||
{
|
||||
@ -117,16 +117,16 @@ nsTString_CharT::ToInteger( nsresult* aErrorCode, uint32_t aRadix ) const
|
||||
bool negate=false;
|
||||
CharT theChar=0;
|
||||
|
||||
//initial value, override if we find an integer
|
||||
//initial value, override if we find an integer
|
||||
*aErrorCode=NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
|
||||
if(cp) {
|
||||
|
||||
|
||||
//begin by skipping over leading chars that shouldn't be part of the number...
|
||||
|
||||
|
||||
CharT* endcp=cp+mLength;
|
||||
bool done=false;
|
||||
|
||||
|
||||
while((cp<endcp) && (!done)){
|
||||
switch(*cp++) {
|
||||
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
||||
@ -134,16 +134,16 @@ nsTString_CharT::ToInteger( nsresult* aErrorCode, uint32_t aRadix ) const
|
||||
theRadix=16;
|
||||
done=true;
|
||||
break;
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
done=true;
|
||||
break;
|
||||
case '-':
|
||||
case '-':
|
||||
negate=true; //fall through...
|
||||
break;
|
||||
case 'X': case 'x':
|
||||
case 'X': case 'x':
|
||||
theRadix=16;
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
} //switch
|
||||
@ -151,12 +151,12 @@ nsTString_CharT::ToInteger( nsresult* aErrorCode, uint32_t aRadix ) const
|
||||
|
||||
if (done) {
|
||||
|
||||
//integer found
|
||||
//integer found
|
||||
*aErrorCode = NS_OK;
|
||||
|
||||
if (aRadix!=kAutoDetect) theRadix = aRadix; // override
|
||||
|
||||
//now iterate the numeric chars and build our result
|
||||
//now iterate the numeric chars and build our result
|
||||
CharT* first=--cp; //in case we have to back up.
|
||||
bool haveValue = false;
|
||||
|
||||
@ -232,9 +232,9 @@ nsTString_CharT::ToInteger( nsresult* aErrorCode, uint32_t aRadix ) const
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* nsTString::ToInteger64
|
||||
*/
|
||||
/**
|
||||
* nsTString::ToInteger64
|
||||
*/
|
||||
int64_t
|
||||
nsTString_CharT::ToInteger64( nsresult* aErrorCode, uint32_t aRadix ) const
|
||||
{
|
||||
@ -244,16 +244,16 @@ nsTString_CharT::ToInteger64( nsresult* aErrorCode, uint32_t aRadix ) const
|
||||
bool negate=false;
|
||||
CharT theChar=0;
|
||||
|
||||
//initial value, override if we find an integer
|
||||
//initial value, override if we find an integer
|
||||
*aErrorCode=NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
|
||||
if(cp) {
|
||||
|
||||
|
||||
//begin by skipping over leading chars that shouldn't be part of the number...
|
||||
|
||||
|
||||
CharT* endcp=cp+mLength;
|
||||
bool done=false;
|
||||
|
||||
|
||||
while((cp<endcp) && (!done)){
|
||||
switch(*cp++) {
|
||||
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
||||
@ -278,12 +278,12 @@ nsTString_CharT::ToInteger64( nsresult* aErrorCode, uint32_t aRadix ) const
|
||||
|
||||
if (done) {
|
||||
|
||||
//integer found
|
||||
//integer found
|
||||
*aErrorCode = NS_OK;
|
||||
|
||||
if (aRadix!=kAutoDetect) theRadix = aRadix; // override
|
||||
|
||||
//now iterate the numeric chars and build our result
|
||||
//now iterate the numeric chars and build our result
|
||||
CharT* first=--cp; //in case we have to back up.
|
||||
bool haveValue = false;
|
||||
|
||||
@ -365,220 +365,220 @@ nsTString_CharT::ToInteger64( nsresult* aErrorCode, uint32_t aRadix ) const
|
||||
|
||||
uint32_t
|
||||
nsTString_CharT::Mid( self_type& aResult, index_type aStartPos, size_type aLengthToCopy ) const
|
||||
{
|
||||
if (aStartPos == 0 && aLengthToCopy >= mLength)
|
||||
aResult = *this;
|
||||
else
|
||||
aResult = Substring(*this, aStartPos, aLengthToCopy);
|
||||
{
|
||||
if (aStartPos == 0 && aLengthToCopy >= mLength)
|
||||
aResult = *this;
|
||||
else
|
||||
aResult = Substring(*this, aStartPos, aLengthToCopy);
|
||||
|
||||
return aResult.mLength;
|
||||
}
|
||||
return aResult.mLength;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* nsTString::SetCharAt
|
||||
*/
|
||||
/**
|
||||
* nsTString::SetCharAt
|
||||
*/
|
||||
|
||||
bool
|
||||
nsTString_CharT::SetCharAt( char16_t aChar, uint32_t aIndex )
|
||||
{
|
||||
if (aIndex >= mLength)
|
||||
return false;
|
||||
{
|
||||
if (aIndex >= mLength)
|
||||
return false;
|
||||
|
||||
if (!EnsureMutable())
|
||||
NS_ABORT_OOM(mLength);
|
||||
if (!EnsureMutable())
|
||||
NS_ABORT_OOM(mLength);
|
||||
|
||||
mData[aIndex] = CharT(aChar);
|
||||
return true;
|
||||
}
|
||||
mData[aIndex] = CharT(aChar);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* nsTString::StripChars,StripChar,StripWhitespace
|
||||
*/
|
||||
|
||||
/**
|
||||
* nsTString::StripChars,StripChar,StripWhitespace
|
||||
*/
|
||||
|
||||
void
|
||||
nsTString_CharT::StripChars( const char* aSet )
|
||||
{
|
||||
if (!EnsureMutable())
|
||||
NS_ABORT_OOM(mLength);
|
||||
{
|
||||
if (!EnsureMutable())
|
||||
NS_ABORT_OOM(mLength);
|
||||
|
||||
mLength = nsBufferRoutines<CharT>::strip_chars(mData, mLength, aSet);
|
||||
}
|
||||
mLength = nsBufferRoutines<CharT>::strip_chars(mData, mLength, aSet);
|
||||
}
|
||||
|
||||
void
|
||||
nsTString_CharT::StripWhitespace()
|
||||
{
|
||||
StripChars(kWhitespace);
|
||||
}
|
||||
{
|
||||
StripChars(kWhitespace);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* nsTString::ReplaceChar,ReplaceSubstring
|
||||
*/
|
||||
/**
|
||||
* nsTString::ReplaceChar,ReplaceSubstring
|
||||
*/
|
||||
|
||||
void
|
||||
nsTString_CharT::ReplaceChar( char_type aOldChar, char_type aNewChar )
|
||||
{
|
||||
if (!EnsureMutable()) // XXX do this lazily?
|
||||
NS_ABORT_OOM(mLength);
|
||||
{
|
||||
if (!EnsureMutable()) // XXX do this lazily?
|
||||
NS_ABORT_OOM(mLength);
|
||||
|
||||
for (uint32_t i=0; i<mLength; ++i)
|
||||
{
|
||||
if (mData[i] == aOldChar)
|
||||
mData[i] = aNewChar;
|
||||
}
|
||||
for (uint32_t i=0; i<mLength; ++i)
|
||||
{
|
||||
if (mData[i] == aOldChar)
|
||||
mData[i] = aNewChar;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsTString_CharT::ReplaceChar( const char* aSet, char_type aNewChar )
|
||||
{
|
||||
if (!EnsureMutable()) // XXX do this lazily?
|
||||
NS_ABORT_OOM(mLength);
|
||||
|
||||
char_type* data = mData;
|
||||
uint32_t lenRemaining = mLength;
|
||||
|
||||
while (lenRemaining)
|
||||
{
|
||||
if (!EnsureMutable()) // XXX do this lazily?
|
||||
NS_ABORT_OOM(mLength);
|
||||
int32_t i = ::FindCharInSet(data, lenRemaining, aSet);
|
||||
if (i == kNotFound)
|
||||
break;
|
||||
|
||||
char_type* data = mData;
|
||||
uint32_t lenRemaining = mLength;
|
||||
|
||||
while (lenRemaining)
|
||||
{
|
||||
int32_t i = ::FindCharInSet(data, lenRemaining, aSet);
|
||||
if (i == kNotFound)
|
||||
break;
|
||||
|
||||
data[i++] = aNewChar;
|
||||
data += i;
|
||||
lenRemaining -= i;
|
||||
}
|
||||
data[i++] = aNewChar;
|
||||
data += i;
|
||||
lenRemaining -= i;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsTString_CharT::ReplaceSubstring( const char_type* aTarget, const char_type* aNewValue )
|
||||
{
|
||||
ReplaceSubstring(nsTDependentString_CharT(aTarget),
|
||||
nsTDependentString_CharT(aNewValue));
|
||||
}
|
||||
{
|
||||
ReplaceSubstring(nsTDependentString_CharT(aTarget),
|
||||
nsTDependentString_CharT(aNewValue));
|
||||
}
|
||||
|
||||
void
|
||||
nsTString_CharT::ReplaceSubstring( const self_type& aTarget, const self_type& aNewValue )
|
||||
{
|
||||
if (aTarget.Length() == 0)
|
||||
return;
|
||||
|
||||
uint32_t i = 0;
|
||||
while (i < mLength)
|
||||
{
|
||||
if (aTarget.Length() == 0)
|
||||
return;
|
||||
int32_t r = FindSubstring(mData + i, mLength - i, static_cast<const char_type*>(aTarget.Data()), aTarget.Length(), false);
|
||||
if (r == kNotFound)
|
||||
break;
|
||||
|
||||
uint32_t i = 0;
|
||||
while (i < mLength)
|
||||
{
|
||||
int32_t r = FindSubstring(mData + i, mLength - i, static_cast<const char_type*>(aTarget.Data()), aTarget.Length(), false);
|
||||
if (r == kNotFound)
|
||||
break;
|
||||
|
||||
Replace(i + r, aTarget.Length(), aNewValue);
|
||||
i += r + aNewValue.Length();
|
||||
}
|
||||
Replace(i + r, aTarget.Length(), aNewValue);
|
||||
i += r + aNewValue.Length();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* nsTString::Trim
|
||||
*/
|
||||
/**
|
||||
* nsTString::Trim
|
||||
*/
|
||||
|
||||
void
|
||||
nsTString_CharT::Trim( const char* aSet, bool aTrimLeading, bool aTrimTrailing, bool aIgnoreQuotes )
|
||||
{
|
||||
// the old implementation worried about aSet being null :-/
|
||||
if (!aSet)
|
||||
return;
|
||||
|
||||
char_type* start = mData;
|
||||
char_type* end = mData + mLength;
|
||||
|
||||
// skip over quotes if requested
|
||||
if (aIgnoreQuotes && mLength > 2 && mData[0] == mData[mLength - 1] &&
|
||||
(mData[0] == '\'' || mData[0] == '"'))
|
||||
{
|
||||
// the old implementation worried about aSet being null :-/
|
||||
if (!aSet)
|
||||
return;
|
||||
|
||||
char_type* start = mData;
|
||||
char_type* end = mData + mLength;
|
||||
|
||||
// skip over quotes if requested
|
||||
if (aIgnoreQuotes && mLength > 2 && mData[0] == mData[mLength - 1] &&
|
||||
(mData[0] == '\'' || mData[0] == '"'))
|
||||
{
|
||||
++start;
|
||||
--end;
|
||||
}
|
||||
|
||||
uint32_t setLen = nsCharTraits<char>::length(aSet);
|
||||
|
||||
if (aTrimLeading)
|
||||
{
|
||||
uint32_t cutStart = start - mData;
|
||||
uint32_t cutLength = 0;
|
||||
|
||||
// walk forward from start to end
|
||||
for (; start != end; ++start, ++cutLength)
|
||||
{
|
||||
int32_t pos = FindChar1(aSet, setLen, 0, *start, setLen);
|
||||
if (pos == kNotFound)
|
||||
break;
|
||||
}
|
||||
|
||||
if (cutLength)
|
||||
{
|
||||
Cut(cutStart, cutLength);
|
||||
|
||||
// reset iterators
|
||||
start = mData + cutStart;
|
||||
end = mData + mLength - cutStart;
|
||||
}
|
||||
}
|
||||
|
||||
if (aTrimTrailing)
|
||||
{
|
||||
uint32_t cutEnd = end - mData;
|
||||
uint32_t cutLength = 0;
|
||||
|
||||
// walk backward from end to start
|
||||
--end;
|
||||
for (; end >= start; --end, ++cutLength)
|
||||
{
|
||||
int32_t pos = FindChar1(aSet, setLen, 0, *end, setLen);
|
||||
if (pos == kNotFound)
|
||||
break;
|
||||
}
|
||||
|
||||
if (cutLength)
|
||||
Cut(cutEnd - cutLength, cutLength);
|
||||
}
|
||||
++start;
|
||||
--end;
|
||||
}
|
||||
|
||||
uint32_t setLen = nsCharTraits<char>::length(aSet);
|
||||
|
||||
/**
|
||||
* nsTString::CompressWhitespace
|
||||
*/
|
||||
if (aTrimLeading)
|
||||
{
|
||||
uint32_t cutStart = start - mData;
|
||||
uint32_t cutLength = 0;
|
||||
|
||||
// walk forward from start to end
|
||||
for (; start != end; ++start, ++cutLength)
|
||||
{
|
||||
int32_t pos = FindChar1(aSet, setLen, 0, *start, setLen);
|
||||
if (pos == kNotFound)
|
||||
break;
|
||||
}
|
||||
|
||||
if (cutLength)
|
||||
{
|
||||
Cut(cutStart, cutLength);
|
||||
|
||||
// reset iterators
|
||||
start = mData + cutStart;
|
||||
end = mData + mLength - cutStart;
|
||||
}
|
||||
}
|
||||
|
||||
if (aTrimTrailing)
|
||||
{
|
||||
uint32_t cutEnd = end - mData;
|
||||
uint32_t cutLength = 0;
|
||||
|
||||
// walk backward from end to start
|
||||
--end;
|
||||
for (; end >= start; --end, ++cutLength)
|
||||
{
|
||||
int32_t pos = FindChar1(aSet, setLen, 0, *end, setLen);
|
||||
if (pos == kNotFound)
|
||||
break;
|
||||
}
|
||||
|
||||
if (cutLength)
|
||||
Cut(cutEnd - cutLength, cutLength);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* nsTString::CompressWhitespace
|
||||
*/
|
||||
|
||||
void
|
||||
nsTString_CharT::CompressWhitespace( bool aTrimLeading, bool aTrimTrailing )
|
||||
{
|
||||
const char* set = kWhitespace;
|
||||
{
|
||||
const char* set = kWhitespace;
|
||||
|
||||
ReplaceChar(set, ' ');
|
||||
Trim(set, aTrimLeading, aTrimTrailing);
|
||||
ReplaceChar(set, ' ');
|
||||
Trim(set, aTrimLeading, aTrimTrailing);
|
||||
|
||||
// this one does some questionable fu... just copying the old code!
|
||||
mLength = nsBufferRoutines<char_type>::compress_chars(mData, mLength, set);
|
||||
}
|
||||
// this one does some questionable fu... just copying the old code!
|
||||
mLength = nsBufferRoutines<char_type>::compress_chars(mData, mLength, set);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* nsTString::AssignWithConversion
|
||||
*/
|
||||
/**
|
||||
* nsTString::AssignWithConversion
|
||||
*/
|
||||
|
||||
void
|
||||
nsTString_CharT::AssignWithConversion( const incompatible_char_type* aData, int32_t aLength )
|
||||
{
|
||||
// for compatibility with the old string implementation, we need to allow
|
||||
// for a nullptr input buffer :-(
|
||||
if (!aData)
|
||||
{
|
||||
// for compatibility with the old string implementation, we need to allow
|
||||
// for a nullptr input buffer :-(
|
||||
if (!aData)
|
||||
{
|
||||
Truncate();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (aLength < 0)
|
||||
aLength = nsCharTraits<incompatible_char_type>::length(aData);
|
||||
|
||||
AssignWithConversion(Substring(aData, aLength));
|
||||
}
|
||||
Truncate();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (aLength < 0)
|
||||
aLength = nsCharTraits<incompatible_char_type>::length(aData);
|
||||
|
||||
AssignWithConversion(Substring(aData, aLength));
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,95 +1,95 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
|
||||
/**
|
||||
* computes the aggregate string length
|
||||
*/
|
||||
/**
|
||||
* computes the aggregate string length
|
||||
*/
|
||||
|
||||
nsTSubstringTuple_CharT::size_type
|
||||
nsTSubstringTuple_CharT::Length() const
|
||||
{
|
||||
uint32_t len;
|
||||
if (mHead)
|
||||
len = mHead->Length();
|
||||
else
|
||||
len = TO_SUBSTRING(mFragA).Length();
|
||||
{
|
||||
uint32_t len;
|
||||
if (mHead)
|
||||
len = mHead->Length();
|
||||
else
|
||||
len = TO_SUBSTRING(mFragA).Length();
|
||||
|
||||
return len + TO_SUBSTRING(mFragB).Length();
|
||||
}
|
||||
return len + TO_SUBSTRING(mFragB).Length();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* writes the aggregate string to the given buffer. bufLen is assumed
|
||||
* to be equal to or greater than the value returned by the Length()
|
||||
* method. the string written to |buf| is not null-terminated.
|
||||
*/
|
||||
/**
|
||||
* writes the aggregate string to the given buffer. bufLen is assumed
|
||||
* to be equal to or greater than the value returned by the Length()
|
||||
* method. the string written to |buf| is not null-terminated.
|
||||
*/
|
||||
|
||||
void
|
||||
nsTSubstringTuple_CharT::WriteTo( char_type *buf, uint32_t bufLen ) const
|
||||
{
|
||||
const substring_type& b = TO_SUBSTRING(mFragB);
|
||||
|
||||
NS_ASSERTION(bufLen >= b.Length(), "buffer too small");
|
||||
uint32_t headLen = bufLen - b.Length();
|
||||
if (mHead)
|
||||
{
|
||||
const substring_type& b = TO_SUBSTRING(mFragB);
|
||||
mHead->WriteTo(buf, headLen);
|
||||
}
|
||||
else
|
||||
{
|
||||
const substring_type& a = TO_SUBSTRING(mFragA);
|
||||
|
||||
NS_ASSERTION(bufLen >= b.Length(), "buffer too small");
|
||||
uint32_t headLen = bufLen - b.Length();
|
||||
if (mHead)
|
||||
{
|
||||
mHead->WriteTo(buf, headLen);
|
||||
}
|
||||
else
|
||||
{
|
||||
const substring_type& a = TO_SUBSTRING(mFragA);
|
||||
|
||||
NS_ASSERTION(a.Length() == headLen, "buffer incorrectly sized");
|
||||
char_traits::copy(buf, a.Data(), a.Length());
|
||||
}
|
||||
|
||||
char_traits::copy(buf + headLen, b.Data(), b.Length());
|
||||
|
||||
#if 0
|
||||
// we need to write out data into |buf|, ending at |buf+bufLen|. so our
|
||||
// data needs to precede |buf+bufLen| exactly. we trust that the buffer
|
||||
// was properly sized!
|
||||
|
||||
const substring_type& b = TO_SUBSTRING(mFragB);
|
||||
|
||||
NS_ASSERTION(bufLen >= b.Length(), "buffer is too small");
|
||||
char_traits::copy(buf + bufLen - b.Length(), b.Data(), b.Length());
|
||||
|
||||
bufLen -= b.Length();
|
||||
|
||||
if (mHead)
|
||||
{
|
||||
mHead->WriteTo(buf, bufLen);
|
||||
}
|
||||
else
|
||||
{
|
||||
const substring_type& a = TO_SUBSTRING(mFragA);
|
||||
NS_ASSERTION(bufLen == a.Length(), "buffer is too small");
|
||||
char_traits::copy(buf, a.Data(), a.Length());
|
||||
}
|
||||
#endif
|
||||
NS_ASSERTION(a.Length() == headLen, "buffer incorrectly sized");
|
||||
char_traits::copy(buf, a.Data(), a.Length());
|
||||
}
|
||||
|
||||
char_traits::copy(buf + headLen, b.Data(), b.Length());
|
||||
|
||||
/**
|
||||
* returns true if this tuple is dependent on (i.e., overlapping with)
|
||||
* the given char sequence.
|
||||
*/
|
||||
#if 0
|
||||
// we need to write out data into |buf|, ending at |buf+bufLen|. so our
|
||||
// data needs to precede |buf+bufLen| exactly. we trust that the buffer
|
||||
// was properly sized!
|
||||
|
||||
const substring_type& b = TO_SUBSTRING(mFragB);
|
||||
|
||||
NS_ASSERTION(bufLen >= b.Length(), "buffer is too small");
|
||||
char_traits::copy(buf + bufLen - b.Length(), b.Data(), b.Length());
|
||||
|
||||
bufLen -= b.Length();
|
||||
|
||||
if (mHead)
|
||||
{
|
||||
mHead->WriteTo(buf, bufLen);
|
||||
}
|
||||
else
|
||||
{
|
||||
const substring_type& a = TO_SUBSTRING(mFragA);
|
||||
NS_ASSERTION(bufLen == a.Length(), "buffer is too small");
|
||||
char_traits::copy(buf, a.Data(), a.Length());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* returns true if this tuple is dependent on (i.e., overlapping with)
|
||||
* the given char sequence.
|
||||
*/
|
||||
|
||||
bool
|
||||
nsTSubstringTuple_CharT::IsDependentOn( const char_type *start, const char_type *end ) const
|
||||
{
|
||||
// we start with the right-most fragment since it is faster to check.
|
||||
{
|
||||
// we start with the right-most fragment since it is faster to check.
|
||||
|
||||
if (TO_SUBSTRING(mFragB).IsDependentOn(start, end))
|
||||
return true;
|
||||
if (TO_SUBSTRING(mFragB).IsDependentOn(start, end))
|
||||
return true;
|
||||
|
||||
if (mHead)
|
||||
return mHead->IsDependentOn(start, end);
|
||||
if (mHead)
|
||||
return mHead->IsDependentOn(start, end);
|
||||
|
||||
return TO_SUBSTRING(mFragA).IsDependentOn(start, end);
|
||||
}
|
||||
return TO_SUBSTRING(mFragA).IsDependentOn(start, end);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user