| OLD | NEW |
| 1 /* | 1 /* |
| 2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2012 Apple Inc. All rights | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2012 Apple Inc. All rights |
| 4 * reserved. | 4 * reserved. |
| 5 * Copyright (C) 2007-2009 Torch Mobile, Inc. | 5 * Copyright (C) 2007-2009 Torch Mobile, Inc. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 putUTF8Triple(buffer, *characters); | 702 putUTF8Triple(buffer, *characters); |
| 703 } | 703 } |
| 704 } | 704 } |
| 705 } | 705 } |
| 706 | 706 |
| 707 return CString(bufferVector.data(), buffer - bufferVector.data()); | 707 return CString(bufferVector.data(), buffer - bufferVector.data()); |
| 708 } | 708 } |
| 709 | 709 |
| 710 String String::make8BitFrom16BitSource(const UChar* source, size_t length) { | 710 String String::make8BitFrom16BitSource(const UChar* source, size_t length) { |
| 711 if (!length) | 711 if (!length) |
| 712 return emptyString(); | 712 return emptyString; |
| 713 | 713 |
| 714 LChar* destination; | 714 LChar* destination; |
| 715 String result = String::createUninitialized(length, destination); | 715 String result = String::createUninitialized(length, destination); |
| 716 | 716 |
| 717 copyLCharsFromUCharSource(destination, source, length); | 717 copyLCharsFromUCharSource(destination, source, length); |
| 718 | 718 |
| 719 return result; | 719 return result; |
| 720 } | 720 } |
| 721 | 721 |
| 722 String String::make16BitFrom8BitSource(const LChar* source, size_t length) { | 722 String String::make16BitFrom8BitSource(const LChar* source, size_t length) { |
| 723 if (!length) | 723 if (!length) |
| 724 return emptyString16Bit(); | 724 return emptyString16Bit; |
| 725 | 725 |
| 726 UChar* destination; | 726 UChar* destination; |
| 727 String result = String::createUninitialized(length, destination); | 727 String result = String::createUninitialized(length, destination); |
| 728 | 728 |
| 729 StringImpl::copyChars(destination, source, length); | 729 StringImpl::copyChars(destination, source, length); |
| 730 | 730 |
| 731 return result; | 731 return result; |
| 732 } | 732 } |
| 733 | 733 |
| 734 String String::fromUTF8(const LChar* stringStart, size_t length) { | 734 String String::fromUTF8(const LChar* stringStart, size_t length) { |
| 735 RELEASE_ASSERT(length <= std::numeric_limits<unsigned>::max()); | 735 RELEASE_ASSERT(length <= std::numeric_limits<unsigned>::max()); |
| 736 | 736 |
| 737 if (!stringStart) | 737 if (!stringStart) |
| 738 return String(); | 738 return String(); |
| 739 | 739 |
| 740 if (!length) | 740 if (!length) |
| 741 return emptyString(); | 741 return emptyString; |
| 742 | 742 |
| 743 if (charactersAreAllASCII(stringStart, length)) | 743 if (charactersAreAllASCII(stringStart, length)) |
| 744 return StringImpl::create(stringStart, length); | 744 return StringImpl::create(stringStart, length); |
| 745 | 745 |
| 746 Vector<UChar, 1024> buffer(length); | 746 Vector<UChar, 1024> buffer(length); |
| 747 UChar* bufferStart = buffer.data(); | 747 UChar* bufferStart = buffer.data(); |
| 748 | 748 |
| 749 UChar* bufferCurrent = bufferStart; | 749 UChar* bufferCurrent = bufferStart; |
| 750 const char* stringCurrent = reinterpret_cast<const char*>(stringStart); | 750 const char* stringCurrent = reinterpret_cast<const char*>(stringStart); |
| 751 if (convertUTF8ToUTF16( | 751 if (convertUTF8ToUTF16( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 768 return fromUTF8(s.data()); | 768 return fromUTF8(s.data()); |
| 769 } | 769 } |
| 770 | 770 |
| 771 String String::fromUTF8WithLatin1Fallback(const LChar* string, size_t size) { | 771 String String::fromUTF8WithLatin1Fallback(const LChar* string, size_t size) { |
| 772 String utf8 = fromUTF8(string, size); | 772 String utf8 = fromUTF8(string, size); |
| 773 if (!utf8) | 773 if (!utf8) |
| 774 return String(string, size); | 774 return String(string, size); |
| 775 return utf8; | 775 return utf8; |
| 776 } | 776 } |
| 777 | 777 |
| 778 const String& emptyString() { | |
| 779 DEFINE_STATIC_LOCAL(String, emptyString, (StringImpl::empty)); | |
| 780 return emptyString; | |
| 781 } | |
| 782 | |
| 783 const String& emptyString16Bit() { | |
| 784 DEFINE_STATIC_LOCAL(String, emptyString, (StringImpl::empty16Bit)); | |
| 785 return emptyString; | |
| 786 } | |
| 787 | |
| 788 std::ostream& operator<<(std::ostream& out, const String& string) { | 778 std::ostream& operator<<(std::ostream& out, const String& string) { |
| 789 if (string.isNull()) | 779 if (string.isNull()) |
| 790 return out << "<null>"; | 780 return out << "<null>"; |
| 791 | 781 |
| 792 out << '"'; | 782 out << '"'; |
| 793 for (unsigned index = 0; index < string.length(); ++index) { | 783 for (unsigned index = 0; index < string.length(); ++index) { |
| 794 // Print shorthands for select cases. | 784 // Print shorthands for select cases. |
| 795 UChar character = string[index]; | 785 UChar character = string[index]; |
| 796 switch (character) { | 786 switch (character) { |
| 797 case '\t': | 787 case '\t': |
| (...skipping 29 matching lines...) Expand all Loading... |
| 827 return out << '"'; | 817 return out << '"'; |
| 828 } | 818 } |
| 829 | 819 |
| 830 #ifndef NDEBUG | 820 #ifndef NDEBUG |
| 831 void String::show() const { | 821 void String::show() const { |
| 832 dataLogF("%s\n", asciiDebug(impl()).data()); | 822 dataLogF("%s\n", asciiDebug(impl()).data()); |
| 833 } | 823 } |
| 834 #endif | 824 #endif |
| 835 | 825 |
| 836 } // namespace WTF | 826 } // namespace WTF |
| OLD | NEW |