/// <summary> /// Construct a property from the specified string input. /// </summary> /// <param name="input">A string representation of the property as read from a vCard object.</param> internal PropertyBase(string input) { // Make sure input is not empty if (string.IsNullOrWhiteSpace(input)) { throw new ArgumentNullException("input"); } // Split out the name/value. if (input.NonQuotedIndexOf(Constants.PROP_NAME_VAL_SEPARATOR) < 0) { throw new ArgumentOutOfRangeException("input", $"No name/value separator [{Constants.PROP_NAME_VAL_SEPARATOR}] is could be found. Improperly formed input."); } var nameValue = input.NonQuotedSplitOnFirst(Constants.PROP_NAME_VAL_SEPARATOR); nameValue.Item1.UnQuote(); // Separate out the name/parameters if (nameValue.Item1.NonQuotedIndexOf(Constants.PROP_PARAMETER_SEPARATOR) > 0) { var nameParam = nameValue.Item1.NonQuotedSplitOnFirst(Constants.PROP_PARAMETER_SEPARATOR); // Parse the name ParseNamePart(nameParam.Item1); foreach (string s in nameParam.Item2.NonQuotedSplit(Constants.PROP_PARAMETER_SEPARATOR, false)) { try { AddParameter(s.ParseParam()); } catch { } } } else { // No parameters, just parse the name ParseNamePart(nameValue.Item1); } // Set the RawValue RawValue = nameValue.Item2; // Process the values if (Value is IList) { if (Value == null) { Value = Activator.CreateInstance <T>(); } foreach (string s in nameValue.Item2.NonQuotedSplit(VALUE_SEPARATOR, true)) { AddValue(IETFValueEncoding.DecodeValue(s)); } } else { SetValue(IETFValueEncoding.DecodeValue(nameValue.Item2)); } }
internal PropertyBase(string name, string parameters, string value) { Name = name; if (!string.IsNullOrWhiteSpace(parameters)) { foreach (string s in parameters.NonQuotedSplit(Constants.PROP_PARAMETER_SEPARATOR, false)) { try { AddParameter(s.ParseParam()); } catch { } } } // Set RawValue RawValue = value; if (!string.IsNullOrWhiteSpace(value)) { // Process the values if (Value is IList) { if (Value == null) { Value = Activator.CreateInstance <T>(); } foreach (string s in value.NonQuotedSplit(VALUE_SEPARATOR, true)) { AddValue(IETFValueEncoding.DecodeValue(s)); } } else { SetValue(IETFValueEncoding.DecodeValue(value)); } } else { SetValue(default);
public void DecodeValueTest(string expected, string input) => Assert.AreEqual(expected, IETFValueEncoding.DecodeValue(input));