summaryrefslogtreecommitdiffstats
path: root/base/sys_string_conversions_mac.mm
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-18 21:39:23 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-18 21:39:23 +0000
commitf224d57a86d8ed1ed6c4bca3c8a7150bf3c0ed14 (patch)
treef6305290a1c4781138d7d5a4f410915846ae6766 /base/sys_string_conversions_mac.mm
parent7a0220b27d9d9a9e5b870411c6a18edca1981767 (diff)
downloadchromium_src-f224d57a86d8ed1ed6c4bca3c8a7150bf3c0ed14.zip
chromium_src-f224d57a86d8ed1ed6c4bca3c8a7150bf3c0ed14.tar.gz
chromium_src-f224d57a86d8ed1ed6c4bca3c8a7150bf3c0ed14.tar.bz2
Now that we deal with string16s, provide some useful conversions for them.
Review URL: http://codereview.chromium.org/21473 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9970 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/sys_string_conversions_mac.mm')
-rw-r--r--base/sys_string_conversions_mac.mm27
1 files changed, 19 insertions, 8 deletions
diff --git a/base/sys_string_conversions_mac.mm b/base/sys_string_conversions_mac.mm
index 0da99f1..d0b2b235c 100644
--- a/base/sys_string_conversions_mac.mm
+++ b/base/sys_string_conversions_mac.mm
@@ -115,17 +115,11 @@ static CFStringRef STLStringToCFStringWithEncodingsT(
// when strings don't carry BOMs, as they typically won't.
static const CFStringEncoding kNarrowStringEncoding = kCFStringEncodingUTF8;
#ifdef __BIG_ENDIAN__
-#if defined(WCHAR_T_IS_UTF16)
-static const CFStringEncoding kWideStringEncoding = kCFStringEncodingUTF16BE;
-#elif defined(WCHAR_T_IS_UTF32)
+static const CFStringEncoding kMediumStringEncoding = kCFStringEncodingUTF16BE;
static const CFStringEncoding kWideStringEncoding = kCFStringEncodingUTF32BE;
-#endif // WCHAR_T_IS_UTF32
#elif defined(__LITTLE_ENDIAN__)
-#if defined(WCHAR_T_IS_UTF16)
-static const CFStringEncoding kWideStringEncoding = kCFStringEncodingUTF16LE;
-#elif defined(WCHAR_T_IS_UTF32)
+static const CFStringEncoding kMediumStringEncoding = kCFStringEncodingUTF16LE;
static const CFStringEncoding kWideStringEncoding = kCFStringEncodingUTF32LE;
-#endif // WCHAR_T_IS_UTF32
#endif // __LITTLE_ENDIAN__
} // namespace
@@ -154,6 +148,10 @@ CFStringRef SysUTF8ToCFStringRef(const std::string& utf8) {
return STLStringToCFStringWithEncodingsT(utf8, kNarrowStringEncoding);
}
+CFStringRef SysUTF16ToCFStringRef(const string16& utf16) {
+ return STLStringToCFStringWithEncodingsT(utf16, kMediumStringEncoding);
+}
+
CFStringRef SysWideToCFStringRef(const std::wstring& wide) {
return STLStringToCFStringWithEncodingsT(wide, kWideStringEncoding);
}
@@ -162,6 +160,10 @@ NSString* SysUTF8ToNSString(const std::string& utf8) {
return CFTypeRefToNSObjectAutorelease(SysUTF8ToCFStringRef(utf8));
}
+NSString* SysUTF16ToNSString(const string16& utf16) {
+ return CFTypeRefToNSObjectAutorelease(SysUTF16ToCFStringRef(utf16));
+}
+
NSString* SysWideToNSString(const std::wstring& wide) {
return CFTypeRefToNSObjectAutorelease(SysWideToCFStringRef(wide));
}
@@ -171,6 +173,11 @@ std::string SysCFStringRefToUTF8(CFStringRef ref) {
kNarrowStringEncoding);
}
+string16 SysCFStringRefToUTF16(CFStringRef ref) {
+ return CFStringToSTLStringWithEncodingT<string16>(ref,
+ kMediumStringEncoding);
+}
+
std::wstring SysCFStringRefToWide(CFStringRef ref) {
return CFStringToSTLStringWithEncodingT<std::wstring>(ref,
kWideStringEncoding);
@@ -180,6 +187,10 @@ std::string SysNSStringToUTF8(NSString* nsstring) {
return SysCFStringRefToUTF8(reinterpret_cast<CFStringRef>(nsstring));
}
+string16 SysNSStringToUTF16(NSString* nsstring) {
+ return SysCFStringRefToUTF16(reinterpret_cast<CFStringRef>(nsstring));
+}
+
std::wstring SysNSStringToWide(NSString* nsstring) {
return SysCFStringRefToWide(reinterpret_cast<CFStringRef>(nsstring));
}