Beispiel #1
0
        static void Main(string[] args)
        {
            var getopt = new Getopt(Assembly.GetExecutingAssembly().GetName().Name, args, "i:o:") { Opterr = false };

            string input = null;
            string output = null;

            int option;
            while (-1 != (option = getopt.getopt()))
            {
                switch (option)
                {
                    case 'i': input = getopt.Optarg; break;
                    case 'o': output = getopt.Optarg; break;

                    default: PrintUsage(); return;
                }
            }

            if (input == null || output == null)
            {
                PrintUsage();
                return;
            }

            try
            {
                if (!File.Exists(input))
                {
                    Console.WriteLine("File {0} not found", input);
                    return;
                }

                Dictionary<string, string> entries;
                var parser = new PoParser();
                using (var reader = new StreamReader(input))
                {
                    entries = parser.ParseIntoDictionary(reader);
                }

                using (var writer = new ResourceWriter(output))
                {
                    foreach (var kv in entries)
                    {
                        try { writer.AddResource(kv.Key, kv.Value); }
                        catch (Exception e) { Console.WriteLine("Error adding item {0}: {1}", kv.Key, e.Message); }
                    }
                    writer.Generate();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error during execution: {0}", ex.Message);
                return;
            }
        }
        public void ParseIntoDictionaryStringWithSlashesTest()
        {
            string msgid = @"The type of parameter \""${0}\"" is not supported";
            string msgstr = @"Il tipo del parametro \""${0}\"" non è supportato";

            string parsedMsgid = @"The type of parameter ""${0}"" is not supported";
            string parsedMsgstr = @"Il tipo del parametro ""${0}"" non è supportato";

            PoParser target = new PoParser();
            TextReader reader = new StringReader(String.Format(@"
            msgid ""{0}""
            msgstr ""{1}""
            ", msgid, msgstr));
            
            var actual = target.ParseIntoDictionary(reader);

            Assert.AreEqual(1, actual.Count, "Parsed dictionary entries count do not match");
            Assert.AreEqual(parsedMsgid, actual.Keys.ToArray()[0], "Key does not match");
            Assert.AreEqual(parsedMsgstr, actual.Values.ToArray()[0], "Value does not match");
        }