Exemple #1
0
        /// <summary>
        /// Parses vCard from the specified stream.
        /// </summary>
        /// <param name="fileStrings">List of strings that contains vCard.</param>
        public void ParseStrings(List <string> fileStrings)
        {
            m_pItems.Clear();
            m_pPhoneNumbers   = null;
            m_pEmailAddresses = null;

            int    lineCount = 0;
            string line      = fileStrings[lineCount];

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

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

                // Item syntax: name[*(;parameter)]:value
                string[] name_params = name_value[0].Split(new char[] { ';' }, 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);
            }
        }
Exemple #2
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, System.Text.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 char[] { ':' }, 2);

                // Item syntax: name[*(;parameter)]:value
                string[] name_params = name_value[0].Split(new char[] { ';' }, 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);
            }
        }
Exemple #3
0
        /// <summary>
        /// Parses vCard from the specified stream.
        /// </summary>
        /// <param name="fileStrings">List of strings that contains vCard.</param>
        public void ParseStrings(List<string> fileStrings)
        {
            m_pItems.Clear();
            m_pPhoneNumbers = null;
            m_pEmailAddresses = null;

            int lineCount = 0;
            string line = fileStrings[lineCount];
            // Find row BEGIN:VCARD
            while(line != null && line.ToUpper() != "BEGIN:VCARD"){
                line = fileStrings[lineCount++];
            }
            // Read first vCard line after BEGIN:VCARD
            line = fileStrings[lineCount++];
            while(line != null && line.ToUpper() != "END:VCARD"){
                StringBuilder item = new StringBuilder();
                item.Append(line);
                // Get next line, see if item continues (folded line).
                line = fileStrings[lineCount++];
                while(line != null && (line.StartsWith("\t") || line.StartsWith(" "))){
                    item.Append(line.Substring(1));
                    line = fileStrings[lineCount++];
                }

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

                // Item syntax: name[*(;parameter)]:value
                string[] name_params = name_value[0].Split(new char[]{';'},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);
            }
        }
        /// <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,System.Text.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 char[]{':'},2);

                // Item syntax: name[*(;parameter)]:value
                string[] name_params = name_value[0].Split(new char[]{';'},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);
            }
        }