#ifndef String_h
#define String_h
#include "StringImpl.h"
#if __APPLE__
#include <CoreFoundation/CoreFoundation.h>
#endif
namespace WebCore {
class String {
public:
String() { } String(const UChar*, unsigned length);
explicit String(const UChar*); String(const KJS::Identifier&);
String(const KJS::UString&);
String(const char*);
String(const char*, unsigned length);
String(StringImpl* i) : m_impl(i) { }
operator KJS::Identifier() const;
operator KJS::UString() const;
unsigned length() const;
const UChar* characters() const;
UChar operator[](unsigned i) const;
bool contains(UChar c) const { return find(c) != -1; }
bool contains(const char* str, bool caseSensitive = true) const { return find(str, 0, caseSensitive) != -1; }
bool contains(const String& str, bool caseSensitive = true) const { return find(str, 0, caseSensitive) != -1; }
int find(UChar c, int start = 0) const
{ return m_impl ? m_impl->find(c, start) : -1; }
int find(const char* str, int start = 0, bool caseSensitive = true) const
{ return m_impl ? m_impl->find(str, start, caseSensitive) : -1; }
int find(const String& str, int start = 0, bool caseSensitive = true) const
{ return m_impl ? m_impl->find(str.impl(), start, caseSensitive) : -1; }
bool startsWith(const String& s, bool caseSensitive = true) const
{ return m_impl ? m_impl->startsWith(s.impl(), caseSensitive) : s.isEmpty(); }
bool endsWith(const String& s, bool caseSensitive = true) const
{ return m_impl ? m_impl->endsWith(s.impl(), caseSensitive) : s.isEmpty(); }
void append(const String&);
void append(char);
void append(UChar);
void insert(const String&, unsigned pos);
String& replace(UChar a, UChar b) { if (m_impl) m_impl = m_impl->replace(a, b); return *this; }
String& replace(UChar a, const String& b) { if (m_impl) m_impl = m_impl->replace(a, b.impl()); return *this; }
String& replace(unsigned index, unsigned len, const String& b) { if (m_impl) m_impl = m_impl->replace(index, len, b.impl()); return *this; }
void truncate(unsigned len);
void remove(unsigned pos, int len = 1);
String substring(unsigned pos, unsigned len = UINT_MAX) const;
String left(unsigned len) const { return substring(0, len); }
String right(unsigned len) const { return substring(length() - len, len); }
String split(unsigned pos);
String lower() const;
String upper() const;
String stripWhiteSpace() const;
String foldCase() const;
static String number(int);
static String number(unsigned);
static String number(long);
static String number(unsigned long);
static String number(long long);
static String number(unsigned long long);
static String number(double);
static String sprintf(const char *, ...)
#if __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif
;
int toInt(bool* ok = 0) const;
Length* toLengthArray(int& len) const;
Length* toCoordsArray(int& len) const;
bool percentage(int &_percentage) const;
String copy() const;
bool isNull() const { return !m_impl; }
bool isEmpty() const;
StringImpl* impl() const { return m_impl.get(); }
#if __APPLE__
String(CFStringRef);
CFStringRef createCFString() const { return m_impl ? m_impl->createCFString() : CFSTR(""); }
#endif
#if __OBJC__
String(NSString*);
operator NSString*() const { if (!m_impl) return @""; return *m_impl; }
#endif
#ifndef NDEBUG
Vector<char> ascii() const;
#endif
String(const DeprecatedString&);
DeprecatedString deprecatedString() const;
private:
RefPtr<StringImpl> m_impl;
};
String operator+(const String&, const String&);
String operator+(const String&, const char*);
String operator+(const char*, const String&);
inline String& operator+=(String& a, const String& b) { a.append(b); return a; }
inline bool operator==(const String& a, const String& b) { return equal(a.impl(), b.impl()); }
inline bool operator==(const String& a, const char* b) { return equal(a.impl(), b); }
inline bool operator==(const char* a, const String& b) { return equal(a, b.impl()); }
inline bool operator!=(const String& a, const String& b) { return !equal(a.impl(), b.impl()); }
inline bool operator!=(const String& a, const char* b) { return !equal(a.impl(), b); }
inline bool operator!=(const char* a, const String& b) { return !equal(a, b.impl()); }
inline bool equalIgnoringCase(const String& a, const String& b) { return equalIgnoringCase(a.impl(), b.impl()); }
inline bool equalIgnoringCase(const String& a, const char* b) { return equalIgnoringCase(a.impl(), b); }
inline bool equalIgnoringCase(const char* a, const String& b) { return equalIgnoringCase(a, b.impl()); }
bool operator==(const String& a, const DeprecatedString& b);
inline bool operator==(const DeprecatedString& b, const String& a) { return a == b; }
inline bool operator!=(const String& a, const DeprecatedString& b) { return !(a == b); }
inline bool operator!=(const DeprecatedString& b, const String& a ) { return !(a == b); }
}
namespace WTF {
template<typename T> struct DefaultHash;
template<typename T> struct StrHash;
template<> struct DefaultHash<WebCore::String> {
typedef StrHash<WebCore::String> Hash;
};
}
#endif