2009-12-04 James Hawkins <jhawkins@chromium.org>
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Dec 2009 00:24:28 +0000 (00:24 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Dec 2009 00:24:28 +0000 (00:24 +0000)
        Reviewed by Darin Fisher.

        https://bugs.webkit.org/show_bug.cgi?id=32095
        Implement WebRegularExpression, a WebKit API for accessing
        WebCore::RegularExpression.

        * WebKit.gyp:
        * public/WebRegularExpression.h: Added.
        * public/WebTextCaseSensitivity.h: Added.
        (WebKit::):
        * src/AssertMatchingEnums.cpp:
        * src/WebRegularExpression.cpp: Added.
        (WebKit::WebRegularExpression::WebRegularExpression):
        (WebKit::WebRegularExpression::~WebRegularExpression):
        (WebKit::WebRegularExpression::match):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@51720 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/chromium/ChangeLog
WebKit/chromium/WebKit.gyp
WebKit/chromium/public/WebRegularExpression.h [new file with mode: 0644]
WebKit/chromium/public/WebTextCaseSensitivity.h [new file with mode: 0644]
WebKit/chromium/src/AssertMatchingEnums.cpp
WebKit/chromium/src/WebRegularExpression.cpp [new file with mode: 0644]

index 2697e6d..445f9ca 100644 (file)
@@ -1,3 +1,21 @@
+2009-12-04  James Hawkins  <jhawkins@chromium.org>
+
+        Reviewed by Darin Fisher.
+
+        https://bugs.webkit.org/show_bug.cgi?id=32095
+        Implement WebRegularExpression, a WebKit API for accessing
+        WebCore::RegularExpression.
+
+        * WebKit.gyp:
+        * public/WebRegularExpression.h: Added.
+        * public/WebTextCaseSensitivity.h: Added.
+        (WebKit::):
+        * src/AssertMatchingEnums.cpp:
+        * src/WebRegularExpression.cpp: Added.
+        (WebKit::WebRegularExpression::WebRegularExpression):
+        (WebKit::WebRegularExpression::~WebRegularExpression):
+        (WebKit::WebRegularExpression::match):
+
 2009-12-04  Peter Kasting  <pkasting@google.com>
 
         Reviewed by Darin Fisher.
 2009-12-04  Peter Kasting  <pkasting@google.com>
 
         Reviewed by Darin Fisher.
index ab08dc9..d7bd30d 100644 (file)
                 'public/WebPopupMenuInfo.h',
                 'public/WebRange.h',
                 'public/WebRect.h',
                 'public/WebPopupMenuInfo.h',
                 'public/WebRange.h',
                 'public/WebRect.h',
+                'public/WebRegularExpression.h',
                 'public/WebRuntimeFeatures.h',
                 'public/WebScreenInfo.h',
                 'public/WebScriptController.h',
                 'public/WebRuntimeFeatures.h',
                 'public/WebScreenInfo.h',
                 'public/WebScriptController.h',
                 'public/WebStorageNamespace.h',
                 'public/WebString.h',
                 'public/WebTextAffinity.h',
                 'public/WebStorageNamespace.h',
                 'public/WebString.h',
                 'public/WebTextAffinity.h',
+                'public/WebTextCaseSensitivity.h',
                 'public/WebTextDirection.h',
                 'public/WebURL.h',
                 'public/WebURLError.h',
                 'public/WebTextDirection.h',
                 'public/WebURL.h',
                 'public/WebURLError.h',
                 'src/WebPopupMenuImpl.cpp',
                 'src/WebPopupMenuImpl.h',
                 'src/WebRange.cpp',
                 'src/WebPopupMenuImpl.cpp',
                 'src/WebPopupMenuImpl.h',
                 'src/WebRange.cpp',
+                'src/WebRegularExpression.cpp',
                 'src/WebRuntimeFeatures.cpp',
                 'src/WebScriptController.cpp',
                 'src/WebSearchableFormData.cpp',
                 'src/WebRuntimeFeatures.cpp',
                 'src/WebScriptController.cpp',
                 'src/WebSearchableFormData.cpp',
diff --git a/WebKit/chromium/public/WebRegularExpression.h b/WebKit/chromium/public/WebRegularExpression.h
new file mode 100644 (file)
index 0000000..bdf72d8
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * 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
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebRegularExpression_h
+#define WebRegularExpression_h
+
+#include "WebCommon.h"
+#include "WebNonCopyable.h"
+#include "WebTextCaseSensitivity.h"
+
+namespace WebKit {
+
+class WebRegularExpressionPrivate;
+class WebString;
+
+class WebRegularExpression : public WebNonCopyable {
+public:
+    WEBKIT_API WebRegularExpression(const WebString& pattern, WebTextCaseSensitivity);
+    WEBKIT_API ~WebRegularExpression();
+
+    WEBKIT_API int match(const WebString&, int startFrom = 0, int* matchLength = 0) const;
+
+private:
+    WebRegularExpressionPrivate* m_private;
+};
+
+} // namespace WebKit
+
+#endif
diff --git a/WebKit/chromium/public/WebTextCaseSensitivity.h b/WebKit/chromium/public/WebTextCaseSensitivity.h
new file mode 100644 (file)
index 0000000..ae5860c
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * 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
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebTextCaseSensitivity_h
+#define WebTextCaseSensitivity_h
+
+namespace WebKit {
+
+// These constants specify the preferred case sensitivity.
+enum WebTextCaseSensitivity {
+    WebTextCaseSensitive,   // String matching is case-sensitive.
+    WebTextCaseInsensitive, // String matching is case-insensitive.
+};
+
+} // namespace WebKit
+
+#endif
index f349cc3..35e2057 100644 (file)
@@ -41,6 +41,7 @@
 #include "NotificationPresenter.h"
 #include "PasteboardPrivate.h"
 #include "PlatformCursor.h"
 #include "NotificationPresenter.h"
 #include "PasteboardPrivate.h"
 #include "PlatformCursor.h"
+#include "StringImpl.h"
 #include "TextAffinity.h"
 #include "WebAccessibilityObject.h"
 #include "WebApplicationCacheHost.h"
 #include "TextAffinity.h"
 #include "WebAccessibilityObject.h"
 #include "WebApplicationCacheHost.h"
@@ -51,6 +52,7 @@
 #include "WebMediaPlayer.h"
 #include "WebNotificationPresenter.h"
 #include "WebTextAffinity.h"
 #include "WebMediaPlayer.h"
 #include "WebNotificationPresenter.h"
 #include "WebTextAffinity.h"
+#include "WebTextCaseSensitivity.h"
 #include <wtf/Assertions.h>
 
 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, webcore_name) \
 #include <wtf/Assertions.h>
 
 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, webcore_name) \
@@ -272,3 +274,6 @@ COMPILE_ASSERT_MATCHING_ENUM(WebNotificationPresenter::PermissionDenied, Notific
 
 COMPILE_ASSERT_MATCHING_ENUM(WebTextAffinityUpstream, UPSTREAM);
 COMPILE_ASSERT_MATCHING_ENUM(WebTextAffinityDownstream, DOWNSTREAM);
 
 COMPILE_ASSERT_MATCHING_ENUM(WebTextAffinityUpstream, UPSTREAM);
 COMPILE_ASSERT_MATCHING_ENUM(WebTextAffinityDownstream, DOWNSTREAM);
+
+COMPILE_ASSERT_MATCHING_ENUM(WebTextCaseSensitive, TextCaseSensitive);
+COMPILE_ASSERT_MATCHING_ENUM(WebTextCaseInsensitive, TextCaseInsensitive);
diff --git a/WebKit/chromium/src/WebRegularExpression.cpp b/WebKit/chromium/src/WebRegularExpression.cpp
new file mode 100644 (file)
index 0000000..558b750
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * 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
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebRegularExpression.h"
+
+#include "RegularExpression.h"
+#include "WebString.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+class WebRegularExpressionPrivate : public RegularExpression {
+};
+
+WebRegularExpression::WebRegularExpression(const WebString& pattern,
+                                           WebTextCaseSensitivity caseSensitivity)
+{
+    TextCaseSensitivity sensitivity = static_cast<TextCaseSensitivity>(caseSensitivity);
+    RegularExpression* re = new RegularExpression(pattern, sensitivity);
+    m_private = static_cast<WebRegularExpressionPrivate*>(re);
+}
+
+WebRegularExpression::~WebRegularExpression()
+{
+    delete m_private;
+}
+
+int WebRegularExpression::match(const WebString& str,
+                                int startFrom,
+                                int* matchLength) const
+{
+    if (!m_private)
+        return -1;
+
+    return m_private->match(str, startFrom, matchLength);
+}
+
+} // namespace WebKit