예제 #1
0
		internal virtual String commandNumberToCommandName(StringIntArray cmdList, int cmdNumber)
		{
			for (int i = 0; i < cmdList.Count; i++)
			{
				if (cmdList.getInt(i) == cmdNumber)
					return cmdList.getString(i);
			}
			
			return "?"; //$NON-NLS-1$
		}
예제 #2
0
		/// <summary> Attempt to match given the given string against our set of commands</summary>
		/// <returns> the command code that was hit.
		/// </returns>
		internal virtual int determineCommand(StringIntArray cmdList, String input, int defCmd)
		{
			int cmd = defCmd;
			
			// first check for a comment
			if (input[0] == '#')
				cmd = CMD_COMMENT;
			else
			{
				//			long start = System.currentTimeMillis();
				System.Collections.ArrayList ar = cmdList.elementsStartingWith(input);
				//			long end = System.currentTimeMillis();
				
				int size = ar.Count;
				
				/*
				* 3 cases:
				*  - No hits, return unknown and let our caller
				*    dump the error.
				*  - We match unambiguously or we have 1 or more matches
				*    and the input is a single character. We then take the
				*    first hit as our command.
				*  - If we have multiple hits then we dump a 'ambiguous' message
				*    and puke quietly.
				*/
				if (size == 0)
				{
				}
				// no command match return unknown
				
				// only 1 match or our input is 1 character or first match is exact
				else if (size == 1 || input.Length == 1 || String.CompareOrdinal(cmdList.getString(((System.Int32) ar[0])), input) == 0)
				{
					cmd = (cmdList.getInteger(((System.Int32) ar[0])));
				}
				else
				{
					// matches more than one command dump message and go
					System.Text.StringBuilder sb = new System.Text.StringBuilder();
					System.Collections.IDictionary args = new System.Collections.Hashtable();
					args["input"] = input; //$NON-NLS-1$
					sb.Append(LocalizationManager.getLocalizedTextString("ambiguousCommand", args)); //$NON-NLS-1$
					sb.Append(' ');
					for (int i = 0; i < size; i++)
					{
						String s = cmdList.getString(((System.Int32) ar[i]));
						sb.Append(s);
						if (i + 1 < size)
							sb.Append(", "); //$NON-NLS-1$
					}
					sb.Append('.');
					err(sb.ToString());
					throw new AmbiguousException();
				}
			}
			return cmd;
		}