Esempio n. 1
0
		/// <summary>Creates a new parsed content type.</summary>
		/// <remarks>Creates a new parsed content type.</remarks>
		/// <param name="mimeType">
		/// the full MIME type; typically the value of the
		/// "Content-Type" header of some MIME-compliant message. Can be null.
		/// </param>
		public ParsedContentType(string mimeType)
		{
			string contentType = null;
			string encoding = null;
			if (mimeType != null)
			{
				StringTokenizer tok = new StringTokenizer(mimeType, ";");
				if (tok.HasMoreTokens())
				{
					contentType = tok.NextToken().Trim();
					while (tok.HasMoreTokens())
					{
						string param = tok.NextToken().Trim();
						if (param.StartsWith("charset="))
						{
							encoding = Sharpen.Runtime.Substring(param, 8).Trim();
							int l = encoding.Length;
							if (l > 0)
							{
								if (encoding[0] == '"')
								{
									encoding = Sharpen.Runtime.Substring(encoding, 1);
								}
								if (encoding[l - 1] == '"')
								{
									encoding = Sharpen.Runtime.Substring(encoding, 0, l - 1);
								}
							}
							break;
						}
					}
				}
			}
			this.contentType = contentType;
			this.encoding = encoding;
		}
Esempio n. 2
0
		/// <summary>Parse arguments.</summary>
		/// <remarks>Parse arguments.</remarks>
		public virtual string[] ProcessOptions(string[] args)
		{
			targetPackage = string.Empty;
			// default to no package
			compilerEnv.SetGenerateDebugInfo(false);
			// default to no symbols
			for (int i = 0; i < args.Length; i++)
			{
				string arg = args[i];
				if (!arg.StartsWith("-"))
				{
					int tail = args.Length - i;
					if (targetName != null && tail > 1)
					{
						AddError("msg.multiple.js.to.file", targetName);
						return null;
					}
					string[] result = new string[tail];
					for (int j = 0; j != tail; ++j)
					{
						result[j] = args[i + j];
					}
					return result;
				}
				if (arg.Equals("-help") || arg.Equals("-h") || arg.Equals("--help"))
				{
					printHelp = true;
					return null;
				}
				try
				{
					if (arg.Equals("-version") && ++i < args.Length)
					{
						int version = System.Convert.ToInt32(args[i]);
						compilerEnv.SetLanguageVersion(version);
						continue;
					}
					if ((arg.Equals("-opt") || arg.Equals("-O")) && ++i < args.Length)
					{
						int optLevel = System.Convert.ToInt32(args[i]);
						compilerEnv.SetOptimizationLevel(optLevel);
						continue;
					}
				}
				catch (FormatException)
				{
					BadUsage(args[i]);
					return null;
				}
				if (arg.Equals("-nosource"))
				{
					compilerEnv.SetGeneratingSource(false);
					continue;
				}
				if (arg.Equals("-debug") || arg.Equals("-g"))
				{
					compilerEnv.SetGenerateDebugInfo(true);
					continue;
				}
				if (arg.Equals("-main-method-class") && ++i < args.Length)
				{
					compiler.SetMainMethodClass(args[i]);
					continue;
				}
				if (arg.Equals("-encoding") && ++i < args.Length)
				{
					characterEncoding = args[i];
					continue;
				}
				if (arg.Equals("-o") && ++i < args.Length)
				{
					string name = args[i];
					int end = name.Length;
					if (end == 0 || !char.IsJavaIdentifierStart(name[0]))
					{
						AddError("msg.invalid.classfile.name", name);
						continue;
					}
					for (int j = 1; j < end; j++)
					{
						char c = name[j];
						if (!char.IsJavaIdentifierPart(c))
						{
							if (c == '.')
							{
								// check if it is the dot in .class
								if (j == end - 6 && name.EndsWith(".class"))
								{
									name = Sharpen.Runtime.Substring(name, 0, j);
									break;
								}
							}
							AddError("msg.invalid.classfile.name", name);
							break;
						}
					}
					targetName = name;
					continue;
				}
				if (arg.Equals("-observe-instruction-count"))
				{
					compilerEnv.SetGenerateObserverCount(true);
				}
				if (arg.Equals("-package") && ++i < args.Length)
				{
					string pkg = args[i];
					int end = pkg.Length;
					for (int j = 0; j != end; ++j)
					{
						char c = pkg[j];
						if (char.IsJavaIdentifierStart(c))
						{
							for (++j; j != end; ++j)
							{
								c = pkg[j];
								if (!char.IsJavaIdentifierPart(c))
								{
									break;
								}
							}
							if (j == end)
							{
								break;
							}
							if (c == '.' && j != end - 1)
							{
								continue;
							}
						}
						AddError("msg.package.name", targetPackage);
						return null;
					}
					targetPackage = pkg;
					continue;
				}
				if (arg.Equals("-extends") && ++i < args.Length)
				{
					string targetExtends = args[i];
					Type superClass;
					try
					{
						superClass = Sharpen.Runtime.GetType(targetExtends);
					}
					catch (TypeLoadException e)
					{
						throw new Exception(e.ToString());
					}
					// TODO: better error
					compiler.SetTargetExtends(superClass);
					continue;
				}
				if (arg.Equals("-implements") && ++i < args.Length)
				{
					// TODO: allow for multiple comma-separated interfaces.
					string targetImplements = args[i];
					StringTokenizer st = new StringTokenizer(targetImplements, ",");
					IList<Type> list = new List<Type>();
					while (st.HasMoreTokens())
					{
						string className = st.NextToken();
						try
						{
							list.Add(Sharpen.Runtime.GetType(className));
						}
						catch (TypeLoadException e)
						{
							throw new Exception(e.ToString());
						}
					}
					// TODO: better error
					Type[] implementsClasses = Sharpen.Collections.ToArray(list, new Type[list.Count]);
					compiler.SetTargetImplements(implementsClasses);
					continue;
				}
				if (arg.Equals("-d") && ++i < args.Length)
				{
					destinationDir = args[i];
					continue;
				}
				BadUsage(arg);
				return null;
			}
			// no file name
			P(ToolErrorReporter.GetMessage("msg.no.file"));
			return null;
		}
 public static int CBLCollateRevIDs(string revId1, string revId2)
 {
     string rev1GenerationStr = null;
     string rev2GenerationStr = null;
     string rev1Hash = null;
     string rev2Hash = null;
     var st1 = new StringTokenizer(revId1, "-");
     try
     {
         rev1GenerationStr = st1.NextToken();
         rev1Hash = st1.NextToken();
     }
     catch (Exception)
     {
     }
     StringTokenizer st2 = new StringTokenizer(revId2, "-");
     try
     {
         rev2GenerationStr = st2.NextToken();
         rev2Hash = st2.NextToken();
     }
     catch (Exception)
     {
     }
     // improper rev IDs; just compare as plain text:
     if (rev1GenerationStr == null || rev2GenerationStr == null)
     {
         return revId1.CompareToIgnoreCase(revId2);
     }
     int rev1Generation;
     int rev2Generation;
     try
     {
         rev1Generation = System.Convert.ToInt32(rev1GenerationStr);
         rev2Generation = System.Convert.ToInt32(rev2GenerationStr);
     }
     catch (FormatException)
     {
         // improper rev IDs; just compare as plain text:
         return revId1.CompareToIgnoreCase(revId2);
     }
     // Compare generation numbers; if they match, compare suffixes:
     if (rev1Generation.CompareTo(rev2Generation) != 0)
     {
         return rev1Generation.CompareTo(rev2Generation);
     }
     else
     {
         if (rev1Hash != null && rev2Hash != null)
         {
             // compare suffixes if possible
             return Sharpen.Runtime.CompareOrdinal(rev1Hash, rev2Hash);
         }
         else
         {
             // just compare as plain text:
             return revId1.CompareToIgnoreCase(revId2);
         }
     }
 }
Esempio n. 4
0
		internal static object LookupQualifiedName(Scriptable scope, string qualifiedName)
		{
			StringTokenizer st = new StringTokenizer(qualifiedName, ".");
			object result = scope;
			while (st.HasMoreTokens())
			{
				string s = st.NextToken();
				result = ScriptableObject.GetProperty((Scriptable)result, s);
				if (result == null || !(result is Scriptable))
				{
					break;
				}
			}
			return result;
		}
		private void ParseContentType()
		{
			StringTokenizer tokenizer = new StringTokenizer(contentType, ";");
			bool first = true;
			while (tokenizer.HasMoreTokens())
			{
				string param = tokenizer.NextToken().Trim();
				if (first == true)
				{
					if (!param.StartsWith("multipart/"))
					{
						throw new ArgumentException(contentType + " does not start with multipart/");
					}
					first = false;
				}
				else
				{
					if (param.StartsWith("boundary="))
					{
						string tempBoundary = Sharpen.Runtime.Substring(param, 9);
						if (tempBoundary.StartsWith("\""))
						{
							if (tempBoundary.Length < 2 || !tempBoundary.EndsWith("\""))
							{
								throw new ArgumentException(contentType + " is not valid");
							}
							tempBoundary = Sharpen.Runtime.Substring(tempBoundary, 1, tempBoundary.Length - 1
								);
						}
						if (tempBoundary.Length < 1)
						{
							throw new ArgumentException(contentType + " has zero-length boundary");
						}
						tempBoundary = string.Format("\r\n--%s", tempBoundary);
						boundary = Sharpen.Runtime.GetBytesForString(tempBoundary, Sharpen.Extensions.GetEncoding
							("UTF-8"));
						break;
					}
				}
			}
		}
		public virtual void ParseHeaders(string headersStr)
		{
			headers = new Dictionary<string, string>();
			if (headersStr != null && headersStr.Length > 0)
			{
				headersStr = headersStr.Trim();
				StringTokenizer tokenizer = new StringTokenizer(headersStr, "\r\n");
				while (tokenizer.HasMoreTokens())
				{
					string header = tokenizer.NextToken();
					if (!header.Contains(":"))
					{
						throw new ArgumentException("Missing ':' in header line: " + header);
					}
					StringTokenizer headerTokenizer = new StringTokenizer(header, ":");
					string key = headerTokenizer.NextToken().Trim();
					string value = headerTokenizer.NextToken().Trim();
					headers.Put(key, value);
				}
			}
		}