コード例 #1
0
        /// <summary>
        /// Parses vCard from the specified stream.
        /// </summary>
        /// <param name="stream">Stream what contains vCard.</param>
        public void Parse(Stream stream)
        {
            m_pItems.Clear();
            m_pPhoneNumbers   = null;
            m_pEmailAddresses = null;

            TextReader r    = new StreamReader(stream, Encoding.Default);
            string     line = r.ReadLine();

            // Find row BEGIN:VCARD
            while (line != null && line.ToUpper() != "BEGIN:VCARD")
            {
                line = r.ReadLine();
            }
            // Read frist vCard line after BEGIN:VCARD
            line = r.ReadLine();
            while (line != null && line.ToUpper() != "END:VCARD")
            {
                StringBuilder item = new StringBuilder();
                item.Append(line);
                // Get next line, see if item continues (folded line).
                line = r.ReadLine();
                while (line != null && (line.StartsWith("\t") || line.StartsWith(" ")))
                {
                    item.Append(line.Substring(1));
                    line = r.ReadLine();
                }

                string[] name_value = item.ToString().Split(new[] { ':' }, 2);

                // Item syntax: name[*(;parameter)]:value
                string[] name_params = name_value[0].Split(new[] { ';' }, 2);
                string   name        = name_params[0];
                string   parameters  = "";
                if (name_params.Length == 2)
                {
                    parameters = name_params[1];
                }
                string value = "";
                if (name_value.Length == 2)
                {
                    value = name_value[1];
                }
                m_pItems.Add(name, parameters, value);
            }
        }
コード例 #2
0
ファイル: vCard.cs プロジェクト: haoasqui/ONLYOFFICE-Server
        /// <summary>
        /// Parses vCard from the specified stream.
        /// </summary>
        /// <param name="stream">Stream what contains vCard.</param>
        public void Parse(Stream stream)
        {
            m_pItems.Clear();
            m_pPhoneNumbers = null;
            m_pEmailAddresses = null;

            TextReader r = new StreamReader(stream, Encoding.Default);
            string line = r.ReadLine();
            // Find row BEGIN:VCARD
            while (line != null && line.ToUpper() != "BEGIN:VCARD")
            {
                line = r.ReadLine();
            }
            // Read frist vCard line after BEGIN:VCARD
            line = r.ReadLine();
            while (line != null && line.ToUpper() != "END:VCARD")
            {
                StringBuilder item = new StringBuilder();
                item.Append(line);
                // Get next line, see if item continues (folded line).
                line = r.ReadLine();
                while (line != null && (line.StartsWith("\t") || line.StartsWith(" ")))
                {
                    item.Append(line.Substring(1));
                    line = r.ReadLine();
                }

                string[] name_value = item.ToString().Split(new[] {':'}, 2);

                // Item syntax: name[*(;parameter)]:value
                string[] name_params = name_value[0].Split(new[] {';'}, 2);
                string name = name_params[0];
                string parameters = "";
                if (name_params.Length == 2)
                {
                    parameters = name_params[1];
                }
                string value = "";
                if (name_value.Length == 2)
                {
                    value = name_value[1];
                }
                m_pItems.Add(name, parameters, value);
            }
        }