using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace FBPLib
{
    public class Port
    {
        /* 
 *  This class ensures that Network connect statements use "real" port names, 
 *  rather than arbitrary character strings 
 */

        public string name;

        public int index; // -1 if array port

        public string displayName = null;

        public Port(string n, int i)
        {
            name = n;
            index = i;
            if (index == -1)
            {
                Regex re = new Regex(@"^(\w+)\[(\d+)\]$");  // test for square bracket
                Match m = re.Match(name);
                if (m.Success)
                {
                    name = m.Groups[1].Value;
                    index = Int32.Parse(m.Groups[2].Value);
                }
            }
            if (index != -1)  // index may have changed!
                displayName = String.Format("{0}[{1}]", name, index);
            else 
                displayName = String.Format("{0}", name);
        }
    }
}

