예제 #1
0
파일: Common.cs 프로젝트: lujinlong/Apq
		/// <summary>
		/// 接受格式:命令([列表])+
		/// 列表分隔用","
		/// 特殊字符集:{(),}
		/// </summary>
		/// <param name="str"></param>
		/// <param name="ESCAPE"></param>
		/// <returns></returns>
		public static int cmd(string str, string ESCAPE)
		{
			str = str.Trim();
			if (str.Length == 0)
			{
				return 0;
			}

			if (ESCAPE == null)
			{
				ESCAPE = Apq.Shell.Common.ESCAPE;
			}

			State state = new State();
			ParseResult obj = new ParseResult();

			obj.cmd = Apq.Shell.Common.GetCmd(str, state, ESCAPE);
			if (state.Index < str.Length)
			{
				Apq.Shell.Common.GetPars(str, state, ESCAPE, obj.Pars);
			}

			//return Apq.Shell.exec( obj );
			return 0;
		}
예제 #2
0
파일: Common.cs 프로젝트: lujinlong/Apq
		/// <summary>
		/// 获取命令
		/// </summary>
		/// <param name="str"></param>
		/// <param name="state"></param>
		/// <param name="ESCAPE"></param>
		/// <returns></returns>
		public static string GetCmd(string str, State state, string ESCAPE)
		{
			System.Collections.ArrayList ary = new System.Collections.ArrayList();
			for (Char c = Apq.Shell.Char.GetChar(str, state, ESCAPE); c != null; state.Index++, c = Apq.Shell.Char.GetChar(str, state, ESCAPE))
			{
				if (c.Type == 2)
				{
					if (c.Value == "(") break;
					throw new ArgumentException("命令中不能含有特殊字符!");
				}
				ary.Add(c);
			}
			StringBuilder cmd = new StringBuilder();
			for (int i = 0; i < ary.Count; i++)
			{
				cmd.Append((ary[i] as Char).Value);
			}

			return cmd.ToString();
		}
예제 #3
0
파일: Char.cs 프로젝트: lujinlong/Apq
		/// <summary>
		/// 获取指定位置的字符[若为转义符自动取下一位置]
		/// </summary>
		/// <param name="str"></param>
		/// <param name="state"></param>
		/// <param name="ESCAPE"></param>
		/// <returns></returns>
		public static Char GetChar(string str, State state, string ESCAPE)
		{
			if (state.Index >= str.Length)
			{
				return null;
			}
			Char c = new Char();
			c.Value = str[state.Index].ToString();
			if (c.Value == ESCAPE)
			{
				try
				{
					c.Value = Transform(str[++state.Index].ToString());
				}
				catch { }
				c.Type = 1;
			}
			else
			{
				c.Type = Apq.Collections.IList.Contains(Apq.Shell.Common.SpecialChars, c.Value) ? 2 : 1;
			}
			return c;
		}
예제 #4
0
파일: Common.cs 프로젝트: lujinlong/Apq
		/// <summary>
		/// 获取括号对
		/// </summary>
		/// <param name="str"></param>
		/// <param name="state"></param>
		/// <param name="ESCAPE"></param>
		/// <param name="Pars"></param>
		public static void GetPars(string str, State state, string ESCAPE, System.Collections.ArrayList Pars)
		{
			System.Collections.ArrayList Chars = new System.Collections.ArrayList();	// 字符数组
			int index = 0;	// 待解析的起始位置
			for (Char c = Apq.Shell.Char.GetChar(str, state, ESCAPE); c != null; state.Index++, c = Apq.Shell.Char.GetChar(str, state, ESCAPE))
			{
				Chars.Add(c);
				if (c.Type == 2)
				{
					if (c.Value == ")")
					{
						Pars.Add(Apq.Shell.Common.BuildSym(Chars, index));
						index = state.Index + 1;
					}
				}
			}
		}