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
reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2012 Apple Inc. All rights
reserved. |
4 * Copyright (C) 2007-2009 Torch Mobile, Inc. | 4 * Copyright (C) 2007-2009 Torch Mobile, Inc. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 return emptyString16Bit(); | 862 return emptyString16Bit(); |
863 | 863 |
864 UChar* destination; | 864 UChar* destination; |
865 String result = String::createUninitialized(length, destination); | 865 String result = String::createUninitialized(length, destination); |
866 | 866 |
867 StringImpl::copyChars(destination, source, length); | 867 StringImpl::copyChars(destination, source, length); |
868 | 868 |
869 return result; | 869 return result; |
870 } | 870 } |
871 | 871 |
872 String String::fromUTF8(const LChar* stringStart, size_t length) | 872 String String::fromUTF8(const LChar* stringStart, size_t length, bool strict) |
873 { | 873 { |
874 RELEASE_ASSERT(length <= std::numeric_limits<unsigned>::max()); | 874 RELEASE_ASSERT(length <= std::numeric_limits<unsigned>::max()); |
875 | 875 |
876 if (!stringStart) | 876 if (!stringStart) |
877 return String(); | 877 return String(); |
878 | 878 |
879 if (!length) | 879 if (!length) |
880 return emptyString(); | 880 return emptyString(); |
881 | 881 |
882 if (charactersAreAllASCII(stringStart, length)) | 882 if (charactersAreAllASCII(stringStart, length)) |
883 return StringImpl::create(stringStart, length); | 883 return StringImpl::create(stringStart, length); |
884 | 884 |
885 Vector<UChar, 1024> buffer(length); | 885 Vector<UChar, 1024> buffer(length); |
886 UChar* bufferStart = buffer.data(); | 886 UChar* bufferStart = buffer.data(); |
887 | 887 |
888 UChar* bufferCurrent = bufferStart; | 888 UChar* bufferCurrent = bufferStart; |
889 const char* stringCurrent = reinterpret_cast<const char*>(stringStart); | 889 const char* stringCurrent = reinterpret_cast<const char*>(stringStart); |
890 if (convertUTF8ToUTF16(&stringCurrent, reinterpret_cast<const char *>(string
Start + length), &bufferCurrent, bufferCurrent + buffer.size()) != conversionOK) | 890 if (convertUTF8ToUTF16(&stringCurrent, reinterpret_cast<const char*>(stringS
tart + length), &bufferCurrent, bufferCurrent + buffer.size(), nullptr, strict)
!= conversionOK) |
891 return String(); | 891 return String(); |
892 | 892 |
893 unsigned utf16Length = bufferCurrent - bufferStart; | 893 unsigned utf16Length = bufferCurrent - bufferStart; |
894 ASSERT(utf16Length < length); | 894 ASSERT(utf16Length < length); |
895 return StringImpl::create(bufferStart, utf16Length); | 895 return StringImpl::create(bufferStart, utf16Length); |
896 } | 896 } |
897 | 897 |
898 String String::fromUTF8(const LChar* string) | 898 String String::fromUTF8(const LChar* string) |
899 { | 899 { |
900 if (!string) | 900 if (!string) |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 buffer.append('\0'); | 1238 buffer.append('\0'); |
1239 return buffer; | 1239 return buffer; |
1240 } | 1240 } |
1241 | 1241 |
1242 Vector<char> asciiDebug(String& string) | 1242 Vector<char> asciiDebug(String& string) |
1243 { | 1243 { |
1244 return asciiDebug(string.impl()); | 1244 return asciiDebug(string.impl()); |
1245 } | 1245 } |
1246 | 1246 |
1247 #endif | 1247 #endif |
OLD | NEW |