예제 #1
0
        public static string FormatConcat(string template, params object[] values)
        {
            CompiledFormat cf = Compile(template);

            //string[] compiled = new string[cf.MaxPart * 2];
            string retval  = string.Empty;
            int    counter = 0;
            object val;

            for (int i = 0; i < cf.MaxPart; i++)
            {
                retval += cf.Parts[i];
                counter++;
                if ((cf.ParamId[i]) != -1)
                {
                    val = values[cf.ParamId[i]];
                    if (val is string)
                    {
                        retval += val as string;
                    }
                    else
                    {
                        retval += val.ToString();
                    }
                    counter++;
                }
            }

            return(retval);
        }
예제 #2
0
        public static string FormatList(string template, params object[] values)
        {
            CompiledFormat cf = Compile(template);

            //string[] compiled = new string[cf.MaxPart * 2];
            List <string> compiledList = new List <string>();

            //int counter = 0;
            object val;

            for (int i = 0; i < cf.MaxPart; i++)
            {
                compiledList.Add(cf.Parts[i]);
                if ((cf.ParamId[i]) != -1)
                {
                    val = values[cf.ParamId[i]];
                    if (val is string)
                    {
                        compiledList.Add(val as string);
                    }
                    else
                    {
                        compiledList.Add(val.ToString());
                    }
                }
            }

            return(string.Concat(compiledList.ToArray()));
        }
예제 #3
0
        public byte[] GetCompiledProgram(CompiledFormat format = LATEST_FORMAT)
        {
            switch (format)
            {
            case CompiledFormat.V1:
                return(GetCompiledProgramV1());

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #4
0
        /// <summary>
        /// Compiled String.Format equivalent
        /// <para>Fastest</para>
        /// </summary>
        /// <param name="template"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        public static string Format(string template, params object[] values)
        {
            CompiledFormat cf = Compile(template);

            StringBuilder sb      = new StringBuilder(template.Length + (values.Length * 5));
            var           maxpart = cf.MaxPart;

            for (int i = 0; i < maxpart; i++)
            {
                //if (cf.Parts.Length > i)
                sb.Append(cf.Parts[i]);

                if ((cf.ParamId[i]) != -1)
                {
                    sb.Append(values[cf.ParamId[i]]);
                }
            }
            return(sb.ToString());
        }
예제 #5
0
        public void LoadCompiledProgram(byte[] bytes, string fileName, CompiledFormat format = LATEST_FORMAT)
        {
            if (LogDebugMessage == null)
            {
                throw new YarnException("LogDebugMessage must be set before loading");
            }

            if (LogErrorMessage == null)
            {
                throw new YarnException("LogErrorMessage must be set before loading");
            }

            switch (format)
            {
            case CompiledFormat.V1:
                LoadCompiledProgramV1(bytes);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #6
0
        /// <summary>
        /// Compiles a format to CompiledFormat, uses the m_cache dictionary to store/load CompiledFormats
        /// </summary>
        /// <param name="template"></param>
        /// <returns></returns>
        private static CompiledFormat Compile(string template)
        {
            CompiledFormat cf;
            if (m_cache.TryGetValue(template, out cf))
                return cf;

            cf = new CompiledFormat();

            string[] parts = new string[10];
            int[] paramIds = new int[10] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };


            int currentPart = 0;
            bool insideBrackets = false;

            string tempstr = string.Empty;
            string tempParamId = string.Empty;

            int templatelength = template.Length;

            for (int i = 0; i < templatelength; i++)
            {
                char currentC = template[i];
                if (currentC == '{')
                {
                    insideBrackets = true;

                    if (parts.Length -1 == currentPart)
                    {
                        Array.Resize(ref parts, parts.Length * 2);
                        Array.Resize(ref paramIds, paramIds.Length * 2);
                        //nullify the array
                        for (int z = currentPart; z < paramIds.Length; z++)
                            paramIds[z] = -1;
                    }

                    parts[currentPart] = tempstr;


                    tempstr = "";

                    tempParamId = "";


                    continue;
                }
                else if (currentC == '}')
                {
                    insideBrackets = false;

                    paramIds[currentPart] = int.Parse(tempParamId);

                    currentPart++;

                    continue;
                }
                else
                {
                    if (insideBrackets == false)
                        tempstr = tempstr + currentC;
                    else
                        tempParamId = tempParamId + currentC;
                }
            }

            parts[currentPart] = tempstr;

            cf.MaxPart = currentPart + 1;
            cf.ParamId = paramIds;
            cf.Parts = parts;

            m_cache[template] = cf;
            return cf;
        }
예제 #7
0
 public void LoadCompiledProgram(byte[] bytes, string fileName, CompiledFormat format = LATEST_FORMAT)
 {
     throw new NotImplementedException("Loading compiled programs is not currently implemented.");
 }
예제 #8
0
        /// <summary>
        /// Compiles a format to CompiledFormat, uses the m_cache dictionary to store/load CompiledFormats
        /// </summary>
        /// <param name="template"></param>
        /// <returns></returns>
        private static CompiledFormat Compile(string template)
        {
            CompiledFormat cf;

            if (m_cache.TryGetValue(template, out cf))
            {
                return(cf);
            }

            cf = new CompiledFormat();

            string[] parts    = new string[10];
            int[]    paramIds = new int[10] {
                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
            };


            int  currentPart    = 0;
            bool insideBrackets = false;

            string tempstr     = string.Empty;
            string tempParamId = string.Empty;

            int templatelength = template.Length;

            for (int i = 0; i < templatelength; i++)
            {
                char currentC = template[i];
                if (currentC == '{')
                {
                    insideBrackets = true;

                    if (parts.Length - 1 == currentPart)
                    {
                        Array.Resize(ref parts, parts.Length * 2);
                        Array.Resize(ref paramIds, paramIds.Length * 2);
                        //nullify the array
                        for (int z = currentPart; z < paramIds.Length; z++)
                        {
                            paramIds[z] = -1;
                        }
                    }

                    parts[currentPart] = tempstr;


                    tempstr = "";

                    tempParamId = "";


                    continue;
                }
                else if (currentC == '}')
                {
                    insideBrackets = false;

                    paramIds[currentPart] = int.Parse(tempParamId);

                    currentPart++;

                    continue;
                }
                else
                {
                    if (insideBrackets == false)
                    {
                        tempstr = tempstr + currentC;
                    }
                    else
                    {
                        tempParamId = tempParamId + currentC;
                    }
                }
            }

            parts[currentPart] = tempstr;

            cf.MaxPart = currentPart + 1;
            cf.ParamId = paramIds;
            cf.Parts   = parts;

            m_cache[template] = cf;
            return(cf);
        }