//Dispatch cards to be encoded to an encoder selected by command line option. then stitch them together in a stringbuilder. public string EncodeCardCollection(CardCollection cardCollection, EncodingFormats encodingFormat) { var outputBuilder = new StringBuilder(); var encoder = InstanciateEncoder(encodingFormat); if (ShuffleFields && encodingFormat == EncodingFormats.scfdivineFormat) { Console.WriteLine("This format cannot be shuffled"); ShuffleFields = false; } if (IncludeFlavorText && encodingFormat == EncodingFormats.MtgEncoderFormat) { ((MtgEncodeFormatEncoder)encoder).IncludeFlavorText = IncludeFlavorText; } foreach (var card in cardCollection.Cards) { var cardOutput = encoder.EncodeCard(card); if (string.IsNullOrWhiteSpace(cardOutput)) { continue; } if (ShuffleFields) { cardOutput = ShuffleCardFields(cardOutput); } outputBuilder.Append($"{cardOutput}\n\n"); } return(outputBuilder.ToString()); }
public static string GetFormatCode(EncodingFormats format) { if (format == EncodingFormats.ASCII) { return(ASCIIFormatCode); } return(Base64FormatCode); }
public static string ConvertBytesToString(byte[] encodedBytes, EncodingFormats format) { if (format == EncodingFormats.Base64) { return(Convert.ToBase64String(encodedBytes)); } else { return(Encoding.ASCII.GetString(encodedBytes)); } }
public static byte[] GetBytesFromString(string original, EncodingFormats format) { if (format == EncodingFormats.Base64) { return(Convert.FromBase64String(original)); } else { return(Encoding.ASCII.GetBytes(original)); } }
//Return an encoder based on the requested decodingFormat private IDecoderInterface InstanciateDecoder(EncodingFormats decodingFormat) { switch (decodingFormat) { case EncodingFormats.scfdivineFormat: return(new scfdivineFormatDecoder()); case EncodingFormats.MtgEncoderFormat: default: return(new MtgEncodeFormatDecoder()); } }
//Return an encoder based on the requested encodingFormat public IEncoderInterface InstanciateEncoder(EncodingFormats encodingFormat) { switch (encodingFormat) { case EncodingFormats.scfdivineFormat: return(new scfdivineFormatEncoder()); case EncodingFormats.MtgEncoderFormat: default: return(new MtgEncodeFormatEncoder()); } }
//Dispatch lines to be decoded to a decoder selected by decodingFormat public CardCollection DecodeString(string inputData, EncodingFormats decodingFormat) { PotentialCards = 0; ActualCards = 0; var cardCollection = new CardCollection(); var decoder = InstanciateDecoder(decodingFormat); if (string.IsNullOrWhiteSpace(inputData)) { Console.WriteLine("Input contained no data."); return(cardCollection); } using (StringReader reader = new StringReader(inputData)) { string line; while ((line = reader.ReadLine()) != null) { if (string.IsNullOrWhiteSpace(line)) { continue; } PotentialCards++; var card = decoder.DecodeCard(line); if (card != null) { ActualCards++; SetAdditionalData(card); cardCollection.Cards.Add(card); _ConsoleLog.VerboseWriteLine(card + Environment.NewLine); } else { _ConsoleLog.VerboseWriteLine($"Dud: '{line}'" + Environment.NewLine); } } } return(cardCollection); }
public StringUtilities(EncodingFormats format) { EncodingFormat = format; }
public StringEncoder(EncodingFormats format) { this.EncodingFormat = format; m_byteShift = 53; }