OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) | 4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) |
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All r ights reserved. | 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All r ights reserved. |
6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) | 6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 1875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1886 } else { | 1886 } else { |
1887 // Cases 2 & 4. | 1887 // Cases 2 & 4. |
1888 memcpy(data + dstOffset, characters16() + srcSegmentStart, srcSegmentLen gth * sizeof(UChar)); | 1888 memcpy(data + dstOffset, characters16() + srcSegmentStart, srcSegmentLen gth * sizeof(UChar)); |
1889 } | 1889 } |
1890 | 1890 |
1891 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); | 1891 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); |
1892 | 1892 |
1893 return newImpl.release(); | 1893 return newImpl.release(); |
1894 } | 1894 } |
1895 | 1895 |
1896 PassRefPtr<StringImpl> StringImpl::replaceUnpairedSurrogates() | |
Nils Barth (inactive)
2014/06/11 03:54:26
Could you link to spec, and quote spec in comments
jsbell
2014/06/12 17:45:55
Done.
| |
1897 { | |
1898 if (is8Bit()) | |
1899 return this; | |
1900 | |
1901 const UChar* characters = characters16(); | |
1902 const unsigned length = m_length; | |
1903 | |
1904 // Scan to see if there are any unmatched surrogates. | |
Nils Barth (inactive)
2014/06/11 03:54:26
Could you comment that this is a Blink-specific op
jsbell
2014/06/12 17:45:55
Done.
| |
1905 bool unmatched = false; | |
Nils Barth (inactive)
2014/06/11 03:54:26
This block would be a bit simpler as a helper func
jsbell
2014/06/12 17:45:55
Done.
| |
1906 for (unsigned i = 0; i < length; ++i) { | |
1907 UChar c = characters[i]; | |
1908 if (c < 0xD800 || c > 0xDFFF) { | |
Nils Barth (inactive)
2014/06/11 03:54:26
Understand "want to match below", though style-wis
jsbell
2014/06/12 17:45:56
Done.
| |
1909 // Non-surrogate - no-op. | |
1910 } else if (0xDC00 <= c && c <= 0xDFFF) { | |
1911 // Unmatched trail surrogate. | |
1912 unmatched = true; | |
1913 break; | |
1914 } else if (i == length - 1) { | |
1915 // Unmatched lead surrogate at EOF. | |
1916 unmatched = true; | |
1917 break; | |
1918 } else { | |
1919 UChar d = characters[i + 1]; | |
1920 if (0xDC00 <= d && d <= 0xDFFF) { | |
1921 // Matching trail surrogate. | |
1922 ++i; | |
1923 continue; | |
1924 } | |
1925 // Unmatched lead. | |
1926 unmatched = true; | |
1927 break; | |
1928 } | |
1929 } | |
1930 if (!unmatched) | |
1931 return this; | |
1932 | |
1933 UChar* data; | |
1934 RefPtr<StringImpl> newImpl = createUninitialized(length, data); | |
1935 for (unsigned i = 0; i < length; ++i) { | |
1936 UChar c = characters[i]; | |
1937 if (c < 0xD800 || c > 0xDFFF) { | |
1938 // Non-surrogate. | |
1939 data[i] = c; | |
1940 } else if (0xDC00 <= c && c <= 0xDFFF) { | |
1941 // Unmatched trail surrogate. | |
1942 data[i] = Unicode::replacementCharacter; | |
1943 } else if (i == length - 1) { | |
Nils Barth (inactive)
2014/06/11 03:54:26
Could you add a comment stating:
// 0xD800 <= c &&
jsbell
2014/06/12 17:45:56
I added ASSERTs instead.
| |
1944 // Unmatched lead surrogate at EOF. | |
1945 data[i] = Unicode::replacementCharacter; | |
1946 } else { | |
1947 UChar d = characters[i + 1]; | |
1948 if (0xDC00 <= d && d <= 0xDFFF) { | |
1949 // Matching trail surrogate. | |
1950 data[i] = c; | |
Nils Barth (inactive)
2014/06/11 03:54:26
Could you comment that we're not translating the s
jsbell
2014/06/12 17:45:55
Done.
| |
1951 data[i + 1] = d; | |
1952 ++i; | |
1953 } else { | |
1954 // Unmatched lead. | |
1955 data[i] = Unicode::replacementCharacter; | |
1956 } | |
1957 } | |
1958 } | |
1959 | |
1960 return newImpl.release(); | |
1961 } | |
1962 | |
Nils Barth (inactive)
2014/06/11 03:54:26
nit: one blank line, right?
jsbell
2014/06/12 17:45:55
Done.
| |
1963 | |
1896 PassRefPtr<StringImpl> StringImpl::upconvertedString() | 1964 PassRefPtr<StringImpl> StringImpl::upconvertedString() |
1897 { | 1965 { |
1898 if (is8Bit()) | 1966 if (is8Bit()) |
1899 return String::make16BitFrom8BitSource(characters8(), m_length).releaseI mpl(); | 1967 return String::make16BitFrom8BitSource(characters8(), m_length).releaseI mpl(); |
1900 return this; | 1968 return this; |
1901 } | 1969 } |
1902 | 1970 |
1903 static inline bool stringImplContentEqual(const StringImpl* a, const StringImpl* b) | 1971 static inline bool stringImplContentEqual(const StringImpl* a, const StringImpl* b) |
1904 { | 1972 { |
1905 unsigned aLength = a->length(); | 1973 unsigned aLength = a->length(); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2099 | 2167 |
2100 size_t StringImpl::sizeInBytes() const | 2168 size_t StringImpl::sizeInBytes() const |
2101 { | 2169 { |
2102 size_t size = length(); | 2170 size_t size = length(); |
2103 if (!is8Bit()) | 2171 if (!is8Bit()) |
2104 size *= 2; | 2172 size *= 2; |
2105 return size + sizeof(*this); | 2173 return size + sizeof(*this); |
2106 } | 2174 } |
2107 | 2175 |
2108 } // namespace WTF | 2176 } // namespace WTF |
OLD | NEW |