private string StripFormatSpecifier()

in src/MIDebugEngine/Engine.Impl/Variables.cs [368:435]


        private string StripFormatSpecifier(string exp, out string formatSpecifier)
        {
            formatSpecifier = null; // will be used with -var-set-format
            int lastComma = exp.LastIndexOf(',');
            if (lastComma <= 0)
                return exp;

            // https://docs.microsoft.com/en-us/visualstudio/debugger/format-specifiers-in-cpp
            string expFS = exp.Substring(lastComma + 1);
            string trimmed = expFS.Trim();
            switch (trimmed)
            {
                case "x":
                case "X":
                case "h":
                case "H":
                case "xb":
                case "Xb":
                case "hb":
                case "Hb":
                    // could be improved upon via post-processing with ToUpperInvariant/SubString
                    formatSpecifier = "zero-hexadecimal";
                    goto case "";
                case "o":
                    formatSpecifier = "octal";
                    goto case "";
                case "d":
                    formatSpecifier = "decimal";
                    goto case "";
                case "b":
                case "bb":
                    formatSpecifier = "binary";
                    goto case "";
                case "e":
                case "g":
                    goto case "";
                case "s":
                case "sb":
                case "s8":
                case "s8b":
                    return "(const char*)(" + exp.Substring(0, lastComma) + ")";
                case "su":
                case "sub":
                    return "(const char16_t*)(" + exp.Substring(0, lastComma) + ")";
                case "c":
                    return "(char)(" + exp.Substring(0, lastComma) + ")";
                // just remove and ignore these
                case "en":
                case "na":
                case "nd":
                case "nr":
                case "!":
                case "":
                    return exp.Substring(0, lastComma);
            }

            // array with static size
            // TODO: could return '(T(*)[n])(exp)' but requires T
            var m = Regex.Match(trimmed, @"^\[?(\d+)\]?$");
            if (m.Success)
                return exp.Substring(0, lastComma);

            // array with dynamic size
            if (Regex.Match(trimmed, @"^\[([a-zA-Z_][a-zA-Z_\d]*)\]$").Success)
                return exp.Substring(0, lastComma);

            return exp;
        }