summaryrefslogtreecommitdiffstats
path: root/webkit/api
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-11 03:37:55 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-11 03:37:55 +0000
commit9c5645b5f8af3c04528caef61c59e2754f79288b (patch)
tree76b465be9c92307ff53d3e793d727084c807c681 /webkit/api
parente3ecc42b385ab2e6dc6e37c11cc52e15fb755185 (diff)
downloadchromium_src-9c5645b5f8af3c04528caef61c59e2754f79288b.zip
chromium_src-9c5645b5f8af3c04528caef61c59e2754f79288b.tar.gz
chromium_src-9c5645b5f8af3c04528caef61c59e2754f79288b.tar.bz2
Add some helper methods for constructing a WebCString from UTF16 input,
assuming a UTF16 to UTF8 conversion. Also, includes a .utf16() method on WebCString to get a UTF16 string out. These methods mirror the similar methods for UTF8 on WebString. Make use of these conversion methods in a few more places. R=dglazkov BUG=none TEST=none Review URL: http://codereview.chromium.org/164274 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23010 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/api')
-rw-r--r--webkit/api/public/WebCString.h19
-rw-r--r--webkit/api/public/WebString.h1
-rw-r--r--webkit/api/src/WebCString.cpp28
3 files changed, 41 insertions, 7 deletions
diff --git a/webkit/api/public/WebCString.h b/webkit/api/public/WebCString.h
index 7b4cc4e..3e12ff0 100644
--- a/webkit/api/public/WebCString.h
+++ b/webkit/api/public/WebCString.h
@@ -1,10 +1,10 @@
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
@@ -14,7 +14,7 @@
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -40,8 +40,8 @@ namespace WebCore { class CString; }
#endif
namespace WebKit {
-
class WebCStringPrivate;
+ class WebString;
// A single-byte string container with unspecified encoding. It is
// inexpensive to copy a WebCString object.
@@ -77,6 +77,11 @@ namespace WebKit {
bool isEmpty() const { return length() == 0; }
bool isNull() const { return m_private == 0; }
+ WEBKIT_API WebString utf16() const;
+
+ WEBKIT_API static WebCString fromUTF16(const WebUChar* data, size_t length);
+ WEBKIT_API static WebCString fromUTF16(const WebUChar* data);
+
#if WEBKIT_IMPLEMENTATION
WebCString(const WebCore::CString&);
WebCString& operator=(const WebCore::CString&);
@@ -98,6 +103,12 @@ namespace WebKit {
size_t len = length();
return len ? std::string(data(), len) : std::string();
}
+
+ template <class UTF16String>
+ static WebCString fromUTF16(const UTF16String& s)
+ {
+ return fromUTF16(s.data(), s.length());
+ }
#endif
private:
diff --git a/webkit/api/public/WebString.h b/webkit/api/public/WebString.h
index bf59854..5107de4 100644
--- a/webkit/api/public/WebString.h
+++ b/webkit/api/public/WebString.h
@@ -86,6 +86,7 @@ namespace WebKit {
WebString(const WebCore::String&);
WebString& operator=(const WebCore::String&);
operator WebCore::String() const;
+
WebString(const WebCore::AtomicString&);
WebString& operator=(const WebCore::AtomicString&);
operator WebCore::AtomicString() const;
diff --git a/webkit/api/src/WebCString.cpp b/webkit/api/src/WebCString.cpp
index a387a72..8e10659 100644
--- a/webkit/api/src/WebCString.cpp
+++ b/webkit/api/src/WebCString.cpp
@@ -1,10 +1,10 @@
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
@@ -14,7 +14,7 @@
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -31,7 +31,10 @@
#include "config.h"
#include "WebCString.h"
+#include "WebString.h"
+
#include "CString.h"
+#include "TextEncoding.h"
namespace WebKit {
@@ -75,6 +78,25 @@ const char* WebCString::data() const
return const_cast<WebCStringPrivate*>(m_private)->data();
}
+WebString WebCString::utf16() const
+{
+ return WebCore::UTF8Encoding().decode(data(), length());
+}
+
+WebCString WebCString::fromUTF16(const WebUChar* data, size_t length)
+{
+ return WebCore::UTF8Encoding().encode(
+ data, length, WebCore::QuestionMarksForUnencodables);
+}
+
+WebCString WebCString::fromUTF16(const WebUChar* data)
+{
+ size_t len = 0;
+ while (data[len] != WebUChar(0))
+ len++;
+ return fromUTF16(data, len);
+}
+
WebCString::WebCString(const WebCore::CString& s)
: m_private(static_cast<WebCStringPrivate*>(s.buffer()))
{