Index: js/src/xpconnect/idl/Makefile.in
===================================================================
RCS file: /cvsroot/mozilla/js/src/xpconnect/idl/Makefile.in,v
retrieving revision 1.23
diff -p -u -8 -r1.23 Makefile.in
--- js/src/xpconnect/idl/Makefile.in 6 Apr 2004 04:25:48 -0000 1.23
+++ js/src/xpconnect/idl/Makefile.in 25 Jul 2006 20:20:48 -0000
@@ -58,16 +58,17 @@ XPIDLSRCS = \
nsIJSRuntimeService.idl \
nsIXPConnect.idl \
nsIXPCSecurityManager.idl \
nsIXPCScriptable.idl \
nsIScriptError.idl \
nsIXPCScriptNotify.idl \
nsIScriptableInterfaces.idl \
XPCIDispatch.idl \
+ nsIRegExp.idl \
$(NULL)
ifdef XPC_IDISPATCH_SUPPORT
XPIDLSRCS += \
nsIDispatchSupport.idl \
nsIActiveXSecurityPolicy.idl \
$(NULL)
endif
Index: js/src/xpconnect/idl/nsIRegExp.idl
===================================================================
RCS file: js/src/xpconnect/idl/nsIRegExp.idl
diff -N js/src/xpconnect/idl/nsIRegExp.idl
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ js/src/xpconnect/idl/nsIRegExp.idl 25 Jul 2006 20:20:48 -0000
@@ -0,0 +1,110 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is XPCOM Regular Expressions.
+ *
+ * The Initial Developer of the Original Code is
+ * Mike Shaver <shaver@mozilla.org>.
+ * Portions created by the Initial Developer are Copyright (C) 2002
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Alexander J. Vincent <ajvincent@gmail.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "nsISupports.idl"
+
+[scriptable, uuid(96f6a218-4ca7-4b60-94c6-11617819551b)]
+interface nsIRegExp : nsISupports {
+ /**
+ * Match pattern against target (flags for case-insensitivity, etc.)
+ *
+ * @param aTarget The string value to search.
+ *
+ * @return True if the pattern matched.
+ */
+ boolean test(in AString aTarget);
+
+ /**
+ * Match pattern against target (flags for case-insensitivity, etc.)
+ *
+ * @param aTarget The string value to search.
+ * @param aCount Object with value property reflecting length of array.
+ * @param aValues Object with value property reflecting array of matches.
+ */
+ void exec(in AString aTarget,
+ out unsigned long aCount,
+ [retval, array, size_is(aCount)] out wstring aValues);
+};
+
+[scriptable, uuid(ee6ce775-9bf8-4461-aa8a-3742cf7bd9ec)]
+interface nsIRegExpService : nsISupports
+{
+ const long GLOBAL = 1 << 0;
+ const long CASE_INSENSITIVE = 1 << 1;
+ const long MULTI_LINE = 1 << 2;
+
+ /**
+ * Match pattern against target (flags for case-insensitivity, etc.)
+ *
+ * @param aPattern ECMAScript RegExp pattern, without opening or closing
+ * slashes.
+ * @param aTarget The string value to search.
+ * @param aFlags Bitwise flags indicating search flags
+ *
+ * @return True if the pattern matched.
+ */
+ boolean search(in AString aPattern,
+ in AString aTarget,
+ in PRUint32 aFlags);
+
+ /**
+ * Match pattern against target (flags for case-insensitivity, etc.)
+ *
+ * @param aPattern ECMAScript RegExp pattern, without opening or closing
+ slashes.
+ * @param aTarget The string value to search.
+ * @param aFlags Bitwise flags indicating search flags.
+ * @param aCount Object with value property reflecting length of array.
+ * @param aValues Object with value property reflecting array of matches.
+ */
+ void match(in AString aPattern,
+ in AString aTarget,
+ in PRUint32 aFlags,
+ out unsigned long aCount,
+ [retval, array, size_is(aCount)] out wstring aValues);
+
+ /**
+ * Get a compiled regular expression for repeated use.
+ *
+ * @param aPattern ECMAScript RegExp pattern, without opening or closing
+ slashes.
+ * @param aFlags Bitwise flags indicating search flags.
+ *
+ * @return nsIRegExp object wrapping compiled regular expression.
+ */
+ nsIRegExp compile(in AString aPattern, in PRUint32 aFlags);
+};
Index: js/src/xpconnect/src/Makefile.in
===================================================================
RCS file: /cvsroot/mozilla/js/src/xpconnect/src/Makefile.in,v
retrieving revision 1.83
diff -p -u -8 -r1.83 Makefile.in
--- js/src/xpconnect/src/Makefile.in 24 Feb 2006 17:50:29 -0000 1.83
+++ js/src/xpconnect/src/Makefile.in 25 Jul 2006 20:20:48 -0000
@@ -105,16 +105,18 @@ CPPSRCS += XPCDispObject.cpp \
XPCIDispatchExtension.cpp \
XPCDispParams.cpp \
XPCDispParamPropJSClass.cpp \
XPCIDispatchClassInfo.cpp \
nsDispatchSupport.cpp \
$(NULL)
endif
+EXTRA_COMPONENTS = nsRegExpService.js
+
include $(topsrcdir)/config/config.mk
LOCAL_INCLUDES = \
-I$(srcdir)/../loader \
$(NULL)
EXTRA_DSO_LDOPTS += \
$(MOZ_COMPONENT_LIBS) \
Index: js/src/xpconnect/src/nsRegExpService.js
===================================================================
RCS file: js/src/xpconnect/src/nsRegExpService.js
diff -N js/src/xpconnect/src/nsRegExpService.js
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ js/src/xpconnect/src/nsRegExpService.js 25 Jul 2006 20:20:49 -0000
@@ -0,0 +1,175 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is XPCOM Regular Expressions.
+ *
+ * The Initial Developer of the Original Code is
+ * Alexander J. Vincent <ajvincent@gmail.com>.
+ * Portions created by the Initial Developer are Copyright (C) 2006
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+var componentName = "ECMAScript Regular Expression Service"
+var componentId = Components.ID("{4faf8501-09c3-4320-b3d6-6639e7c66490}");
+var contractId = "@mozilla.org/regular-expression-service;1";
+
+function nsIRegExp(aPattern, aFlags)
+{
+ const reInterface = Components.interfaces.nsIRegExpService;
+ var flags = "";
+ if (aFlags & reInterface.GLOBAL)
+ flags += "g";
+ if (aFlags & reInterface.CASE_INSENSITIVE)
+ flags += "i";
+ if (aFlags & reInterface.MULTI_LINE)
+ flags += "m";
+
+ this.regexp = new RegExp(aPattern, flags);
+}
+nsIRegExp.prototype = {
+ // Internal use only.
+ compile: function compile()
+ {
+ return this.regexp.compile();
+ },
+
+ // nsIRegExp
+ test: function test(aTarget)
+ {
+ return this.regexp.test(aTarget);
+ },
+
+ // nsIRegExp
+ exec: function exec(aTarget, aCount, aValues)
+ {
+ aValues.value = this.regexp.exec(aTarget);
+ aCount.value = aValues.value.length;
+ },
+
+ // nsISupports
+ QueryInterface: function QueryInterface(aIID) {
+ if (aIID.equals(Components.interfaces.nsIRegExp) ||
+ aIID.equals(Components.interfaces.nsISupports))
+ return this;
+
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+ }
+};
+
+// Component constructor.
+function nsIRegExpService() {
+}
+nsIRegExpService.prototype = {
+ // nsIRegExpService
+ search: function search(aPattern, aTarget, aFlags)
+ {
+ var regexp = new nsIRegExp(aPattern, aFlags);
+ return regexp.test(aTarget);
+ },
+
+ // nsIRegExpService
+ match: function match(aPattern,
+ aTarget,
+ aFlags,
+ aCount,
+ aValues)
+ {
+ var regexp = new nsIRegExp(aPattern, aFlags);
+ regexp.exec(aTaget, aCount, aValues);
+ },
+
+ // nsIRegExpService
+ compile: function compile(aPattern, aFlags)
+ {
+ var regexp = new nsIRegExp(aPattern, aFlags);
+ return regexp.compile();
+ },
+
+ // nsISupports
+ QueryInterface: function QueryInterface(aIID) {
+ if (aIID.equals(Components.interfaces.nsIRegExpService) ||
+ aIID.equals(Components.interfaces.nsISupports))
+ return this;
+
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+ }
+};
+
+/* Factories in modules cause leaks according to
+ https://bugzilla.mozilla.org/show_bug.cgi?id=168411#c28
+ */
+
+var factory = {
+ createInstance: function createInstance(outer, iid) {
+ if (outer != null) {
+ throw Components.results.NS_ERROR_NO_AGGREGATION;
+ return (new nsIRegExpService()).QueryInterface(iid);
+ }
+ }
+};
+
+/* The rest of this code is largely borrowed from "Creating Applications With
+ * Mozilla", http://books.mozdev.org, Chapter 8.
+ */
+var Module = {
+ registerSelf: function registerSelf(compMgr, fileSpec, location, type) {
+ compReg = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
+ compReg.registerFactoryLocation(componentId,
+ componentName,
+ contractId,
+ fileSpec,
+ location,
+ type );
+ },
+
+ getClassObject: function(compMgr, aCID, aIID) {
+ if (!aCID.equals(componentId)) {
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+ }
+ if (!aIID.equals(Components.interfaces.nsIFactory)) {
+ throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
+ }
+ return factory;
+ },
+
+ canUnload: function() {
+ return true;
+ },
+
+ QueryInterface: function QueryInterface(aIID) {
+ if (aIID.equals(Components.interfaces.nsIModule) ||
+ (aIID.equals(Components.interfaces.nsISupports)))
+ return this;
+
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+ }
+};
+
+function NSGetModule(compMgr, fileSpec) {
+ return Module;
+}