Esempio n. 1
0
 public void WriteAllArguments(IArgumentReader reader)
 {
     foreach (var a in reader.GetAllArguments())
     {
         writer.WriteLine("\t{0}\t {1}", a.Command, a.Help);
     }
 }
Esempio n. 2
0
        public static string Sprintf(string Format, IArgumentReader Arguments)
        {
            var FormatReader = new StringReader(Format);
            return FormatRegex.Replace(Format, (Match) =>
            {
                var pPad = Match.Groups[1].Value;
                var pJustify = Match.Groups[2].Value;
                var pMinLength = Match.Groups[3].Value;
                var pPrecision = Match.Groups[4].Value;
                var pType = Match.Groups[5].Value;

                //Console.WriteLine("Match: pPad='{0}', pJustify='{1}', pMinLength='{2}', pPrecision='{3}', pType='{4}'", pPad, pJustify, pMinLength, pPrecision, pType);

                string Value = "";
                char PadChar = (pPad.Length > 0) ? pPad[0] : ' ';
                bool Justify = (pJustify.Length > 0) ? true : false;
                int MinLength = (pMinLength.Length > 0) ? int.Parse(pMinLength) : 0;

                switch (pType)
                {
                    case "%": Value = "%"; break;
                    case "b": Value = Convert.ToString(Arguments.LoadInteger(), 2); break;
                    case "c": Value = "" + (char)Arguments.LoadInteger(); break;
                    case "d": Value = Convert.ToString((int)Arguments.LoadInteger(), 10); break;
                    case "u": Value = Convert.ToString((uint)Arguments.LoadInteger(), 10); break;
                    case "f": Value = Convert.ToString(Arguments.LoadFloat()); break;
                    case "o": Value = Convert.ToString((uint)Arguments.LoadInteger(), 8); break;
                    case "s": Value = Arguments.LoadString(); break;
                    case "x":
                    case "X":
                        Value = Convert.ToString((uint)Arguments.LoadInteger(), 16);
                        Value =  (pType == "x") ? Value.ToLowerInvariant() : Value.ToUpperInvariant();
                        break;
                    default:
                        throw(new NotImplementedException());
                }

                if (Value.Length < MinLength)
                {
                    Value = Justify
                        ? Value.PadRight(MinLength, PadChar)
                        : Value.PadLeft(MinLength, PadChar)
                    ;
                }

                return Value;
            });
        }