Xwt.Drawing.Image.ParseImageHints C# (CSharp) Method

ParseImageHints() static private method

static private ParseImageHints ( string baseName, string fileName, string ext, int &scale, ImageTagSet &tags ) : bool
baseName string
fileName string
ext string
scale int
tags ImageTagSet
return bool
        static bool ParseImageHints(string baseName, string fileName, string ext, out int scale, out ImageTagSet tags)
        {
            scale = 1;
            tags = ImageTagSet.Empty;

            if (!fileName.StartsWith (baseName, StringComparison.Ordinal) || fileName.Length <= baseName.Length + 1 || (fileName [baseName.Length] != '@' && fileName [baseName.Length] != '~'))
                return false;

            fileName = fileName.Substring (0, fileName.Length - ext.Length);

            int i = baseName.Length;
            if (fileName [i] == '~') {
                // For example: foo~dark@2x
                i++;
                var i2 = fileName.IndexOf ('@', i);
                if (i2 != -1) {
                    int i3 = fileName.IndexOf ('x', i2 + 2);
                    if (i3 == -1 || !int.TryParse (fileName.Substring (i2 + 1, i3 - i2 - 1), out scale))
                        return false;
                } else
                    i2 = fileName.Length;
                tags = new ImageTagSet (fileName.Substring (i, i2 - i));
                return true;
            }
            else {
                // For example: foo@2x~dark
                i++;
                var i2 = fileName.IndexOf ('~', i + 1);
                if (i2 == -1)
                    i2 = fileName.Length;

                i2--;
                if (i2 < 0 || fileName [i2] != 'x')
                    return false;

                var s = fileName.Substring (i, i2 - i);
                if (!int.TryParse (s, out scale)) {
                    tags = null;
                    return false;
                }
                if (i2 + 2 < fileName.Length)
                    tags = new ImageTagSet (fileName.Substring (i2 + 2));
                return true;
            }
        }