public static VCard GetVCard(string contents) { var vcard = new VCard() { SerializedCard = contents }; if (string.IsNullOrWhiteSpace(contents) || !contents.TrimStart().StartsWith("BEGIN:VCARD") || !contents.TrimEnd().EndsWith("END:VCARD")) { throw new VCardParseException("The input is not a valid vCard file."); } var tokens = TokenParser.Parse(contents); foreach (var token in tokens) { if (string.IsNullOrWhiteSpace(token.Key)) { continue; } var keys = AllParsers.Parsers.Keys.ToList(); foreach (var key in keys) { var pattern = "^" + Regex.Escape(key).Replace("\\*", ".*") + "$"; var match = Regex.IsMatch(token.Key, pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); if (!match) { continue; } var implementation = AllParsers.Parsers[key]; implementation.Invoke(token, ref vcard); } } return(vcard); }
public static VCard GetVCard(string contents) { var vcard = new VCard(); if (string.IsNullOrWhiteSpace(contents)) { return(vcard); } var tokens = TokenParser.Parse(contents); foreach (var token in tokens) { if (string.IsNullOrWhiteSpace(token.Key)) { continue; } var keys = AllParsers.Parsers.Keys.ToList(); foreach (var key in keys) { var pattern = "^" + Regex.Escape(key).Replace("\\*", ".*") + "$"; var match = Regex.IsMatch(token.Key, pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); if (!match) { continue; } var implementation = AllParsers.Parsers[key]; implementation.Invoke(token, ref vcard); } } return(vcard); }