+ bool ConcatSelf(size_t nLen, const wxChar *src, size_t nMaxLen);
+ bool ConcatSelf(size_t nLen, const wxChar *src)
+ { return ConcatSelf(nLen, src, nLen); }
+
+ // functions called before writing to the string: they copy it if there
+ // are other references to our data (should be the only owner when writing)
+ bool CopyBeforeWrite();
+ bool AllocBeforeWrite(size_t);
+
+ // compatibility with wxString
+ bool Alloc(size_t nLen);
+public:
+ // standard types
+ typedef wxUniChar value_type;
+ typedef wxUniChar char_type;
+ typedef wxUniCharRef reference;
+ typedef wxChar* pointer;
+ typedef const wxChar* const_pointer;
+
+ typedef size_t size_type;
+ typedef wxUniChar const_reference;
+
+ #define WX_STR_ITERATOR_IMPL(iterator_name, pointer_type, \
+ reference_type, reference_ctor) \
+ public: \
+ typedef wxUniChar value_type; \
+ typedef reference_type reference; \
+ typedef pointer_type pointer; \
+ \
+ iterator_name(const iterator_name& i) : m_cur(i.m_cur) {} \
+ \
+ reference operator*() const { return reference_ctor; } \
+ \
+ iterator_name& operator++() \
+ { ++m_cur; return *this; } \
+ iterator_name operator++(int) \
+ { iterator_name tmp = *this; ++m_cur; return tmp; } \
+ iterator_name& operator--() \
+ { --m_cur; return *this; } \
+ iterator_name operator--(int) \
+ { iterator_name tmp = *this; --m_cur; return tmp; } \
+ \
+ iterator_name operator+(int n) const \
+ { return iterator_name(m_cur + n); } \
+ iterator_name operator+(size_t n) const \
+ { return iterator_name(m_cur + n); } \
+ iterator_name operator-(int n) const \
+ { return iterator_name(m_cur - n); } \
+ iterator_name operator-(size_t n) const \
+ { return iterator_name(m_cur - n); } \
+ iterator_name operator+=(int n) \
+ { m_cur += n; return *this; } \
+ iterator_name operator+=(size_t n) \
+ { m_cur += n; return *this; } \
+ iterator_name operator-=(int n) \
+ { m_cur -= n; return *this; } \
+ iterator_name operator-=(size_t n) \
+ { m_cur -= n; return *this; } \
+ \
+ unsigned operator-(const iterator_name& i) const \
+ { return m_cur - i.m_cur; } \
+ \
+ bool operator==(const iterator_name&i) const \
+ { return m_cur == i.m_cur; } \
+ bool operator!=(const iterator_name& i) const \
+ { return m_cur != i.m_cur; } \
+ \
+ bool operator<(const iterator_name& i) const \
+ { return m_cur < i.m_cur; } \
+ bool operator>(const iterator_name& i) const \
+ { return m_cur > i.m_cur; } \
+ bool operator<=(const iterator_name& i) const \
+ { return m_cur <= i.m_cur; } \
+ bool operator>=(const iterator_name& i) const \
+ { return m_cur >= i.m_cur; } \
+ \
+ protected: \
+ /* for internal wxString use only: */ \
+ iterator_name(pointer ptr) : m_cur(ptr) {} \
+ operator pointer() const { return m_cur; } \
+ \
+ friend class WXDLLIMPEXP_BASE wxString; \
+ friend class WXDLLIMPEXP_BASE wxStringBase; \
+ friend class WXDLLIMPEXP_BASE wxCStrData; \
+ \
+ protected: \
+ pointer m_cur;
+
+ class const_iterator;
+
+ class iterator
+ {
+ WX_STR_ITERATOR_IMPL(iterator, wxChar*, wxUniCharRef,
+ wxUniCharRef::CreateForString(m_cur))
+
+ friend class const_iterator;
+ };
+
+ class const_iterator
+ {
+ // NB: reference_type is intentionally value, not reference, the character
+ // may be encoded differently in wxString data:
+ WX_STR_ITERATOR_IMPL(const_iterator, const wxChar*, wxUniChar,
+ wxUniChar(*m_cur))
+
+ public:
+ const_iterator(const iterator& i) : m_cur(i.m_cur) {}
+ };
+
+ #undef WX_STR_ITERATOR
+
+ template <typename T>
+ class reverse_iterator_impl
+ {
+ public:
+ typedef T iterator_type;
+ typedef typename T::value_type value_type;
+ typedef typename T::reference reference;
+ typedef typename T::pointer *pointer;
+
+ reverse_iterator_impl(iterator_type i) : m_cur(i) {}
+ reverse_iterator_impl(const reverse_iterator_impl& ri)
+ : m_cur(ri.m_cur) {}
+
+ iterator_type base() const { return m_cur; }
+
+ reference operator*() const { return *(m_cur-1); }
+
+ reverse_iterator_impl& operator++()
+ { --m_cur; return *this; }
+ reverse_iterator_impl operator++(int)
+ { reverse_iterator_impl tmp = *this; --m_cur; return tmp; }
+ reverse_iterator_impl& operator--()
+ { ++m_cur; return *this; }
+ reverse_iterator_impl operator--(int)
+ { reverse_iterator_impl tmp = *this; ++m_cur; return tmp; }
+
+ bool operator==(const reverse_iterator_impl& ri) const
+ { return m_cur == ri.m_cur; }
+ bool operator!=(const reverse_iterator_impl& ri) const
+ { return !(*this == ri); }
+
+ private:
+ iterator_type m_cur;
+ };
+
+ typedef reverse_iterator_impl<iterator> reverse_iterator;
+ typedef reverse_iterator_impl<const_iterator> const_reverse_iterator;
+
+
+ // constructors and destructor
+ // ctor for an empty string
+ wxStringBase() { Init(); }
+ // copy ctor
+ wxStringBase(const wxStringBase& stringSrc)
+ {
+ wxASSERT_MSG( stringSrc.GetStringData()->IsValid(),
+ _T("did you forget to call UngetWriteBuf()?") );
+
+ if ( stringSrc.empty() ) {
+ // nothing to do for an empty string
+ Init();
+ }
+ else {
+ m_pchData = stringSrc.m_pchData; // share same data
+ GetStringData()->Lock(); // => one more copy
+ }
+ }
+ // string containing nRepeat copies of ch
+ wxStringBase(size_type nRepeat, wxUniChar ch);
+ // ctor takes first nLength characters from C string
+ // (default value of npos means take all the string)
+ wxStringBase(const wxChar *psz)
+ { InitWith(psz, 0, npos); }
+ wxStringBase(const wxChar *psz, size_t nLength)
+ { InitWith(psz, 0, nLength); }
+ wxStringBase(const wxChar *psz,
+ const wxMBConv& WXUNUSED(conv),
+ size_t nLength = npos)
+ { InitWith(psz, 0, nLength); }
+ // take nLen chars starting at nPos
+ wxStringBase(const wxStringBase& str, size_t nPos, size_t nLen)
+ {
+ wxASSERT_MSG( str.GetStringData()->IsValid(),
+ _T("did you forget to call UngetWriteBuf()?") );
+ Init();
+ size_t strLen = str.length() - nPos; nLen = strLen < nLen ? strLen : nLen;
+ InitWith(str.c_str(), nPos, nLen);
+ }
+ // take all characters from pStart to pEnd
+ wxStringBase(const void *pStart, const void *pEnd);
+
+ // dtor is not virtual, this class must not be inherited from!
+ ~wxStringBase()
+ {
+#if defined(__VISUALC__) && (__VISUALC__ >= 1200)
+ //RN - according to the above VC++ does indeed inline this,
+ //even though it spits out two warnings
+ #pragma warning (disable:4714)
+#endif
+
+ GetStringData()->Unlock();
+ }
+
+#if defined(__VISUALC__) && (__VISUALC__ >= 1200)
+ //re-enable inlining warning
+ #pragma warning (default:4714)
+#endif
+ // overloaded assignment
+ // from another wxString
+ wxStringBase& operator=(const wxStringBase& stringSrc);
+ // from a character
+ wxStringBase& operator=(wxUniChar ch);
+ // from a C string
+ wxStringBase& operator=(const wxChar *psz);
+
+ // return the length of the string
+ size_type length() const { return GetStringData()->nDataLength; }
+ // return the length of the string
+ size_type size() const { return length(); }
+ // return the maximum size of the string
+ size_type max_size() const { return npos; }
+ // resize the string, filling the space with c if c != 0
+ void resize(size_t nSize, wxUniChar ch = wxT('\0'));
+ // delete the contents of the string
+ void clear() { erase(0, npos); }
+ // returns true if the string is empty
+ bool empty() const { return length() == 0; }
+ // inform string about planned change in size
+ void reserve(size_t sz) { Alloc(sz); }
+ size_type capacity() const { return GetStringData()->nAllocLength; }
+
+ // lib.string.access
+ // return the character at position n
+ value_type at(size_type n) const
+ { wxASSERT_VALID_INDEX( n ); return m_pchData[n]; }
+ // returns the writable character at position n
+ reference at(size_type n)
+ {
+ wxASSERT_VALID_INDEX( n );
+ CopyBeforeWrite();
+ return wxUniCharRef::CreateForString(&m_pchData[n]);
+ }
+
+ // lib.string.modifiers
+ // append elements str[pos], ..., str[pos+n]
+ wxStringBase& append(const wxStringBase& str, size_t pos, size_t n)
+ {
+ wxASSERT(pos <= str.length());
+ ConcatSelf(n, str.c_str() + pos, str.length() - pos);
+ return *this;
+ }
+ // append a string
+ wxStringBase& append(const wxStringBase& str)
+ { ConcatSelf(str.length(), str.c_str()); return *this; }
+ // append first n (or all if n == npos) characters of sz
+ wxStringBase& append(const wxChar *sz)
+ { ConcatSelf(wxStrlen(sz), sz); return *this; }
+ wxStringBase& append(const wxChar *sz, size_t n)
+ { ConcatSelf(n, sz); return *this; }
+ // append n copies of ch
+ wxStringBase& append(size_t n, wxUniChar ch);
+ // append from first to last
+ wxStringBase& append(const_iterator first, const_iterator last)
+ { ConcatSelf(last - first, first); return *this; }
+
+ // same as `this_string = str'
+ wxStringBase& assign(const wxStringBase& str)
+ { return *this = str; }
+ // same as ` = str[pos..pos + n]
+ wxStringBase& assign(const wxStringBase& str, size_t pos, size_t n)
+ { clear(); return append(str, pos, n); }
+ // same as `= first n (or all if n == npos) characters of sz'
+ wxStringBase& assign(const wxChar *sz)
+ { clear(); return append(sz, wxStrlen(sz)); }
+ wxStringBase& assign(const wxChar *sz, size_t n)
+ { clear(); return append(sz, n); }
+ // same as `= n copies of ch'
+ wxStringBase& assign(size_t n, wxUniChar ch)
+ { clear(); return append(n, ch); }
+ // assign from first to last
+ wxStringBase& assign(const_iterator first, const_iterator last)
+ { clear(); return append(first, last); }
+
+ // first valid index position
+ const_iterator begin() const { return m_pchData; }
+ iterator begin();
+ // position one after the last valid one
+ const_iterator end() const { return m_pchData + length(); }
+ iterator end();
+
+ // first element of the reversed string
+ const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
+ reverse_iterator rbegin() { return reverse_iterator(end()); }
+ // one beyond the end of the reversed string
+ const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
+ reverse_iterator rend() { return reverse_iterator(begin()); }
+
+ // insert another string
+ wxStringBase& insert(size_t nPos, const wxStringBase& str)
+ {
+ wxASSERT( str.GetStringData()->IsValid() );
+ return insert(nPos, str.c_str(), str.length());
+ }
+ // insert n chars of str starting at nStart (in str)
+ wxStringBase& insert(size_t nPos, const wxStringBase& str, size_t nStart, size_t n)
+ {
+ wxASSERT( str.GetStringData()->IsValid() );
+ wxASSERT( nStart < str.length() );
+ size_t strLen = str.length() - nStart;
+ n = strLen < n ? strLen : n;
+ return insert(nPos, str.c_str() + nStart, n);
+ }
+ // insert first n (or all if n == npos) characters of sz
+ wxStringBase& insert(size_t nPos, const wxChar *sz, size_t n = npos);
+ // insert n copies of ch
+ wxStringBase& insert(size_t nPos, size_t n, wxUniChar ch)
+ { return insert(nPos, wxStringBase(n, ch)); }
+ iterator insert(iterator it, wxUniChar ch)
+ { size_t idx = it - begin(); insert(idx, 1, ch); return begin() + idx; }
+ void insert(iterator it, const_iterator first, const_iterator last)
+ { insert(it - begin(), first, last - first); }
+ void insert(iterator it, size_type n, wxUniChar ch)
+ { insert(it - begin(), n, ch); }
+
+ // delete characters from nStart to nStart + nLen
+ wxStringBase& erase(size_type pos = 0, size_type n = npos);
+ iterator erase(iterator first, iterator last)
+ {
+ size_t idx = first - begin();
+ erase(idx, last - first);
+ return begin() + idx;
+ }
+ iterator erase(iterator first);
+
+ // explicit conversion to C string (use this with printf()!)
+ const wxChar* c_str() const { return m_pchData; }
+ const wxChar* data() const { return m_pchData; }
+
+ // replaces the substring of length nLen starting at nStart
+ wxStringBase& replace(size_t nStart, size_t nLen, const wxChar* sz);
+ // replaces the substring of length nLen starting at nStart
+ wxStringBase& replace(size_t nStart, size_t nLen, const wxStringBase& str)
+ { return replace(nStart, nLen, str.c_str()); }
+ // replaces the substring with nCount copies of ch
+ wxStringBase& replace(size_t nStart, size_t nLen, size_t nCount, wxUniChar ch);
+ // replaces a substring with another substring
+ wxStringBase& replace(size_t nStart, size_t nLen,
+ const wxStringBase& str, size_t nStart2, size_t nLen2);
+ // replaces the substring with first nCount chars of sz
+ wxStringBase& replace(size_t nStart, size_t nLen,
+ const wxChar* sz, size_t nCount);
+ wxStringBase& replace(iterator first, iterator last, const_pointer s)
+ { return replace(first - begin(), last - first, s); }
+ wxStringBase& replace(iterator first, iterator last, const_pointer s,
+ size_type n)
+ { return replace(first - begin(), last - first, s, n); }
+ wxStringBase& replace(iterator first, iterator last, const wxStringBase& s)
+ { return replace(first - begin(), last - first, s); }
+ wxStringBase& replace(iterator first, iterator last, size_type n, wxUniChar c)
+ { return replace(first - begin(), last - first, n, c); }
+ wxStringBase& replace(iterator first, iterator last,
+ const_iterator first1, const_iterator last1)
+ { return replace(first - begin(), last - first, first1, last1 - first1); }
+
+ // swap two strings
+ void swap(wxStringBase& str);
+
+ // All find() functions take the nStart argument which specifies the
+ // position to start the search on, the default value is 0. All functions
+ // return npos if there were no match.
+
+ // find a substring
+ size_t find(const wxStringBase& str, size_t nStart = 0) const;
+
+ // find first n characters of sz
+ size_t find(const wxChar* sz, size_t nStart = 0, size_t n = npos) const;
+
+ // find the first occurence of character ch after nStart
+ size_t find(wxUniChar ch, size_t nStart = 0) const;
+
+ // rfind() family is exactly like find() but works right to left
+
+ // as find, but from the end
+ size_t rfind(const wxStringBase& str, size_t nStart = npos) const;
+
+ // as find, but from the end
+ size_t rfind(const wxChar* sz, size_t nStart = npos,
+ size_t n = npos) const;
+ // as find, but from the end
+ size_t rfind(wxUniChar ch, size_t nStart = npos) const;
+
+ // find first/last occurence of any character in the set
+
+ // as strpbrk() but starts at nStart, returns npos if not found
+ size_t find_first_of(const wxStringBase& str, size_t nStart = 0) const
+ { return find_first_of(str.c_str(), nStart); }
+ // same as above
+ size_t find_first_of(const wxChar* sz, size_t nStart = 0) const;
+ size_t find_first_of(const wxChar* sz, size_t nStart, size_t n) const;
+ // same as find(char, size_t)
+ size_t find_first_of(wxUniChar c, size_t nStart = 0) const
+ { return find(c, nStart); }
+ // find the last (starting from nStart) char from str in this string
+ size_t find_last_of (const wxStringBase& str, size_t nStart = npos) const
+ { return find_last_of(str.c_str(), nStart); }
+ // same as above
+ size_t find_last_of (const wxChar* sz, size_t nStart = npos) const;
+ size_t find_last_of(const wxChar* sz, size_t nStart, size_t n) const;
+ // same as above
+ size_t find_last_of(wxUniChar c, size_t nStart = npos) const
+ { return rfind(c, nStart); }
+
+ // find first/last occurence of any character not in the set
+
+ // as strspn() (starting from nStart), returns npos on failure
+ size_t find_first_not_of(const wxStringBase& str, size_t nStart = 0) const
+ { return find_first_not_of(str.c_str(), nStart); }
+ // same as above
+ size_t find_first_not_of(const wxChar* sz, size_t nStart = 0) const;
+ size_t find_first_not_of(const wxChar* sz, size_t nStart, size_t n) const;
+ // same as above
+ size_t find_first_not_of(wxUniChar ch, size_t nStart = 0) const;
+ // as strcspn()
+ size_t find_last_not_of(const wxStringBase& str, size_t nStart = npos) const
+ { return find_last_not_of(str.c_str(), nStart); }
+ // same as above
+ size_t find_last_not_of(const wxChar* sz, size_t nStart = npos) const;
+ size_t find_last_not_of(const wxChar* sz, size_t nStart, size_t n) const;
+ // same as above
+ size_t find_last_not_of(wxUniChar ch, size_t nStart = npos) const;
+
+ // All compare functions return -1, 0 or 1 if the [sub]string is less,
+ // equal or greater than the compare() argument.
+
+ // comparison with another string
+ int compare(const wxStringBase& str) const;
+ // comparison with a substring
+ int compare(size_t nStart, size_t nLen, const wxStringBase& str) const;
+ // comparison of 2 substrings
+ int compare(size_t nStart, size_t nLen,
+ const wxStringBase& str, size_t nStart2, size_t nLen2) const;
+ // comparison with a c string
+ int compare(const wxChar* sz) const;
+ // substring comparison with first nCount characters of sz
+ int compare(size_t nStart, size_t nLen,
+ const wxChar* sz, size_t nCount = npos) const;
+
+ size_type copy(wxChar* s, size_type n, size_type pos = 0);
+
+ // substring extraction
+ wxStringBase substr(size_t nStart = 0, size_t nLen = npos) const;
+
+ // string += string
+ wxStringBase& operator+=(const wxStringBase& s) { return append(s); }
+ // string += C string
+ wxStringBase& operator+=(const wxChar *psz) { return append(psz); }
+ // string += char
+ wxStringBase& operator+=(wxUniChar ch) { return append(1, ch); }
+ wxStringBase& operator+=(wxUniCharRef ch) { return append(1, ch); }
+ wxStringBase& operator+=(char ch) { return append(1, ch); }
+ wxStringBase& operator+=(wchar_t ch) { return append(1, ch); }
+};
+
+#endif // !wxUSE_STL
+
+// ----------------------------------------------------------------------------
+// wxCStrData
+// ----------------------------------------------------------------------------
+
+// Lightweight object returned by wxString::c_str() and implicitly convertible
+// to either const char* or const wchar_t*.
+class WXDLLIMPEXP_BASE wxCStrData
+{
+private:
+ // Ctors; for internal use by wxString and wxCStrData only
+ wxCStrData(const wxString *str, size_t offset = 0, bool owned = false)
+ : m_str(str), m_offset(offset), m_owned(owned) {}
+
+public:
+ // Ctor constructs the object from char literal; they are needed to make
+ // operator?: compile and they intentionally take char*, not const char*
+ wxCStrData(char *buf);
+ wxCStrData(wchar_t *buf);
+
+ ~wxCStrData();
+
+ // FIXME: we'll need convertors for both char* and wchar_t* and NONE
+ // for wxChar*, but that's after completing the transition to
+ // "smart" wxUniChar class. For now, just have conversion to
+ // char* in ANSI build and wchar_t in Unicode build.
+#if wxUSE_UNICODE
+ const wchar_t* AsWChar() const;
+ operator const wchar_t*() const { return AsWChar(); }
+#else
+ const char* AsChar() const;
+ operator const char*() const { return AsChar(); }
+#endif
+
+ wxString AsString() const;
+ operator wxString() const;
+
+ // allow expressions like "c_str()[0]":
+ wxUniChar operator[](int n) const { return operator[](size_t(n)); }
+ wxUniChar operator[](size_t n) const;
+ wxUniChar operator[](long n) const { return operator[](size_t(n)); }
+#ifndef wxSIZE_T_IS_UINT
+ wxUniChar operator[](unsigned int n) const { return operator[](size_t(n)); }
+#endif // size_t != unsigned int
+
+ // these operators are needed to emulate the pointer semantics of c_str():
+ // expressions like "wxChar *p = str.c_str() + 1;" should continue to work
+ // (we need both versions to resolve ambiguities):
+ wxCStrData operator+(int n) const
+ { return wxCStrData(m_str, m_offset + n, m_owned); }
+ wxCStrData operator+(long n) const
+ { return wxCStrData(m_str, m_offset + n, m_owned); }
+ wxCStrData operator+(size_t n) const
+ { return wxCStrData(m_str, m_offset + n, m_owned); }
+
+ // this operator is need to make expressions like "*c_str()" or
+ // "*(c_str() + 2)" work
+ wxUniChar operator*() const;
+
+private:
+ const wxString *m_str;
+ size_t m_offset;
+ bool m_owned;
+
+ friend class WXDLLIMPEXP_BASE wxString;
+};
+
+// ----------------------------------------------------------------------------
+// wxStringPrintfMixin
+// ---------------------------------------------------------------------------
+
+// NB: VC6 has a bug that causes linker errors if you have template methods
+// in a class using __declspec(dllimport). The solution is to split such
+// class into two classes, one that contains the template methods and does
+// *not* use WXDLLIMPEXP_BASE and another class that contains the rest
+// (with DLL linkage).
+//
+// We only do this for VC6 here, because the code is less efficient
+// (Printf() has to use dynamic_cast<>) and because OpenWatcom compiler
+// cannot compile this code.
+
+#if defined(__VISUALC__) && __VISUALC__ < 1300
+ #define wxNEEDS_WXSTRING_PRINTF_MIXIN
+#endif
+
+#ifdef wxNEEDS_WXSTRING_PRINTF_MIXIN
+// this class contains implementation of wxString's vararg methods, it's
+// exported from wxBase DLL
+class WXDLLIMPEXP_BASE wxStringPrintfMixinBase
+{
+protected:
+ wxStringPrintfMixinBase() {}
+
+ int DoPrintf(const wxChar *format, ...) ATTRIBUTE_PRINTF_2;
+ static wxString DoFormat(const wxChar *format, ...) ATTRIBUTE_PRINTF_1;
+};
+
+// this class contains template wrappers for wxString's vararg methods, it's
+// intentionally *not* exported from the DLL in order to fix the VC6 bug
+// described above
+class wxStringPrintfMixin : public wxStringPrintfMixinBase
+{
+private:
+ // to further complicate things, we can't return wxString from
+ // wxStringPrintfMixin::Format() because wxString is not yet declared at
+ // this point; the solution is to use this fake type trait template - this
+ // way the compiler won't know the return type until Format() is used
+ // (this doesn't compile with Watcom, but VC6 compiles it just fine):
+ template<typename T> struct StringReturnType
+ {
+ typedef wxString type;
+ };
+
+public:
+ // these are duplicated wxString methods, they're also declared below
+ // if !wxNEEDS_WXSTRING_PRINTF_MIXIN:
+
+ // int Printf(const wxChar *pszFormat, ...);
+ WX_DEFINE_VARARG_FUNC(int, Printf, DoPrintf)
+ // static wxString Format(const wxChar *pszFormat, ...) ATTRIBUTE_PRINTF_1;
+ WX_DEFINE_VARARG_FUNC(static typename StringReturnType<T1>::type,
+ Format, DoFormat)
+ // int sprintf(const wxChar *pszFormat, ...) ATTRIBUTE_PRINTF_2;
+ WX_DEFINE_VARARG_FUNC(int, sprintf, DoPrintf)
+
+protected:
+ wxStringPrintfMixin() : wxStringPrintfMixinBase() {}
+};
+#endif // wxNEEDS_WXSTRING_PRINTF_MIXIN
+
+
+// ----------------------------------------------------------------------------
+// wxString: string class trying to be compatible with std::string, MFC
+// CString and wxWindows 1.x wxString all at once
+// ---------------------------------------------------------------------------