예제 #1
0
        Carriage ParseCarriage(string carriageText)
        {
            var pieces             = carriageText.Split('+');
            var maybeCarriageFlair = pieces.First().Split(':');

            var i = 1;

            for (; i < maybeCarriageFlair.Length && !Constants.KnownFlair.Contains(maybeCarriageFlair[i]); i += 2)
            {
            }
            i--;

            var flair = string.Join(':', maybeCarriageFlair, 0, i);

            if (i > 1)
            {
                flair += ":";
            }
            var riderBits = string.Join(':', maybeCarriageFlair, i, maybeCarriageFlair.Length - i);
            var riderFullyReconstructed = string.Join('+', new[] { riderBits }.Concat(pieces.Skip(1)));


            var carriage = new Carriage
            {
                Flairs = ParseCarriageFlairs(flair),
                Riders = ParseRiders(riderFullyReconstructed)
            };

            return(carriage);
        }
예제 #2
0
        string FormatCarriage(Carriage carriage)
        {
            var rider = FormatRiders(carriage.Riders);

            return($"{FormatCarriageFlairs(carriage.Flairs)}{rider}");
        }