Exemple #1
0
    static void ImportCsv()
    {
        string csvPath = EditorUtility.OpenFilePanel("Select CSV file", "", "csv");

        if (csvPath.Length == 0)
        {
            return;
        }

        var csv   = File.ReadAllText(csvPath);
        var bytes = CsvToFlexBufferConverter.Convert(csv, FlexBuffersPreferences.CsvSeparator);

        if (bytes == null)
        {
            return;
        }

        var fileName = Path.GetFileNameWithoutExtension(csvPath);

        var flxPath = EditorUtility.SaveFilePanel(
            "Save as FlexBuffer",
            "",
            fileName + ".bytes",
            "bytes");

        if (flxPath.Length != 0)
        {
            File.WriteAllBytes(flxPath, bytes);
        }
    }
        public void MultipleLineWithSpecialSeparatorAndDoubleQuotesEscapingLineBreak()
        {
            var bytes = CsvToFlexBufferConverter.Convert(
                @"A;B;C
1;2;3
""ds
kfsdh"";sdfsdf;sdfsf
", ';');
            var flx  = FlxValue.FromBytes(bytes);
            var json = flx.ToJson;

            Assert.AreEqual(flx.AsVector.Length, 3);
            Assert.AreEqual(flx[0].AsVector.Length, 3);
            Assert.AreEqual(flx[0][0].AsString, "A");
            Assert.AreEqual(flx[0][1].AsString, "B");
            Assert.AreEqual(flx[0][2].AsString, "C");

            Assert.AreEqual(flx[1][0].AsString, "1");
            Assert.AreEqual(flx[1][1].AsString, "2");
            Assert.AreEqual(flx[1][2].AsString, "3");

            Assert.AreEqual(flx[2][0].AsString, "ds\nkfsdh");
            Assert.AreEqual(flx[2][1].AsString, "sdfsdf");
            Assert.AreEqual(flx[2][2].AsString, "sdfsf");
        }
        public void SimpleCSV()
        {
            var bytes = CsvToFlexBufferConverter.Convert("A,B,C");
            var flx   = FlxValue.FromBytes(bytes);

            Assert.AreEqual(flx.AsVector.Length, 1);
            Assert.AreEqual(flx[0].AsVector.Length, 3);
            Assert.AreEqual(flx[0][0].AsString, "A");
            Assert.AreEqual(flx[0][1].AsString, "B");
            Assert.AreEqual(flx[0][2].AsString, "C");
        }
        public void MultipleLineCSV()
        {
            var bytes = CsvToFlexBufferConverter.Convert(
                @"A,B,C
1,2,3
dskfsdh,sdfsdf,sdfsf");
            var flx  = FlxValue.FromBytes(bytes);
            var json = flx.ToJson;

            Assert.AreEqual(flx.AsVector.Length, 3);
            Assert.AreEqual(flx[0].AsVector.Length, 3);
            Assert.AreEqual(flx[0][0].AsString, "A");
            Assert.AreEqual(flx[0][1].AsString, "B");
            Assert.AreEqual(flx[0][2].AsString, "C");

            Assert.AreEqual(flx[1][0].AsString, "1");
            Assert.AreEqual(flx[1][1].AsString, "2");
            Assert.AreEqual(flx[1][2].AsString, "3");

            Assert.AreEqual(flx[2][0].AsString, "dskfsdh");
            Assert.AreEqual(flx[2][1].AsString, "sdfsdf");
            Assert.AreEqual(flx[2][2].AsString, "sdfsf");
        }