Parse() public static méthode

Parses given string as the parameter.
public static Parse ( string parameter ) : HeaderParameter
parameter string Parameter string to be parsed.
Résultat HeaderParameter
Exemple #1
0
        internal static HeaderValue ParseInternal(string header, string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            HeaderParameterCollection parameters       = new HeaderParameterCollection();
            StringBuilder             currentValue     = new StringBuilder(64);
            StringBuilder             currentParameter = new StringBuilder(128);
            StringBuilder             currentTarget    = currentValue;
            bool isInString = false;
            bool isEscape   = false;

            foreach (char letter in value)
            {
                switch (letter)
                {
                default:
                    ParseOtherChars(letter, currentTarget, ref isInString, ref isEscape);
                    break;

                case '\\':
                    ParseEscapeChar(letter, currentTarget, ref isInString, ref isEscape);
                    break;

                case '"':
                    ParseStringChar(letter, currentTarget, ref isInString, ref isEscape);
                    break;

                case ';':
                    ParseSeparatorChar(letter, ref currentTarget, ref isInString, ref isEscape, currentValue, currentParameter, parameters);
                    break;
                }
            }

            if (currentParameter.Length > 0)
            {
                parameters.Add(HeaderParameter.Parse(currentParameter.ToString().Trim()));
            }

            return(CreateInstance(header, currentValue.ToString(), parameters));
        }
Exemple #2
0
 private static void ParseSeparatorChar(char chr, ref StringBuilder currentTarget, ref bool isInString, ref bool isEscape, StringBuilder currentValue, StringBuilder currentParameter, HeaderParameterCollection parameters)
 {
     if (isEscape)
     {
         isEscape = false;
         currentTarget.Append("\\" + chr);
     }
     else if (isInString)
     {
         currentTarget.Append(chr);
     }
     else
     {
         if (currentTarget == currentValue)
         {
             currentTarget = currentParameter;
         }
         else
         {
             parameters.Add(HeaderParameter.Parse(currentParameter.ToString().Trim()));
             currentParameter.Clear();
         }
     }
 }