2 * Copyright (C) 2006, 2012 Apple Computer, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
23 #include "wtf/text/WTFString.h"
27 #include "wtf/RetainPtr.h"
28 #include <CoreFoundation/CoreFoundation.h>
32 String::String(CFStringRef str
)
37 CFIndex size
= CFStringGetLength(str
);
39 m_impl
= StringImpl::empty();
41 Vector
<LChar
, 1024> lcharBuffer(size
);
43 CFIndex convertedsize
= CFStringGetBytes(str
, CFRangeMake(0, size
), kCFStringEncodingISOLatin1
, 0, false, lcharBuffer
.data(), size
, &usedBufLen
);
44 if ((convertedsize
== size
) && (usedBufLen
== size
)) {
45 m_impl
= StringImpl::create(lcharBuffer
.data(), size
);
49 Vector
<UChar
, 1024> buffer(size
);
50 CFStringGetCharacters(str
, CFRangeMake(0, size
), (UniChar
*)buffer
.data());
51 m_impl
= StringImpl::create(buffer
.data(), size
);
55 RetainPtr
<CFStringRef
> String::createCFString() const
60 return m_impl
->createCFString();