mirror of
https://review.haiku-os.org/buildtools
synced 2024-11-23 07:18:49 +01:00
Allow use of c_str() when <charT> != char
http://gcc.gnu.org/ml/libstdc++-prs/2000-q4/msg00004.html This allows use on std::wstring, and others.
This commit is contained in:
parent
855732f929
commit
99cc4338d7
@ -38,6 +38,10 @@
|
||||
// NOTE : This does NOT conform to the draft standard and is likely to change
|
||||
#include <alloc.h>
|
||||
|
||||
#ifdef __HAIKU__
|
||||
# include <config/types.h>
|
||||
#endif
|
||||
|
||||
extern "C++" {
|
||||
class istream; class ostream;
|
||||
|
||||
@ -61,12 +65,10 @@ extern void __length_error (const char *);
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__BEOS__) || defined(__HAIKU__)
|
||||
// Needed for atomic_add():
|
||||
typedef long int32;
|
||||
typedef volatile long vint32;
|
||||
extern "C" int32 atomic_add(vint32* value, int32 addvalue);
|
||||
#endif /* __BEOS__ || __HAIKU__ */
|
||||
#ifdef __HAIKU__
|
||||
extern "C" __haiku_int32 atomic_add(volatile __haiku_int32* value,
|
||||
__haiku_int32 addvalue);
|
||||
#endif /* __HAIKU__ */
|
||||
|
||||
template <class charT, class traits = string_char_traits<charT>,
|
||||
class Allocator = alloc >
|
||||
@ -79,9 +81,9 @@ private:
|
||||
|
||||
charT* data () { return reinterpret_cast<charT *>(this + 1); }
|
||||
charT& operator[] (size_t s) { return data () [s]; }
|
||||
#if defined(__BEOS__) || defined(__HAIKU__)
|
||||
charT* grab () { if (selfish) return clone (); atomic_add((vint32*) &ref, 1); return data (); }
|
||||
void release() { if (atomic_add((int32*) &ref, -1) == 1) delete this; }
|
||||
#ifdef __HAIKU__
|
||||
charT* grab () { if (selfish) return clone (); atomic_add((volatile __haiku_int32*) &ref, 1); return data (); }
|
||||
void release() { if (atomic_add((__haiku_int32*) &ref, -1) == 1) delete this; }
|
||||
#else
|
||||
charT* grab () { if (selfish) return clone (); ++ref; return data (); }
|
||||
#if defined __i486__ || defined __i586__ || defined __i686__
|
||||
@ -119,7 +121,7 @@ private:
|
||||
#else
|
||||
void release () { if (--ref == 0) delete this; }
|
||||
#endif
|
||||
#endif /* __BEOS__ || __HAIKU__ */
|
||||
#endif /* __HAIKU__ */
|
||||
inline static void * operator new (size_t, size_t);
|
||||
inline static void operator delete (void *);
|
||||
inline static Rep* create (size_t);
|
||||
@ -348,7 +350,10 @@ private:
|
||||
|
||||
public:
|
||||
const charT* c_str () const
|
||||
{ if (length () == 0) return ""; terminate (); return data (); }
|
||||
{
|
||||
static const charT null_str[1] = {0};
|
||||
if (length () == 0) return null_str; terminate (); return data ();
|
||||
}
|
||||
void resize (size_type n, charT c);
|
||||
void resize (size_type n)
|
||||
{ resize (n, eos ()); }
|
||||
@ -405,7 +410,13 @@ public:
|
||||
|
||||
int compare (const basic_string& str, size_type pos = 0, size_type n = npos) const;
|
||||
// There is no 'strncmp' equivalent for charT pointers.
|
||||
|
||||
// BeOS bogus version
|
||||
int compare (const charT* s, size_type pos, size_type n) const;
|
||||
|
||||
// Correct std C++ prototype
|
||||
int compare (size_type pos, size_type n, const charT* s) const
|
||||
{ return compare(s, pos, n); }
|
||||
int compare (const charT* s, size_type pos = 0) const
|
||||
{ return compare (s, pos, traits::length (s)); }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user