UString.h 23.3 KB
Newer Older
1 2
/*
 *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3
 *  Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
levin@chromium.org's avatar
levin@chromium.org committed
4
 *  Copyright (C) 2009 Google Inc. All rights reserved.
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
mjs's avatar
mjs committed
18
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
 *  Boston, MA 02110-1301, USA.
20
 *
21 22
 */

23 24
#ifndef UString_h
#define UString_h
25

26
#include "Collector.h"
27
#include "UStringImpl.h"
ggaren's avatar
ggaren committed
28
#include <stdint.h>
29
#include <string.h>
ggaren's avatar
ggaren committed
30
#include <wtf/Assertions.h>
levin@chromium.org's avatar
levin@chromium.org committed
31 32
#include <wtf/CrossThreadRefCounted.h>
#include <wtf/OwnFastMallocPtr.h>
mjs's avatar
mjs committed
33
#include <wtf/PassRefPtr.h>
ggaren's avatar
ggaren committed
34
#include <wtf/RefPtr.h>
35
#include <wtf/Vector.h>
36
#include <wtf/text/CString.h>
37
#include <wtf/unicode/Unicode.h>
38

39
namespace JSC {
40

weinig@apple.com's avatar
weinig@apple.com committed
41 42
    using WTF::PlacementNewAdoptType;
    using WTF::PlacementNewAdopt;
darin's avatar
darin committed
43

44
    class UString {
45
        friend class JIT;
46

weinig@apple.com's avatar
weinig@apple.com committed
47
    public:
48 49
        typedef UStringImpl Rep;
    
mjs's avatar
mjs committed
50
    public:
51
        UString() {}
52
        UString(const char*); // Constructor for null-terminated string.
53 54
        UString(const char*, unsigned length);
        UString(const UChar*, unsigned length);
55
        UString(const Vector<UChar>& buffer);
weinig@apple.com's avatar
weinig@apple.com committed
56 57 58 59 60 61 62 63 64 65 66 67

        UString(const UString& s)
            : m_rep(s.m_rep)
        {
        }

        // Special constructor for cases where we overwrite an object in place.
        UString(PlacementNewAdoptType)
            : m_rep(PlacementNewAdopt)
        {
        }

68 69 70 71 72 73
        template<size_t inlineCapacity>
        static PassRefPtr<UStringImpl> adopt(Vector<UChar, inlineCapacity>& vector)
        {
            return Rep::adopt(vector);
        }

weinig@apple.com's avatar
weinig@apple.com committed
74
        static UString from(int);
75
        static UString from(long long);
76
        static UString from(unsigned);
weinig@apple.com's avatar
weinig@apple.com committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
        static UString from(long);
        static UString from(double);

        // NOTE: This method should only be used for *debugging* purposes as it
        // is neither Unicode safe nor free from side effects nor thread-safe.
        char* ascii() const;

        /**
         * Convert the string to UTF-8, assuming it is UTF-16 encoded.
         * In non-strict mode, this function is tolerant of badly formed UTF-16, it
         * can create UTF-8 strings that are invalid because they have characters in
         * the range U+D800-U+DDFF, U+FFFE, or U+FFFF, but the UTF-8 string is
         * guaranteed to be otherwise valid.
         * In strict mode, error is returned as null CString.
         */
        CString UTF8String(bool strict = false) const;

94 95 96 97 98 99 100 101 102 103 104 105 106
        const UChar* data() const
        {
            if (!m_rep)
                return 0;
            return m_rep->characters();
        }

        unsigned size() const
        {
            if (!m_rep)
                return 0;
            return m_rep->length();
        }
weinig@apple.com's avatar
weinig@apple.com committed
107

108 109
        bool isNull() const { return !m_rep; }
        bool isEmpty() const { return !m_rep || !m_rep->length(); }
weinig@apple.com's avatar
weinig@apple.com committed
110 111 112

        bool is8Bit() const;

113
        UChar operator[](unsigned pos) const;
weinig@apple.com's avatar
weinig@apple.com committed
114 115 116 117 118 119 120 121 122 123 124

        double toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const;
        double toDouble(bool tolerateTrailingJunk) const;
        double toDouble() const;

        uint32_t toUInt32(bool* ok = 0) const;
        uint32_t toUInt32(bool* ok, bool tolerateEmptyString) const;
        uint32_t toStrictUInt32(bool* ok = 0) const;

        unsigned toArrayIndex(bool* ok = 0) const;

125 126 127 128 129
        static const unsigned NotFound = 0xFFFFFFFFu;
        unsigned find(const UString& f, unsigned pos = 0) const;
        unsigned find(UChar, unsigned pos = 0) const;
        unsigned rfind(const UString& f, unsigned pos) const;
        unsigned rfind(UChar, unsigned pos) const;
weinig@apple.com's avatar
weinig@apple.com committed
130

131
        UString substr(unsigned pos = 0, unsigned len = 0xFFFFFFFF) const;
weinig@apple.com's avatar
weinig@apple.com committed
132

133
        static const UString& null() { return *s_nullUString; }
weinig@apple.com's avatar
weinig@apple.com committed
134 135 136

        Rep* rep() const { return m_rep.get(); }

137 138 139 140 141
        UString(PassRefPtr<Rep> r)
            : m_rep(r)
        {
        }

142 143 144 145 146 147
        size_t cost() const
        {
            if (!m_rep)
                return 0;
            return m_rep->cost();
        }
148

149
        ALWAYS_INLINE ~UString() { }
weinig@apple.com's avatar
weinig@apple.com committed
150 151
    private:
        RefPtr<Rep> m_rep;
152 153

        static UString* s_nullUString;
mjs's avatar
mjs committed
154

155
        friend void initializeUString();
darin@apple.com's avatar
darin@apple.com committed
156 157
        friend bool operator==(const UString&, const UString&);
    };
158

159
    ALWAYS_INLINE bool operator==(const UString& s1, const UString& s2)
160
    {
161
        unsigned size = s1.size();
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
        switch (size) {
        case 0:
            return !s2.size();
        case 1:
            return s2.size() == 1 && s1.data()[0] == s2.data()[0];
        case 2: {
            if (s2.size() != 2)
                return false;
            const UChar* d1 = s1.data();
            const UChar* d2 = s2.data();
            return (d1[0] == d2[0]) & (d1[1] == d2[1]);
        }
        default:
            return s2.size() == size && memcmp(s1.data(), s2.data(), size * sizeof(UChar)) == 0;
        }
    }

weinig@apple.com's avatar
weinig@apple.com committed
179 180 181

    inline bool operator!=(const UString& s1, const UString& s2)
    {
182
        return !JSC::operator==(s1, s2);
weinig@apple.com's avatar
weinig@apple.com committed
183 184 185 186
    }

    bool operator<(const UString& s1, const UString& s2);
    bool operator>(const UString& s1, const UString& s2);
187

weinig@apple.com's avatar
weinig@apple.com committed
188
    bool operator==(const UString& s1, const char* s2);
ap@webkit.org's avatar
ap@webkit.org committed
189

weinig@apple.com's avatar
weinig@apple.com committed
190 191
    inline bool operator!=(const UString& s1, const char* s2)
    {
192
        return !JSC::operator==(s1, s2);
weinig@apple.com's avatar
weinig@apple.com committed
193
    }
ap@webkit.org's avatar
ap@webkit.org committed
194

weinig@apple.com's avatar
weinig@apple.com committed
195 196 197 198
    inline bool operator==(const char *s1, const UString& s2)
    {
        return operator==(s2, s1);
    }
darin's avatar
darin committed
199

weinig@apple.com's avatar
weinig@apple.com committed
200 201
    inline bool operator!=(const char *s1, const UString& s2)
    {
202
        return !JSC::operator==(s1, s2);
weinig@apple.com's avatar
weinig@apple.com committed
203
    }
ggaren's avatar
ggaren committed
204

205 206 207 208
    inline int codePointCompare(const UString& s1, const UString& s2)
    {
        return codePointCompare(s1.rep(), s2.rep());
    }
mjs's avatar
mjs committed
209

weinig@apple.com's avatar
weinig@apple.com committed
210 211 212 213 214 215 216 217 218 219 220 221 222
    // Rule from ECMA 15.2 about what an array index is.
    // Must exactly match string form of an unsigned integer, and be less than 2^32 - 1.
    inline unsigned UString::toArrayIndex(bool* ok) const
    {
        unsigned i = toStrictUInt32(ok);
        if (ok && i >= 0xFFFFFFFFU)
            *ok = false;
        return i;
    }

    // We'd rather not do shared substring append for small strings, since
    // this runs too much risk of a tiny initial string holding down a
    // huge buffer.
223
    static const unsigned minShareSize = Heap::minExtraCost / sizeof(UChar);
weinig@apple.com's avatar
weinig@apple.com committed
224

225
    struct IdentifierRepHash : PtrHash<RefPtr<JSC::UString::Rep> > {
226 227
        static unsigned hash(const RefPtr<JSC::UString::Rep>& key) { return key->existingHash(); }
        static unsigned hash(JSC::UString::Rep* key) { return key->existingHash(); }
ggaren@apple.com's avatar
ggaren@apple.com committed
228 229
    };

230
    void initializeUString();
231 232 233 234 235 236

    template<typename StringType>
    class StringTypeAdapter {
    };

    template<>
237
    class StringTypeAdapter<char*> {
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
    public:
        StringTypeAdapter<char*>(char* buffer)
            : m_buffer((unsigned char*)buffer)
            , m_length(strlen(buffer))
        {
        }

        unsigned length() { return m_length; }

        void writeTo(UChar* destination)
        {
            for (unsigned i = 0; i < m_length; ++i)
                destination[i] = m_buffer[i];
        }

    private:
        const unsigned char* m_buffer;
        unsigned m_length;
    };

    template<>
259
    class StringTypeAdapter<const char*> {
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
    public:
        StringTypeAdapter<const char*>(const char* buffer)
            : m_buffer((unsigned char*)buffer)
            , m_length(strlen(buffer))
        {
        }

        unsigned length() { return m_length; }

        void writeTo(UChar* destination)
        {
            for (unsigned i = 0; i < m_length; ++i)
                destination[i] = m_buffer[i];
        }

    private:
        const unsigned char* m_buffer;
        unsigned m_length;
    };

    template<>
281
    class StringTypeAdapter<UString> {
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
    public:
        StringTypeAdapter<UString>(UString& string)
            : m_data(string.data())
            , m_length(string.size())
        {
        }

        unsigned length() { return m_length; }

        void writeTo(UChar* destination)
        {
            for (unsigned i = 0; i < m_length; ++i)
                destination[i] = m_data[i];
        }

    private:
        const UChar* m_data;
        unsigned m_length;
    };

302
    inline void sumWithOverflow(unsigned& total, unsigned addend, bool& overflow)
303 304 305 306 307 308 309
    {
        unsigned oldTotal = total;
        total = oldTotal + addend;
        if (total < oldTotal)
            overflow = true;
    }

310
    template<typename StringType1, typename StringType2>
311
    PassRefPtr<UStringImpl> tryMakeString(StringType1 string1, StringType2 string2)
312 313 314 315 316
    {
        StringTypeAdapter<StringType1> adapter1(string1);
        StringTypeAdapter<StringType2> adapter2(string2);

        UChar* buffer;
317 318 319 320 321
        bool overflow = false;
        unsigned length = adapter1.length();
        sumWithOverflow(length, adapter2.length(), overflow);
        if (overflow)
            return 0;
322 323
        PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
        if (!resultImpl)
324
            return 0;
325 326 327 328 329 330

        UChar* result = buffer;
        adapter1.writeTo(result);
        result += adapter1.length();
        adapter2.writeTo(result);

331
        return resultImpl;
332 333 334
    }

    template<typename StringType1, typename StringType2, typename StringType3>
335
    PassRefPtr<UStringImpl> tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3)
336 337 338 339 340
    {
        StringTypeAdapter<StringType1> adapter1(string1);
        StringTypeAdapter<StringType2> adapter2(string2);
        StringTypeAdapter<StringType3> adapter3(string3);

oliver@apple.com's avatar
oliver@apple.com committed
341
        UChar* buffer = 0;
342 343 344 345 346 347
        bool overflow = false;
        unsigned length = adapter1.length();
        sumWithOverflow(length, adapter2.length(), overflow);
        sumWithOverflow(length, adapter3.length(), overflow);
        if (overflow)
            return 0;
348 349
        PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
        if (!resultImpl)
350
            return 0;
351 352 353 354 355 356 357 358

        UChar* result = buffer;
        adapter1.writeTo(result);
        result += adapter1.length();
        adapter2.writeTo(result);
        result += adapter2.length();
        adapter3.writeTo(result);

359
        return resultImpl;
360 361 362
    }

    template<typename StringType1, typename StringType2, typename StringType3, typename StringType4>
363
    PassRefPtr<UStringImpl> tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4)
364 365 366 367 368 369 370
    {
        StringTypeAdapter<StringType1> adapter1(string1);
        StringTypeAdapter<StringType2> adapter2(string2);
        StringTypeAdapter<StringType3> adapter3(string3);
        StringTypeAdapter<StringType4> adapter4(string4);

        UChar* buffer;
371 372 373 374 375 376 377
        bool overflow = false;
        unsigned length = adapter1.length();
        sumWithOverflow(length, adapter2.length(), overflow);
        sumWithOverflow(length, adapter3.length(), overflow);
        sumWithOverflow(length, adapter4.length(), overflow);
        if (overflow)
            return 0;
378 379
        PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
        if (!resultImpl)
380
            return 0;
381 382 383 384 385 386 387 388 389 390

        UChar* result = buffer;
        adapter1.writeTo(result);
        result += adapter1.length();
        adapter2.writeTo(result);
        result += adapter2.length();
        adapter3.writeTo(result);
        result += adapter3.length();
        adapter4.writeTo(result);

391
        return resultImpl;
392 393 394
    }

    template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5>
395
    PassRefPtr<UStringImpl> tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5)
396 397 398 399 400 401 402 403
    {
        StringTypeAdapter<StringType1> adapter1(string1);
        StringTypeAdapter<StringType2> adapter2(string2);
        StringTypeAdapter<StringType3> adapter3(string3);
        StringTypeAdapter<StringType4> adapter4(string4);
        StringTypeAdapter<StringType5> adapter5(string5);

        UChar* buffer;
404 405 406 407 408 409 410 411
        bool overflow = false;
        unsigned length = adapter1.length();
        sumWithOverflow(length, adapter2.length(), overflow);
        sumWithOverflow(length, adapter3.length(), overflow);
        sumWithOverflow(length, adapter4.length(), overflow);
        sumWithOverflow(length, adapter5.length(), overflow);
        if (overflow)
            return 0;
412 413
        PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
        if (!resultImpl)
414
            return 0;
415 416 417 418 419 420 421 422 423 424 425 426

        UChar* result = buffer;
        adapter1.writeTo(result);
        result += adapter1.length();
        adapter2.writeTo(result);
        result += adapter2.length();
        adapter3.writeTo(result);
        result += adapter3.length();
        adapter4.writeTo(result);
        result += adapter4.length();
        adapter5.writeTo(result);

427
        return resultImpl;
428 429 430
    }

    template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5, typename StringType6>
431
    PassRefPtr<UStringImpl> tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6)
432 433 434 435 436 437 438 439 440
    {
        StringTypeAdapter<StringType1> adapter1(string1);
        StringTypeAdapter<StringType2> adapter2(string2);
        StringTypeAdapter<StringType3> adapter3(string3);
        StringTypeAdapter<StringType4> adapter4(string4);
        StringTypeAdapter<StringType5> adapter5(string5);
        StringTypeAdapter<StringType6> adapter6(string6);

        UChar* buffer;
441 442 443 444 445 446 447 448 449
        bool overflow = false;
        unsigned length = adapter1.length();
        sumWithOverflow(length, adapter2.length(), overflow);
        sumWithOverflow(length, adapter3.length(), overflow);
        sumWithOverflow(length, adapter4.length(), overflow);
        sumWithOverflow(length, adapter5.length(), overflow);
        sumWithOverflow(length, adapter6.length(), overflow);
        if (overflow)
            return 0;
450 451
        PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
        if (!resultImpl)
452
            return 0;
453 454 455 456 457 458 459 460 461 462 463 464 465 466

        UChar* result = buffer;
        adapter1.writeTo(result);
        result += adapter1.length();
        adapter2.writeTo(result);
        result += adapter2.length();
        adapter3.writeTo(result);
        result += adapter3.length();
        adapter4.writeTo(result);
        result += adapter4.length();
        adapter5.writeTo(result);
        result += adapter5.length();
        adapter6.writeTo(result);

467
        return resultImpl;
468 469 470
    }

    template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5, typename StringType6, typename StringType7>
471
    PassRefPtr<UStringImpl> tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6, StringType7 string7)
472 473 474 475 476 477 478 479 480 481
    {
        StringTypeAdapter<StringType1> adapter1(string1);
        StringTypeAdapter<StringType2> adapter2(string2);
        StringTypeAdapter<StringType3> adapter3(string3);
        StringTypeAdapter<StringType4> adapter4(string4);
        StringTypeAdapter<StringType5> adapter5(string5);
        StringTypeAdapter<StringType6> adapter6(string6);
        StringTypeAdapter<StringType7> adapter7(string7);

        UChar* buffer;
482 483 484 485 486 487 488 489 490 491
        bool overflow = false;
        unsigned length = adapter1.length();
        sumWithOverflow(length, adapter2.length(), overflow);
        sumWithOverflow(length, adapter3.length(), overflow);
        sumWithOverflow(length, adapter4.length(), overflow);
        sumWithOverflow(length, adapter5.length(), overflow);
        sumWithOverflow(length, adapter6.length(), overflow);
        sumWithOverflow(length, adapter7.length(), overflow);
        if (overflow)
            return 0;
492 493
        PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
        if (!resultImpl)
494
            return 0;
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510

        UChar* result = buffer;
        adapter1.writeTo(result);
        result += adapter1.length();
        adapter2.writeTo(result);
        result += adapter2.length();
        adapter3.writeTo(result);
        result += adapter3.length();
        adapter4.writeTo(result);
        result += adapter4.length();
        adapter5.writeTo(result);
        result += adapter5.length();
        adapter6.writeTo(result);
        result += adapter6.length();
        adapter7.writeTo(result);

511
        return resultImpl;
512 513 514
    }

    template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5, typename StringType6, typename StringType7, typename StringType8>
515
    PassRefPtr<UStringImpl> tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6, StringType7 string7, StringType8 string8)
516 517 518 519 520 521 522 523 524 525 526
    {
        StringTypeAdapter<StringType1> adapter1(string1);
        StringTypeAdapter<StringType2> adapter2(string2);
        StringTypeAdapter<StringType3> adapter3(string3);
        StringTypeAdapter<StringType4> adapter4(string4);
        StringTypeAdapter<StringType5> adapter5(string5);
        StringTypeAdapter<StringType6> adapter6(string6);
        StringTypeAdapter<StringType7> adapter7(string7);
        StringTypeAdapter<StringType8> adapter8(string8);

        UChar* buffer;
527 528 529 530 531 532 533 534 535 536 537
        bool overflow = false;
        unsigned length = adapter1.length();
        sumWithOverflow(length, adapter2.length(), overflow);
        sumWithOverflow(length, adapter3.length(), overflow);
        sumWithOverflow(length, adapter4.length(), overflow);
        sumWithOverflow(length, adapter5.length(), overflow);
        sumWithOverflow(length, adapter6.length(), overflow);
        sumWithOverflow(length, adapter7.length(), overflow);
        sumWithOverflow(length, adapter8.length(), overflow);
        if (overflow)
            return 0;
538 539
        PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
        if (!resultImpl)
540
            return 0;
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558

        UChar* result = buffer;
        adapter1.writeTo(result);
        result += adapter1.length();
        adapter2.writeTo(result);
        result += adapter2.length();
        adapter3.writeTo(result);
        result += adapter3.length();
        adapter4.writeTo(result);
        result += adapter4.length();
        adapter5.writeTo(result);
        result += adapter5.length();
        adapter6.writeTo(result);
        result += adapter6.length();
        adapter7.writeTo(result);
        result += adapter7.length();
        adapter8.writeTo(result);

559
        return resultImpl;
560 561
    }

562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
    template<typename StringType1, typename StringType2>
    UString makeString(StringType1 string1, StringType2 string2)
    {
        PassRefPtr<UStringImpl> resultImpl = tryMakeString(string1, string2);
        if (!resultImpl)
            CRASH();
        return resultImpl;
    }

    template<typename StringType1, typename StringType2, typename StringType3>
    UString makeString(StringType1 string1, StringType2 string2, StringType3 string3)
    {
        PassRefPtr<UStringImpl> resultImpl = tryMakeString(string1, string2, string3);
        if (!resultImpl)
            CRASH();
        return resultImpl;
    }

    template<typename StringType1, typename StringType2, typename StringType3, typename StringType4>
    UString makeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4)
    {
        PassRefPtr<UStringImpl> resultImpl = tryMakeString(string1, string2, string3, string4);
        if (!resultImpl)
            CRASH();
        return resultImpl;
    }

    template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5>
    UString makeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5)
    {
        PassRefPtr<UStringImpl> resultImpl = tryMakeString(string1, string2, string3, string4, string5);
        if (!resultImpl)
            CRASH();
        return resultImpl;
    }

    template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5, typename StringType6>
    UString makeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6)
    {
        PassRefPtr<UStringImpl> resultImpl = tryMakeString(string1, string2, string3, string4, string5, string6);
        if (!resultImpl)
            CRASH();
        return resultImpl;
    }

    template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5, typename StringType6, typename StringType7>
    UString makeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6, StringType7 string7)
    {
        PassRefPtr<UStringImpl> resultImpl = tryMakeString(string1, string2, string3, string4, string5, string6, string7);
        if (!resultImpl)
            CRASH();
        return resultImpl;
    }

    template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5, typename StringType6, typename StringType7, typename StringType8>
    UString makeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6, StringType7 string7, StringType8 string8)
    {
        PassRefPtr<UStringImpl> resultImpl = tryMakeString(string1, string2, string3, string4, string5, string6, string7, string8);
        if (!resultImpl)
            CRASH();
        return resultImpl;
    }

625
} // namespace JSC
ap@webkit.org's avatar
ap@webkit.org committed
626 627 628 629 630 631

namespace WTF {

    template<typename T> struct DefaultHash;
    template<typename T> struct StrHash;

632 633
    template<> struct StrHash<JSC::UString::Rep*> {
        static unsigned hash(const JSC::UString::Rep* key) { return key->hash(); }
634
        static bool equal(const JSC::UString::Rep* a, const JSC::UString::Rep* b) { return ::equal(a, b); }
ap@webkit.org's avatar
ap@webkit.org committed
635 636 637
        static const bool safeToCompareToEmptyOrDeleted = false;
    };

638 639 640 641
    template<> struct StrHash<RefPtr<JSC::UString::Rep> > : public StrHash<JSC::UString::Rep*> {
        using StrHash<JSC::UString::Rep*>::hash;
        static unsigned hash(const RefPtr<JSC::UString::Rep>& key) { return key->hash(); }
        using StrHash<JSC::UString::Rep*>::equal;
642 643 644
        static bool equal(const RefPtr<JSC::UString::Rep>& a, const RefPtr<JSC::UString::Rep>& b) { return ::equal(a.get(), b.get()); }
        static bool equal(const JSC::UString::Rep* a, const RefPtr<JSC::UString::Rep>& b) { return ::equal(a, b.get()); }
        static bool equal(const RefPtr<JSC::UString::Rep>& a, const JSC::UString::Rep* b) { return ::equal(a.get(), b); }
ap@webkit.org's avatar
ap@webkit.org committed
645 646 647 648

        static const bool safeToCompareToEmptyOrDeleted = false;
    };

649 650 651 652 653
    template <> struct VectorTraits<JSC::UString> : SimpleClassVectorTraits
    {
        static const bool canInitializeWithMemset = true;
    };
    
ap@webkit.org's avatar
ap@webkit.org committed
654
} // namespace WTF
655 656

#endif