Accord.Math.MatrixFormatter.parseOptions C# (CSharp) Method

parseOptions() private static method

Parses a format string containing the format options for the matrix representation.
private static parseOptions ( string format, string &newline, string &elementFormat ) : bool
format string
newline string
elementFormat string
return bool
        private static bool parseOptions(string format, out string newline, out string elementFormat)
        {
            // "{0,g}"      -> multiline with system new line character and number format g
            // "{0:Mr,g}"   -> multiline with \r new line character (old Mac) and number format g
            // "{0:Mn,g}"   -> multiline with \n new line character (Unix-like) and number format g
            // "{0:Mrn,g}"  -> multiline with \r\n new line character (Windows) and number format g
            // "{0:Ms,g}"   -> single line and number format g

            if (String.IsNullOrEmpty(format))
            {
                newline = Environment.NewLine;
                elementFormat = String.Empty;
                return true;
            }

            string[] options = format.Split(',');

            if (options.Length == 1)
            {
                elementFormat = String.Empty;

                switch (options[0])
                {
                    case "Mr":
                        newline = "\r";
                        return true;

                    case "Mn":
                        newline = "\n";
                        return true;

                    case "Mrn":
                        newline = "\r\n";
                        return true;

                    case "Ms":
                        newline = String.Empty;
                        return true;

                    default:
                        newline = Environment.NewLine;
                        elementFormat = format;
                        return true;
                }
            }

            if (options.Length == 2)
            {
                elementFormat = options[1];

                switch (options[0])
                {
                    case "Mr":
                        newline = "\r"; break;

                    case "Mn":
                        newline = "\n"; break;

                    case "Mrn":
                        newline = "\r\n"; break;

                    case "Ms":
                        newline = String.Empty; break;

                    default:
                        newline = String.Empty;
                        return false;
                }

                return true;
            }

            newline = String.Empty;
            elementFormat = format;
            return false;
        }