Example #1
0
        void parseAndPersistBehaviors(JsString sheet)
        {
            JsString       classSelector;
            JsRegExpResult randoriVendorItemsResult;
            JsRegExpResult randoriVendorItemInfoResult;
            JsRegExpResult CSSClassSelectorNameResult;

            /*
             * This regular expression then grabs all of the class selectors
             * \.[\w\W]*?\}
             *
             * This expression finds an -randori vendor prefix styles in the current cssSelector and returns 2 groups, the first
             * is the type, the second is the value
             *
             * \s?-randori-([\w\W]+?)\s?:\s?["']?([\w\W]+?)["']?;
             *
             */

            var allClassSelectors = new JsRegExp(@"^[\w\W]*?\}", "gm");

            const string RANDORI_VENDOR_ITEM_EXPRESSION = @"\s?-randori-([\w\W]+?)\s?:\s?[""']?([\w\W]+?)[""']?;";
            //These two are the same save for the global flag. The global flag seems to disable all capturing groups immediately
            var anyVendorItems = new JsRegExp(RANDORI_VENDOR_ITEM_EXPRESSION, "g");

            //This is the same as the one in findRelevant classes save for the the global flag... which is really important
            //The global flag seems to disable all capturing groups immediately
            var eachVendorItem = new JsRegExp(RANDORI_VENDOR_ITEM_EXPRESSION);

            var      classSelectorName = new JsRegExp(@"^(.+?)\s+?{", "m");
            JsString CSSClassSelectorName;
            JsString randoriVendorItemStr;

            var selectors = sheet.match(allClassSelectors);

            if (selectors != null)
            {
                for (int i = 0; i < selectors.length; i++)
                {
                    classSelector = selectors[i];

                    randoriVendorItemsResult = classSelector.match(anyVendorItems);
                    if (randoriVendorItemsResult != null)
                    {
                        CSSClassSelectorNameResult = classSelector.match(classSelectorName);
                        CSSClassSelectorName       = CSSClassSelectorNameResult[1];

                        for (int j = 0; j < randoriVendorItemsResult.length; j++)
                        {
                            randoriVendorItemStr        = randoriVendorItemsResult[j];
                            randoriVendorItemInfoResult = randoriVendorItemStr.match(eachVendorItem);
                            map.addCSSEntry(CSSClassSelectorName, randoriVendorItemInfoResult[1], randoriVendorItemInfoResult[2]);
                            if (HtmlContext.window.console != null)
                            {
                                HtmlContext.console.log(CSSClassSelectorName + " specifies a " + randoriVendorItemInfoResult[1] + " implemented by class " + randoriVendorItemInfoResult[2]);
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        private void sendTranslationRequest(Timer timer)
        {
            var domainLabels = new JsObject <JsArray <JsString> >();

            var            keyValuePair = new JsRegExp(@"\[(labels|messages|reference)\.(\w+)\]");
            JsRegExpResult result;

            JsString domain;
            JsString key;

            //The translation translator works on domains, so we need to break up the available items we have and make appropriate requests to the translator
            foreach (JsString expression in pendingTranslations)
            {
                result = expression.match(keyValuePair);
                domain = result[1];
                key    = result[2];

                if (domainLabels[domain] == null)
                {
                    domainLabels[domain] = new JsArray <JsString>();
                }

                domainLabels[domain].push(key);
            }

            foreach (JsString domainEntry in domainLabels)
            {
                translator.translate(domainEntry, domainLabels[domainEntry]);
            }
        }
 public JsString parse( JsString content )
 {
     //We need to get rid of the body element and maybe choose to do away with other things like script
     var bodyRegex = new JsRegExp(@"(</?)body", "gi");
     var sanitizedContent = content.replace(bodyRegex,"$1div");
     return sanitizedContent;
 }
        public jQuery renderTemplateClone(JsObject data )
        {
            JsString token;
            JsString field;
            dynamic dereferencedValue;
            var keyRegex = new JsRegExp(@"\{[\w\W]+?\}", "g");
            var foundKeys = templateAsString.match(keyRegex);
            var output = templateAsString;

            if (foundKeys != null) {
                for ( int j = 0; j < foundKeys.length; j++ ) {

                    token = foundKeys[ j ];
                    field = returnFieldName( token );

                    if (field.indexOf(".") != -1) {
                        dereferencedValue = resolveComplexName(data, field);
                    } else if (field != "*") {
                        dereferencedValue = data[field];
                    } else {
                        dereferencedValue = data;
                    }

                    output = output.replace(token, dereferencedValue);
                }
            }

            jQuery fragmentJquery = jQueryContext.J("<div></div>");
            fragmentJquery.append(output);

            return fragmentJquery;
        }
Example #5
0
        /**
         * Given a phone number, returns the phone number with all characters, other than numbers, stripped
         * @param {String} phone the phone number to normalize
         * @return {String} the normalized phone number
         * @static
         */
        static JsString normalizePhoneNumber(JsString phone)
        {
            phone = phone.toString();
            JsRegExp regex = new JsRegExp("[^\\d]", "g");

            return(phone.replace(regex, ""));
        }
Example #6
0
        public JsString parse(JsString content)
        {
            //We need to get rid of the body element and maybe choose to do away with other things like script
            var bodyRegex        = new JsRegExp(@"(</?)body", "gi");
            var sanitizedContent = content.replace(bodyRegex, "$1div");

            return(sanitizedContent);
        }
Example #7
0
		/// <summary>
		/// Converts the specified value.
		/// </summary>
		/// <param name="value">The value.</param>
		/// <exception cref="System.ArgumentNullException"></exception>
		/// <exception cref="System.FormatException"></exception>
		private JsNumber Convert(object value)
		{
			if (value == null)
				throw new ArgumentNullException();

			var regex = new JsRegExp(@"^-?([0-9]+)[^0-9]");
			var match = regex.exec(value.ToString());
			if (match == null)
				throw new FormatException();
			return new JsNumber(match[1].As<double>());
		}
Example #8
0
        static JsString getDirection()
        {
            var @checked = new jQuery("input:[type=radio]:checked")[0].id;
            var regex    = new JsRegExp("custom|customValue");

            if (regex.test(@checked))
            {
                return(new jQuery("#customValue").val().As <JsString>());
            }
            else
            {
                return(@checked);
            }
        }
        void parseResult(JsString responseText)
        {
            //get each line
            JsRegExp       eachLine       = new JsRegExp(@"[\w\W]+?[\n\r]+", "g");
            JsRegExpResult eachLineResult = responseText.match(eachLine);

            this.fileLoaded = true;

            if (eachLineResult != null)
            {
                for (int i = 0; i < eachLineResult.length; i++)
                {
                    parseLine(eachLineResult[i]);
                }
            }
        }
Example #10
0
        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.FormatException"></exception>
        private JsNumber Convert(object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException();
            }

            var regex = new JsRegExp(@"^-?([0-9]+)[^0-9]");
            var match = regex.exec(value.ToString());

            if (match == null)
            {
                throw new FormatException();
            }
            return(new JsNumber(match[1].As <double>()));
        }
Example #11
0
 // http://msdn.microsoft.com/en-us/library/ms537509(v=vs.85).aspx
 public static float GetIEVersion()
 {
     float rv = -1;
     var appName = navigator.appName;
     string agent = navigator.userAgent;
     if (appName == "Microsoft Internet Explorer")
     {
         var r = new JsRegExp("MSIE ([0-9]{1,}[\\.0-9]{0,})");
         var m = r.exec(agent);
         if (m != null)
         {
             rv = Std.ParseFloat(m[1]);
         }
     }
     return rv;
 }
Example #12
0
 protected string FormatUrl(string str, params string[] tmpArgs)
 {
     if (IsJavaScriptExecute()) {
         JsArray lArguments = JsContext.arguments.As<JsArray>();
         int len = lArguments.As<JsArray>().length;
         JsRegExp regExp = new JsRegExp(@"{\w+}");
         for (int i = 1; i < len; ++i) {
             JsString arg = lArguments.As<JsArray>()[i].As<JsString>();
             str = str.As<JsString>().replace(regExp, arg);
         }
     }
     else {
         str = FormatUrlInternal(str, tmpArgs);
     }
     return str;
 }
Example #13
0
 // http://msdn.microsoft.com/en-us/library/ms537509(v=vs.85).aspx
 public static float GetIEVersion()
 {
     float rv = -1;
     var appName = navigator.appName;
     string agent = navigator.userAgent;
     if (appName == "Microsoft Internet Explorer")
     {
         var r = new JsRegExp("MSIE ([0-9]{1,}[\\.0-9]{0,})");
         var m = r.exec(agent);
         if (m != null)
         {
             rv = Std.ParseFloat(m[1]);
         }
     }
     return rv;
 }
        public virtual string loadClass( JsString qualifiedClassName )
        {
            JsRegExp classNameRegex = new JsRegExp("\\.", "g");
            var potentialURL = qualifiedClassName.replace(classNameRegex, "/");
            potentialURL = dynamicClassBaseUrl + potentialURL;
            potentialURL += ".js";

            xmlHttpRequest.open("GET", potentialURL, false);
            xmlHttpRequest.send("");

            //Todo Need to handle other status than just 404
            if (xmlHttpRequest.status == 404) {
                //Todo This alert shouldnt be here, we should figure out a way to get it to the UI level
                HtmlContext.alert("Required Class " + qualifiedClassName + " cannot be loaded.");
                throw new JsError("Cannot continue, missing required class " + qualifiedClassName);
            }

            return ( xmlHttpRequest.responseText + "\n//@ sourceURL=" + potentialURL );
        }
        public string loadClass(JsString qualifiedClassName)
        {
            JsRegExp classNameRegex = new JsRegExp("\\.", "g");
            var      potentialURL   = qualifiedClassName.replace(classNameRegex, "/");

            potentialURL  = dynamicClassBaseUrl + potentialURL;
            potentialURL += ".js";

            xmlHttpRequest.open("GET", potentialURL, false);
            xmlHttpRequest.send("");

            //Todo Need to handle other status than just 404
            if (xmlHttpRequest.status == 404)
            {
                //Todo This alert shouldnt be here, we should figure out a way to get it to the UI level
                HtmlContext.alert("Required Class " + qualifiedClassName + " cannot be loaded.");
                throw new JsError("Cannot continue, missing required class " + qualifiedClassName);
            }

            return(xmlHttpRequest.responseText + "\n//@ sourceURL=" + potentialURL);
        }
Example #16
0
        public jQuery renderTemplateClone(JsObject data)
        {
            JsString token;
            JsString field;
            dynamic  dereferencedValue;
            var      keyRegex  = new JsRegExp(@"\{[\w\W]+?\}", "g");
            var      foundKeys = templateAsString.match(keyRegex);
            var      output    = templateAsString;

            if (foundKeys != null)
            {
                for (int j = 0; j < foundKeys.length; j++)
                {
                    token = foundKeys[j];
                    field = returnFieldName(token);

                    if (field.indexOf(".") != -1)
                    {
                        dereferencedValue = resolveComplexName(data, field);
                    }
                    else if (field != "*")
                    {
                        dereferencedValue = data[field];
                    }
                    else
                    {
                        dereferencedValue = data;
                    }

                    output = output.replace(token, dereferencedValue);
                }
            }

            jQuery fragmentJquery = jQueryContext.J("<div></div>");

            fragmentJquery.append(output);

            return(fragmentJquery);
        }
Example #17
0
        void parseLine(JsString line)
        {
            if (line.length == 0)
            {
                //empty line, bail
                return;
            }

            JsRegExp       isComment       = new JsRegExp(@"^[#!]");
            JsRegExpResult isCommentResult = line.match(isComment);

            if (isCommentResult != null)
            {
                //its a comment, bail
                return;
            }

            JsRegExp       tokenize       = new JsRegExp(@"^(\w+)\s?=\s?([\w\W]+?)[\n\r]+");
            JsRegExpResult tokenizeResult = line.match(tokenize);
            JsString       key;
            JsString       strValue;
            dynamic        value;

            if (tokenizeResult != null && tokenizeResult.length == 3)
            {
                key   = tokenizeResult[1];
                value = tokenizeResult[2];

                strValue = value;
                if (strValue.indexOf(",") != -1)
                {
                    //this is an array, tokenize it
                    value = strValue.split(',');
                }

                keyValuePairs[key] = value;
            }
        }
Example #18
0
 /// <summary>
 /// Adds a new singularization rule to the Inflector. See the intro docs for more information
 /// </summary>
 /// <param name="matcher"><p>The matcher regex</p>
 /// </param>
 /// <param name="replacer"><p>The replacement string, which can reference matches from the matcher argument</p>
 /// </param>
 public static void singular(JsRegExp matcher, JsString replacer)
 {
 }
Example #19
0
		public static string Split(string str, JsRegExp separator, double limit) { throw new NotImplementedException(); }
Example #20
0
 /// <summary>
 /// Adds a new singularization rule to the Inflector. ...
 /// </summary>
 public static object singular(JsRegExp matcher, JsString replacer)
 {
     return(null);
 }
Example #21
0
 public static string Split(string str, JsRegExp separator, double limit)
 {
     throw new NotImplementedException();
 }
Example #22
0
 public static Action <object> RegExp(JsRegExp reg, string errorMessage = null)
 {
     throw new NotImplementedException();
 }
Example #23
0
        /*
         * Given a phone number, returns true or false if the phone number is in a valid format.
         * @param {String} phone the phone number to validate
         * @return {Boolean}
         * @static
         */
        static bool isValidPhoneNumber(JsString phone)
        {
            var regex = new JsRegExp("^(1?([ -]?\\(?\\d{3})\\)?[ -]?)?(\\d{3})([ -]?\\d{4})$");

            return(regex.test(phone));
        }
Example #24
0
 /// <summary>
 /// Executes a regex search in a specified string. Returns true or false. Optional pos and sticky arguments specify the search start position, and whether the match must start at the specified position only. The lastIndex property of the provided regex is not used, but is updated for compatibility.
 /// Also fixes browser bugs compared to the native RegExp.prototype.test and can be used reliably cross-browser.
 /// </summary>
 /// <param name="str">String to search.</param>
 /// <param name="regex">Regex to search with.</param>
 /// <param name="pos">Zero-based index at which to start the search.</param>
 /// <param name="sticky">Whether the match must start at the specified position only. The string 'sticky' is accepted as an alternative to true.</param>
 /// <returns>Whether the regex matched the provided value.</returns>
 ///<example>
 ///usage
 ///<code>
 /// // Basic use
 /// XRegExp.test('abc', /c/); // -> true
 /// 
 /// // With pos and sticky
 /// XRegExp.test('abc', /c/, 0, 'sticky'); // -> false
 ///</code>
 ///</example>
 public static bool test(JsString str, JsRegExp regex, JsNumber pos, JsString sticky) { return false; }
Example #25
0
 public extern JsArray split(JsRegExp separator, int count = 0);
Example #26
0
 public void SetFilter(JsRegExp value)
 {
     throw new NotImplementedException();
 }
Example #27
0
 /// <summary>
 /// Creates an extended regular expression object for matching text with a pattern. Differs from a native regular expression in that additional syntax and flags are supported.
 /// The returned object is in fact a native RegExp and works with all native methods.
 /// </summary>
 /// <param name="pattern">Regex pattern string, or an existing regex object to copy.</param>
 /// <param name="flags">Any combination of flags.
 /// Native flags:
 /// g - global
 /// i - ignore case
 /// m - multiline anchors
 /// y - sticky (Firefox 3+)
 /// Additional XRegExp flags:
 /// n - explicit capture
 /// s - dot matches all (aka singleline)
 /// x - free-spacing and line comments (aka extended)
 /// Flags cannot be provided when constructing one RegExp from another.</param>
 /// <returns>Extended regular expression object.</returns>
 ///<example>
 ///usage
 ///<code>
 /// // With named capture and flag x
 /// XRegExp('(?&lt;year>  [0-9]{4} ) [-\\s]?  # year  \n\
 ///          (?&lt;month> [0-9]{2} ) [-\\s]?  # month \n\
 ///          (?&lt;day>   [0-9]{2} )          # day   ', 'x');
 /// 
 /// // Providing a regex object copies it. Native regexes are recompiled using native (not
 /// // XRegExp) syntax. Copies maintain special properties for named capture, are augmented
 /// // with `XRegExp.prototype` methods, and have fresh `lastIndex` properties (set to zero).
 /// XRegExp(/regex/);
 ///</code>
 ///</example>
 ///<remarks>
 ///Regexes, strings, and backslashes
 ///JavaScript string literals (as opposed to, e.g., user input or text extracted from the DOM) use a backslash as an escape character. The string literal '\\' therefore contains a single backslash, and its length property's value is 1. However, a backslash is also an escape character in regular expression syntax, where the pattern \\ matches a single backslash. When providing string literals to the RegExp or XRegExp constructor functions, four backslashes are therefore needed to match a single backslash—e.g., XRegExp('\\\\'). Only two of those backslashes are actually passed into the constructor function. The other two are used to escape the backslashes in the string before the function ever sees the string.
 ///The same issue is at play with the \\s sequences in the example code just shown. XRegExp is provided with the two characters \s, which it in turn recognizes as the metasequence used to match a whitespace character. \n (used at the end of the first two lines) is another metasequence in JavaScript string literals and inserts actual line feed characters into the string, which terminate the free-spacing mode line comments that start with #. The backslashes at the very end of the first two lines allow the string to continue to the next line, which avoids the need to concatenate multiple strings when extending a string beyond one line of code.
 /// </remarks>
 public XRegExp(JsRegExp pattern, JsString flags) { }
        void parseAndPersistBehaviors(JsString sheet)
        {
            JsString classSelector;
            JsRegExpResult randoriVendorItemsResult;
            JsRegExpResult randoriVendorItemInfoResult;
            JsRegExpResult CSSClassSelectorNameResult;
            /*
             * This regular expression then grabs all of the class selectors
             * \.[\w\W]*?\}
             *
             * This expression finds an -randori vendor prefix styles in the current cssSelector and returns 2 groups, the first
             * is the type, the second is the value
             *
             * \s?-randori-([\w\W]+?)\s?:\s?["']?([\w\W]+?)["']?;
             *
             */

            var allClassSelectors = new JsRegExp(@"^[\w\W]*?\}", "gm");

            const string RANDORI_VENDOR_ITEM_EXPRESSION = @"\s?-randori-([\w\W]+?)\s?:\s?[""']?([\w\W]+?)[""']?;";
            //These two are the same save for the global flag. The global flag seems to disable all capturing groups immediately
            var anyVendorItems = new JsRegExp(RANDORI_VENDOR_ITEM_EXPRESSION, "g");

            //This is the same as the one in findRelevant classes save for the the global flag... which is really important
            //The global flag seems to disable all capturing groups immediately
            var eachVendorItem = new JsRegExp(RANDORI_VENDOR_ITEM_EXPRESSION);

            var classSelectorName = new JsRegExp(@"^(.+?)\s+?{","m");
            JsString CSSClassSelectorName;
            JsString randoriVendorItemStr;

            var selectors = sheet.match(allClassSelectors);

            if (selectors != null ) {
                for (int i = 0; i < selectors.length; i++) {
                    classSelector = selectors[i];

                    randoriVendorItemsResult = classSelector.match(anyVendorItems);
                    if (randoriVendorItemsResult != null) {

                        CSSClassSelectorNameResult = classSelector.match(classSelectorName);
                        CSSClassSelectorName = CSSClassSelectorNameResult[1];

                        for (int j = 0; j < randoriVendorItemsResult.length; j++) {
                            randoriVendorItemStr = randoriVendorItemsResult[j];
                            randoriVendorItemInfoResult = randoriVendorItemStr.match(eachVendorItem);
                            map.addCSSEntry(CSSClassSelectorName, randoriVendorItemInfoResult[1], randoriVendorItemInfoResult[2]);
                            if (HtmlContext.window.console != null) {
                                HtmlContext.console.log(CSSClassSelectorName + " specifies a " + randoriVendorItemInfoResult[1] + " implemented by class " + randoriVendorItemInfoResult[2]);
                            }
                        }
                    }
                }
            }
        }
Example #29
0
 public extern JsArray match(JsRegExp regularExpression);
Example #30
0
 public extern JsString replace(JsRegExp regexp, JsFunction replaceWith);
Example #31
0
        /**
         * Given a shortcode, returns true or false if the it is in a valid format.
         * @param {String} shortcode the short code to validate
         * @return {Boolean}
         * @static
         */
        static bool isValidShortCode(JsString shortcode)
        {
            JsRegExp regex = new JsRegExp("^\\d{3,8}$");

            return(regex.test(shortcode));
        }
Example #32
0
 /// <summary>
 /// Adds a new pluralization rule to the Inflector. ...
 /// </summary>
 public static object plural(JsRegExp matcher, JsString replacer){return null;}
Example #33
0
 /// <summary>
 /// Returns a new string with one or all matches of a pattern replaced. The pattern can be a string or regex, and the replacement can be a string or a function to be called for each match.
 /// To perform a global search and replace, use the optional scope argument or include flag g if using a regex. Replacement strings can use ${n} for named and numbered backreferences.
 /// Replacement functions can use named backreferences via arguments[0].name.
 /// Also fixes browser bugs compared to the native String.prototype.replace and can be used reliably cross-browser.
 /// </summary>
 /// <param name="str">String to search.</param>
 /// <param name="search">Search pattern to be replaced.</param>
 /// <param name="replacement">Replacement string or a function invoked to create it.
 /// Replacement strings can include special replacement syntax:
 /// $$ - Inserts a literal $ character.
 /// $&amp;, $0 - Inserts the matched substring.
 /// $` - Inserts the string that precedes the matched substring (left context).
 /// $' - Inserts the string that follows the matched substring (right context).
 /// $n, $nn - Where n/nn are digits referencing an existent capturing group, inserts backreference n/nn.
 /// ${n} - Where n is a name or any number of digits that reference an existent capturing group, inserts backreference n.
 /// Replacement functions are invoked with three or more arguments:
 /// The matched substring (corresponds to $&amp; above). Named backreferences are accessible as properties of this first argument.
 /// 0..n arguments, one for each backreference (corresponding to $1, $2, etc. above).
 /// The zero-based index of the match within the total search string.
 /// The total string being searched.</param>
 /// <returns>New string with one or all matches replaced.</returns>
 ///<example>
 ///usage
 ///<code>
 /// // Regex search, using named backreferences in replacement string
 /// var name = XRegExp('(?&lt;first>\\w+) (?&lt;last>\\w+)');
 /// XRegExp.replace('John Smith', name, '${last}, ${first}');
 /// // -> 'Smith, John'
 /// 
 /// // Regex search, using named backreferences in replacement function
 /// XRegExp.replace('John Smith', name, function (match) {
 ///   return match.last + ', ' + match.first;
 /// });
 /// // -> 'Smith, John'
 /// 
 /// // String search, with replace-all
 /// XRegExp.replace('RegExp builds RegExps', 'RegExp', 'XRegExp', 'all');
 /// // -> 'XRegExp builds XRegExps'
 ///</code>
 ///</example>
 public static JsString replace(JsString str, JsRegExp search, JsString replacement) { return null; }
Example #34
0
 /// <summary>
 /// Adds a new singularization rule to the Inflector. ...
 /// </summary>
 public static object singular(JsRegExp matcher, JsString replacer){return null;}
Example #35
0
 /// <summary>
 /// Splits a string into an array of strings using a regex or string separator. Matches of the separator are not included in the result array.
 /// However, if separator is a regex that contains capturing groups, backreferences are spliced into the result each time separator is matched.
 /// Fixes browser bugs compared to the native String.prototype.split and can be used reliably cross-browser.
 /// </summary>
 /// <param name="str">String to split.</param>
 /// <param name="separator">Regex or string to use for separating the string.</param>
 /// <param name="limit">Maximum number of items to include in the result array.</param>
 /// <returns>Array of substrings.</returns>
 ///<example>
 ///usage
 ///<code>
 /// // Basic use
 /// XRegExp.split('a b c', ' ');
 /// // -> ['a', 'b', 'c']
 /// 
 /// // With limit
 /// XRegExp.split('a b c', ' ', 2);
 /// // -> ['a', 'b']
 /// 
 /// // Backreferences in result array
 /// XRegExp.split('..word1..', /([a-z]+)(\d+)/i);
 /// // -> ['..', 'word', '1', '..']
 ///</code>
 ///</example>
 public static JsArray split(JsString str, JsRegExp separator, JsNumber limit) { return null; }
 public Regex_SharpKit(string pattern)
 {
     m_JSRegex = new JsRegExp(pattern);
 }
Example #37
0
 /// <summary>
 /// Executes a regex search in a specified string. Returns true or false. Optional pos and sticky arguments specify the search start position, and whether the match must start at the specified position only. The lastIndex property of the provided regex is not used, but is updated for compatibility.
 /// Also fixes browser bugs compared to the native RegExp.prototype.test and can be used reliably cross-browser.
 /// </summary>
 /// <param name="str">String to search.</param>
 /// <param name="regex">Regex to search with.</param>
 /// <returns>Whether the regex matched the provided value.</returns>
 ///<example>
 ///usage
 ///<code>
 /// // Basic use
 /// XRegExp.test('abc', /c/); // -> true
 /// 
 /// // With pos and sticky
 /// XRegExp.test('abc', /c/, 0, 'sticky'); // -> false
 ///</code>
 ///</example>
 public static bool test(JsString str, JsRegExp regex) { return false; }
Example #38
0
		public static Action<object> RegExp(JsRegExp reg, string errorMessage = null) { throw new NotImplementedException(); }
Example #39
0
 public extern JsString replace(JsRegExp regexp, JsFunction replaceWith);
Example #40
0
 /// <summary>
 /// Adds a new pluralization rule to the Inflector. See the intro docs for more information
 /// </summary>
 /// <param name="matcher"><p>The matcher regex</p>
 /// </param>
 /// <param name="replacer"><p>The replacement string, which can reference matches from the matcher argument</p>
 /// </param>
 public static void plural(JsRegExp matcher, JsString replacer){}
 public Regex_SharpKit(string pattern)
 {
     m_JSRegex = new JsRegExp(pattern);
 }
Example #42
0
 public extern JsArray match(JsRegExp regularExpression);
Example #43
0
 /// <summary>
 /// Adds a new pluralization rule to the Inflector. ...
 /// </summary>
 public static object plural(JsRegExp matcher, JsString replacer)
 {
     return(null);
 }
Example #44
0
 /// <summary>
 /// Executes a regex search in a specified string. Returns a match array or null. If the provided regex uses named capture, named backreference properties are included on the match array.
 /// Optional pos and sticky arguments specify the search start position, and whether the match must start at the specified position only. The lastIndex property of the provided regex is not used, but is updated for compatibility.
 /// Also fixes browser bugs compared to the native RegExp.prototype.exec and can be used reliably cross-browser.
 /// </summary>
 /// <param name="str">String to search.</param>
 /// <param name="regex">Regex to search with.</param>
 /// <param name="pos">Zero-based index at which to start the search.</param>
 /// <param name="sticky">Whether the match must start at the specified position only. The string 'sticky' is accepted as an alternative to true</param>
 /// <returns>Match array with named backreference properties, or null.</returns>
 ///<example>
 ///usage
 ///<code>
 /// // Basic use, with named backreference
 /// var match = XRegExp.exec('U+2620', XRegExp('U\\+(?[0-9A-F]{4})'));
 /// match.hex; // -> '2620'
 /// 
 /// // With pos and sticky, in a loop
 /// var pos = 2, result = [], match;
 /// while (match = XRegExp.exec('&lt;1>&lt;2>&lt;3>&lt;4>5&lt;6>', /&lt;(\d)>/, pos, 'sticky')) {
 ///   result.push(match[1]);
 ///   pos = match.index + match[0].length;
 /// }
 /// // result -> ['2', '3', '4']
 ///</code>
 ///</example>
 public static JsArray exec(JsString str, JsRegExp regex, JsNumber pos, JsString sticky) { return null; }
Example #45
0
 public extern JsArray split(JsRegExp separator, int count = 0);
Example #46
0
 /// <summary>
 /// Executes a regex search in a specified string. Returns a match array or null. If the provided regex uses named capture, named backreference properties are included on the match array.
 /// Optional pos and sticky arguments specify the search start position, and whether the match must start at the specified position only. The lastIndex property of the provided regex is not used, but is updated for compatibility.
 /// Also fixes browser bugs compared to the native RegExp.prototype.exec and can be used reliably cross-browser.
 /// </summary>
 /// <param name="str">String to search.</param>
 /// <param name="regex">Regex to search with.</param>
 /// <returns>Match array with named backreference properties, or null.</returns>
 ///<example>
 ///usage
 ///<code>
 /// // Basic use, with named backreference
 /// var match = XRegExp.exec('U+2620', XRegExp('U\\+(?[0-9A-F]{4})'));
 /// match.hex; // -> '2620'
 /// 
 /// // With pos and sticky, in a loop
 /// var pos = 2, result = [], match;
 /// while (match = XRegExp.exec('&lt;1>&lt;2>&lt;3>&lt;4>5&lt;6>', /&lt;(\d)>/, pos, 'sticky')) {
 ///   result.push(match[1]);
 ///   pos = match.index + match[0].length;
 /// }
 /// // result -> ['2', '3', '4']
 ///</code>
 ///</example>
 public static JsArray exec(JsString str, JsRegExp regex) { return null; }
Example #47
0
 /// <summary>
 /// Adds a new pluralization rule to the Inflector. See the intro docs for more information
 /// </summary>
 /// <param name="matcher"><p>The matcher regex</p>
 /// </param>
 /// <param name="replacer"><p>The replacement string, which can reference matches from the matcher argument</p>
 /// </param>
 public static void plural(JsRegExp matcher, JsString replacer)
 {
 }
Example #48
0
 //TODO: callback gets 2 parameter.
 /// <summary>
 /// Executes a provided function once per regex match.
 /// Provides a simpler and cleaner way to iterate over regex matches compared to the traditional approaches of subverting String.prototype.replace or repeatedly calling RegExp.prototype.exec within a while loop. Searches always start at the beginning of the string and continue until the end, regardless of the state of the regex's global property and initial lastIndex.
 /// </summary>
 /// <param name="str">String to search.</param>
 /// <param name="regex">Regex to search with.</param>
 /// <param name="callback">Function to execute for each match. Invoked with four arguments:
 /// The match array, with named backreference properties.
 /// The zero-based match index.
 /// The string being traversed.
 /// The regex object being used to traverse the string.</param>
 /// <returns>Provided context object.</returns>
 ///<example>
 ///usage
 ///<code>
 /// // Extracts every other digit from a string
 /// XRegExp.forEach('1a2345', /\d/, function (match, i) {
 ///   if (i % 2) this.push(+match[0]);
 /// }, []);
 /// // -> [2, 4]
 ///</code>
 ///</example>
 public static object forEach(JsString str, JsRegExp regex, JsAction callback) { return null; }
Example #49
0
		public void AssertMatch(string str, JsRegExp re, string msg) { throw new NotImplementedException(); }
Example #50
0
        //TODO: callback gets 2 parameter.

        /// <summary>
        /// Copies a regex object and adds flag g. The copy maintains special properties for named capture,
        /// is augmented with XRegExp.prototype methods, and has a fresh lastIndex property (set to zero). Native regexes are not recompiled using XRegExp syntax.
        /// </summary>
        /// <param name="regex">Regex to globalize.</param>
        /// <returns>Copy of the provided regex with flag g added.</returns>
        ///<example>
        ///usage
        ///<code>
        ///var globalCopy = XRegExp.globalize(/regex/);
        /// globalCopy.global; // -> true
        /// 
        /// function parse(str, regex) {
        ///   var match;
        ///   regex = XRegExp.globalize(regex);
        ///   while (match = regex.exec(str)) {
        ///     // ...
        ///   }
        /// }
        ///</code>
        ///</example>
        public static JsRegExp globalize(JsRegExp regex) { return null; }
Example #51
0
 /// <summary>
 /// Creates an extended regular expression object for matching text with a pattern. Differs from a native regular expression in that additional syntax and flags are supported.
 /// The returned object is in fact a native RegExp and works with all native methods.
 /// </summary>
 /// <param name="pattern">Regex pattern string, or an existing regex object to copy.</param>
 /// <returns>Extended regular expression object.</returns>
 ///<example>
 ///usage
 ///<code>
 /// // With named capture and flag x
 /// XRegExp('(?&lt;year>  [0-9]{4} ) [-\\s]?  # year  \n\
 ///          (?&lt;month> [0-9]{2} ) [-\\s]?  # month \n\
 ///          (?&lt;day>   [0-9]{2} )          # day   ', 'x');
 /// 
 /// // Providing a regex object copies it. Native regexes are recompiled using native (not
 /// // XRegExp) syntax. Copies maintain special properties for named capture, are augmented
 /// // with `XRegExp.prototype` methods, and have fresh `lastIndex` properties (set to zero).
 /// XRegExp(/regex/);
 ///</code>
 ///</example>
 ///<remarks>
 ///Regexes, strings, and backslashes
 ///JavaScript string literals (as opposed to, e.g., user input or text extracted from the DOM) use a backslash as an escape character. The string literal '\\' therefore contains a single backslash, and its length property's value is 1. However, a backslash is also an escape character in regular expression syntax, where the pattern \\ matches a single backslash. When providing string literals to the RegExp or XRegExp constructor functions, four backslashes are therefore needed to match a single backslash—e.g., XRegExp('\\\\'). Only two of those backslashes are actually passed into the constructor function. The other two are used to escape the backslashes in the string before the function ever sees the string.
 ///The same issue is at play with the \\s sequences in the example code just shown. XRegExp is provided with the two characters \s, which it in turn recognizes as the metasequence used to match a whitespace character. \n (used at the end of the first two lines) is another metasequence in JavaScript string literals and inserts actual line feed characters into the string, which terminate the free-spacing mode line comments that start with #. The backslashes at the very end of the first two lines allow the string to continue to the next line, which avoids the need to concatenate multiple strings when extending a string beyond one line of code.
 /// </remarks>
 public XRegExp(JsRegExp pattern) { }
Example #52
0
        /**
         * Given an email, returns true or false if the it is in a valid format.
         * @param {String} email the email to validate
         * @return {Boolean}
         * @static
         */
        static bool isValidEmail(JsString email)
        {
            var regex = new JsRegExp("^[a-zA-Z]\\w+(.\\w+)*@\\w+(.[0-9a-zA-Z]+)*.[a-zA-Z]{2,4}$", "i");

            return(regex.test(email));
        }
Example #53
0
 public void AssertMatch(string str, JsRegExp re, string msg)
 {
     throw new NotImplementedException();
 }
Example #54
0
 /// <summary>
 /// Extends or changes XRegExp syntax and allows custom flags. This is used internally and can be used to create XRegExp addons.
 /// XRegExp.install('extensibility') must be run before calling this function, or an error is thrown.
 /// If more than one token can match the same string, the last added wins.
 /// </summary>
 /// <param name="regex">Regex object that matches the new token.</param>
 /// <param name="handler">Function that returns a new pattern string (using native regex syntax) to replace the matched token within all future XRegExp regexes.
 /// Has access to persistent properties of the regex being built, through this. Invoked with two arguments:
 /// The match array, with named backreference properties.
 /// The regex scope where the match was found.</param>
 /// <param name="options">
 /// Options object with optional properties:
 /// scope {String} Scopes where the token applies: 'default', 'class', or 'all'.
 /// trigger {Function} Function that returns true when the token should be applied; e.g., if a flag is set. If false is returned, the matched string can be matched by other tokens.
 /// Has access to persistent properties of the regex being built, through this (including function this.hasFlag).
 /// customFlags {String} Nonnative flags used by the token's handler or trigger functions.
 /// Prevents XRegExp from throwing an 'unknown flag' error when the specified flags are used.</param>
 ///<example>
 ///usage
 ///<code>
 /// // Basic usage: Add \a for the ALERT control code
 /// XRegExp.addToken(
 ///   /\\a/,
 ///   function () {return '\\x07';},
 ///   {scope: 'all'}
 /// );
 /// XRegExp('\\a[\\a-\\n]+').test('\x07\n\x07'); // -> true
 ///</code>
 ///</example>
 public static void addToken(JsRegExp regex, JsAction handler, XRegExpAddTokenOptions options) { }
Example #55
0
 /// <summary>
 /// Adds a new singularization rule to the Inflector. See the intro docs for more information
 /// </summary>
 /// <param name="matcher"><p>The matcher regex</p>
 /// </param>
 /// <param name="replacer"><p>The replacement string, which can reference matches from the matcher argument</p>
 /// </param>
 public static void singular(JsRegExp matcher, JsString replacer){}
Example #56
0
 /// <summary>
 /// Extends or changes XRegExp syntax and allows custom flags. This is used internally and can be used to create XRegExp addons.
 /// XRegExp.install('extensibility') must be run before calling this function, or an error is thrown.
 /// If more than one token can match the same string, the last added wins.
 /// </summary>
 /// <param name="regex">Regex object that matches the new token.</param>
 /// <param name="handler">Function that returns a new pattern string (using native regex syntax) to replace the matched token within all future XRegExp regexes.
 /// Has access to persistent properties of the regex being built, through this. Invoked with two arguments:
 /// The match array, with named backreference properties.
 /// The regex scope where the match was found.</param>
 ///<example>
 ///usage
 ///<code>
 /// // Basic usage: Add \a for the ALERT control code
 /// XRegExp.addToken(
 ///   /\\a/,
 ///   function () {return '\\x07';},
 ///   {scope: 'all'}
 /// );
 /// XRegExp('\\a[\\a-\\n]+').test('\x07\n\x07'); // -> true
 ///</code>
 ///</example>
 public static void addToken(JsRegExp regex, JsAction handler) { }