KJS
23 #ifndef _KJS_USTRING_H_
24 #define _KJS_USTRING_H_
26 #include "kjs/global.h"
28 #include <wtf/AlwaysInline.h>
29 #include <wtf/FastMalloc.h>
30 #include <wtf/RefPtr.h>
31 #include <wtf/PassRefPtr.h>
32 #include <wtf/Vector.h>
35 #include "collector.h"
42 #if defined(WTF_COMPILER_GCC) && PLATFORM(FORCE_PACK)
43 #define PACK_STRUCT __attribute__((packed))
80 UChar(
unsigned char h,
unsigned char l);
86 UChar(
unsigned char u);
87 UChar(
unsigned short u);
93 return static_cast<unsigned char>(uc >> 8);
99 unsigned char low()
const
101 return static_cast<unsigned char>(uc);
116 inline UChar::UChar(
unsigned char h,
unsigned char l) : uc(h << 8 | l) { }
127 CString() : data(
nullptr), length(0) { }
129 CString(
const char *c,
size_t len);
134 CString &operator=(
const char *c);
141 const char *c_str()
const
155 KJS_EXPORT
friend bool operator==(
const UString &,
const UString &);
163 static PassRefPtr<Rep> create(
UChar *d,
int l);
164 static PassRefPtr<Rep> createCopying(
const UChar *d,
int l);
165 static PassRefPtr<Rep> create(PassRefPtr<Rep> base,
int offset,
int length);
169 bool baseIsSelf()
const
171 return baseString ==
this;
175 return baseString->buf + baseString->preCapacity + offset;
182 unsigned hash()
const
185 _hash = computeHash(data(), len);
188 unsigned computedHash()
const
193 static unsigned computeHash(
const UChar *,
int length);
194 static unsigned computeHash(
const char *s,
int length);
195 static unsigned computeHash(
const char *);
202 ALWAYS_INLINE
void deref()
213 mutable unsigned _hash;
247 UString(
const char *c,
size_t length);
264 UString &operator=(
const UString &s) { m_rep = s.m_rep;
return *
this; }
266 UString(
const Vector<UChar> &buffer);
275 KJS_EXTERNAL_EXPORT UString(
const QString &);
284 UString(
const UString &,
const UString &);
297 static UString from(
unsigned int u);
311 Range(
int pos,
int len) : position(pos), length(len) {}
317 UString spliceSubstringsWithSeparators(
const Range *substringRanges,
int rangeCount,
const UString *separators,
int separatorCount)
const;
322 UString &append(
const UString &subStr,
int subPos,
int subLength = -1);
323 UString &append(
const UString &t);
324 UString &append(
const char *t);
325 UString &append(
const char *t,
int tSize);
326 UString &append(
unsigned short);
327 UString &append(
char c)
329 return append(
static_cast<unsigned short>(
static_cast<unsigned char>(c)));
331 UString &append(UChar c)
339 CString cstring()
const;
356 CString UTF8String()
const;
365 KJS_EXTERNAL_EXPORT
QString qstring()
const;
369 KJS_EXTERNAL_EXPORT QConstString qconststring()
const;
374 UString &operator=(
const char *c);
375 UString &operator=(Empty);
383 UString &operator+=(
const char *s)
393 return m_rep->data();
400 return (m_rep == &Rep::null);
407 return (!m_rep->len);
422 return m_rep->size();
427 const UChar operator[](
int pos)
const;
436 double toDouble(
bool tolerateTrailingJunk,
bool tolerateEmptyString)
const;
437 double toDouble(
bool tolerateTrailingJunk)
const;
438 double toDouble()
const;
444 uint32_t toStrictUInt32(
bool *ok =
nullptr)
const;
452 unsigned toArrayIndex(
bool *ok =
nullptr)
const;
458 int find(
const UString &f,
int pos = 0)
const;
459 int find(
UChar,
int pos = 0)
const;
465 int rfind(
const UString &f,
int pos)
const;
466 int rfind(
UChar,
int pos)
const;
470 UString substr(
int pos = 0,
int len = -1)
const;
480 static size_t maxUChars();
486 UString(PassRefPtr<Rep> r) : m_rep(r)
490 void copyForWriting();
494 size_t expandedSize(
size_t size,
size_t otherSize)
const;
495 int usedCapacity()
const;
496 int usedPreCapacity()
const;
497 void expandCapacity(
int requiredLength);
498 void expandPreCapacity(
int requiredPreCap);
499 void set(
const char *c,
int len);
504 KJS_EXPORT
inline bool operator==(
const UChar &c1,
const UChar &c2)
506 return (c1.uc == c2.uc);
508 KJS_EXPORT
bool operator==(
const UString &s1,
const UString &s2);
509 KJS_EXPORT
inline bool operator!=(
const UString &s1,
const UString &s2)
511 return !KJS::operator==(s1, s2);
513 KJS_EXPORT
bool operator<(
const UString &s1,
const UString &s2);
514 KJS_EXPORT
bool operator==(
const UString &s1,
const char *s2);
515 KJS_EXPORT
inline bool operator!=(
const UString &s1,
const char *s2)
517 return !KJS::operator==(s1, s2);
519 KJS_EXPORT
inline bool operator==(
const char *s1,
const UString &s2)
523 KJS_EXPORT
inline bool operator!=(
const char *s1,
const UString &s2)
525 return !KJS::operator==(s1, s2);
527 KJS_EXPORT
bool operator==(
const CString &s1,
const CString &s2);
528 KJS_EXPORT
inline UString
operator+(
const UString &s1,
const UString &s2)
530 return UString(s1, s2);
533 KJS_EXPORT
int compare(
const UString &,
const UString &);
538 int UTF8SequenceLength(
char);
543 int decodeUTF8Sequence(
const char *);
555 if (ok && i >= 0xFFFFFFFFU) {
566 static const int minShareSize = Collector::minExtraCostSize /
sizeof(
UChar);
568 inline size_t UString::cost()
const
570 size_t capacity = (m_rep->baseString->capacity + m_rep->baseString->preCapacity) *
sizeof(
UChar);
571 size_t reportedCost = m_rep->baseString->reportedCost;
572 ASSERT(capacity >= reportedCost);
574 size_t capacityDelta = capacity - reportedCost;
576 if (capacityDelta <
static_cast<size_t>(minShareSize)) {
580 m_rep->baseString->reportedCost = capacity;
581 return capacityDelta;
589 template<
typename T>
struct DefaultHash;
590 template<
typename T>
struct StrHash;
592 template<>
struct StrHash<KJS::UString::Rep *> {
599 return KJS::UString::equal(a, b);
601 static const bool safeToCompareToEmptyOrDeleted =
false;
604 template<>
struct DefaultHash<KJS::UString::Rep *> {
605 typedef StrHash<KJS::UString::Rep *> Hash;
UString(const UString &s)
Copy constructor.
unsigned toArrayIndex(bool *ok=nullptr) const
Attempts an conversion to an array index.
unsigned char high() const
UChar()
Construct a character with uninitialized value.
uint32_t toStrictUInt32(bool *ok=nullptr) const
Attempts an conversion to a 32-bit integer.
unsigned char low() const
bool operator==(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
unsigned short unicode() const
UString()
Constructs a null string.
const QCA_EXPORT SecureArray operator+(const SecureArray &a, const SecureArray &b)
bool operator!=(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
const UChar * data() const
UString & operator+=(const UString &s)
Appends the specified string.
8 bit char based string class
Empty
Constructs an empty string.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Jun 27 2022 03:59:24 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.