private IList <string> ExtractCharacterSpecifiers(string characterClass, bool spellOutWhitespace)
        {
            var specifiers = CharacterRanges.Matches(characterClass);
            var result     = new List <string>();

            foreach (Match specifier in specifiers)
            {
                if (specifier.Value.Contains("\\"))
                {
                    if (specifier.Value.EndsWith("-\\"))
                    {
                        throw new ArgumentException("Character Ranges that have incorrectly escaped characters as target are not allowed");
                    }

                    if (specifier.Value.Length == 1)
                    {
                        // Something's bork with the Pattern. For now we skip this it shouldn't affect anyone
                        continue;
                    }
                }

                result.Add(spellOutWhitespace && WhitespaceToString.IsFullySpellingOutApplicable(specifier.Value, out var spelledOutWhiteSpace)
                    ? spelledOutWhiteSpace
                    : specifier.Value);
            }
            return(result);
        }
Example #2
0
        public string Description(bool spellOutWhitespace)
        {
            // here be dragons!
            // keep track of:
            // - escaped chars
            // - escape sequences (each having a different description)
            // - codepoint escapes (belongs into above category but kept separate)
            // - and actually boring literal matches
            if (Specifier.Length > 1)
            {
                var relevant = Specifier.Substring(1); // skip the damn Backslash at the start
                if (relevant.Length > 1)               // longer sequences
                {
                    if (relevant.StartsWith("u"))
                    {
                        return(string.Format(AssistantResources.AtomDescription_Literal_UnicodePoint, relevant.Substring(1))); //skip u
                    }

                    if (relevant.StartsWith("x"))
                    {
                        return(string.Format(AssistantResources.AtomDescription_Literal_HexCodepoint, relevant.Substring(1))); // skip x
                    }

                    return(string.Format(AssistantResources.AtomDescription_Literal_OctalCodepoint, relevant)); // no format specifier to skip
                }

                if (EscapeLiterals.Contains(relevant[0]))
                {
                    return(string.Format(AssistantResources.AtomDescription_Literal_EscapedLiteral, relevant));
                }

                if (char.IsDigit(relevant[0]))
                {
                    return(string.Format(AssistantResources.AtomDescription_Literal_Backreference, relevant));
                }

                return(_escapeDescriptions[relevant[0]]);
            }

            if (Specifier.Equals("."))
            {
                return(AssistantResources.AtomDescription_Dot);
            }

            return(string.Format(AssistantResources.AtomDescription_Literal_ActualLiteral,
                                 spellOutWhitespace && WhitespaceToString.IsFullySpellingOutApplicable(Specifier, out var spelledOutWhiteSpace)
                    ? spelledOutWhiteSpace
                    : Specifier));
        }
Example #3
0
 public string Description(bool spellOutWhitespace) => string.Format(AssistantResources.AtomDescription_Group,
                                                                     spellOutWhitespace && WhitespaceToString.IsFullySpellingOutApplicable(Specifier, out var spelledOutWhiteSpace)
         ? spelledOutWhiteSpace
         : Specifier);