Exemple #1
0
 public static string Unescape(string str)
 {
     if (str == null)
     {
         throw new ArgumentNullException("str");
     }
     return(Parser.Unescape(str));
 }
Exemple #2
0
        // private
        private void Compile()
        {
            replacement = Parser.Unescape(replacement);

            int  anchor = 0, ptr = 0, saveptr;
            char c;

            while (ptr < replacement.Length)
            {
                c = replacement [ptr++];

                if (c != '$')
                {
                    continue;
                }

                // If the '$' was the last character, just emit it as is
                if (ptr == replacement.Length)
                {
                    break;
                }

                // If we saw a '$$'
                if (replacement [ptr] == '$')
                {
                    // Everthing from 'anchor' upto and including the first '$' is copied from the replacement string
                    AddFromReplacement(anchor, ptr);
                    // skip over the second '$'.
                    anchor = ++ptr;
                    continue;
                }

                saveptr = ptr - 1;

                int from_match = CompileTerm(ref ptr);

                // We couldn't recognize the term following the '$'.  Just treat it as a literal.
                // 'ptr' has already been advanced, no need to rewind it back
                if (from_match >= 0)
                {
                    continue;
                }

                AddFromReplacement(anchor, saveptr);
                AddInt(from_match);
                anchor = ptr;
            }

            // If we never needed to advance anchor, it means the result is the whole replacement string.
            // We optimize that case by never allocating the pieces array.
            if (anchor != 0)
            {
                AddFromReplacement(anchor, ptr);
            }
        }
Exemple #3
0
 public static string Unescape(string str)
 {
     return(Parser.Unescape(str));
 }