The Labs \ Source Viewer \ SSCLI \ Microsoft.JScript \ RegExpPrototype

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. namespace Microsoft.JScript
  16. {
  17.    
  18.     using System;
  19.    
  20.     public class RegExpPrototype : JSObject
  21.     {
  22.         static internal readonly RegExpPrototype ob = new RegExpPrototype(ObjectPrototype.ob);
  23.         static internal RegExpConstructor _constructor;
  24.        
  25.         internal RegExpPrototype(ObjectPrototype parent) : base(parent)
  26.         {
  27.             //this.constructor is given a value by the proper constructor class
  28.         }
  29.        
  30.         [JSFunctionAttribute(JSFunctionAttributeEnum.HasThisObject, JSBuiltin.RegExp_compile)]
  31.         public static RegExpObject compile(object thisob, object source, object flags)
  32.         {
  33.             RegExpObject regExpObject = thisob as RegExpObject;
  34.             if (regExpObject == null)
  35.                 throw new JScriptException(JSError.RegExpExpected);
  36.             return regExpObject.compile(source == null || source is Missing ? "" : Convert.ToString(source), flags == null || flags is Missing ? "" : Convert.ToString(flags));
  37.         }
  38.        
  39.         public static RegExpConstructor constructor {
  40.             get { return RegExpPrototype._constructor; }
  41.         }
  42.        
  43.         [JSFunctionAttribute(JSFunctionAttributeEnum.HasThisObject, JSBuiltin.RegExp_exec)]
  44.         public static object exec(object thisob, object input)
  45.         {
  46.             RegExpObject regExpObject = thisob as RegExpObject;
  47.             if (regExpObject == null)
  48.                 throw new JScriptException(JSError.RegExpExpected);
  49.             if (input is Missing && !regExpObject.regExpConst.noExpando)
  50.                 input = regExpObject.regExpConst.input;
  51.             return regExpObject.exec(Convert.ToString(input));
  52.         }
  53.        
  54.         [JSFunctionAttribute(JSFunctionAttributeEnum.HasThisObject, JSBuiltin.RegExp_test)]
  55.         public static bool test(object thisob, object input)
  56.         {
  57.             RegExpObject regExpObject = thisob as RegExpObject;
  58.             if (regExpObject == null)
  59.                 throw new JScriptException(JSError.RegExpExpected);
  60.             if (input is Missing && !regExpObject.regExpConst.noExpando)
  61.                 input = regExpObject.regExpConst.input;
  62.             return regExpObject.test(Convert.ToString(input));
  63.         }
  64.        
  65.         [JSFunctionAttribute(JSFunctionAttributeEnum.HasThisObject, JSBuiltin.RegExp_toString)]
  66.         public static string toString(object thisob)
  67.         {
  68.             RegExpObject regExpObject = thisob as RegExpObject;
  69.             if (regExpObject == null)
  70.                 throw new JScriptException(JSError.RegExpExpected);
  71.             return regExpObject.ToString();
  72.         }
  73.     }
  74. }

Developer Fusion