Ejemplo n.º 1
0
        /// <summary>
        /// Divide sequencia
        /// </summary>
        /// <param name="prev"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        private string SplitSequence(string prev, string next)
        {
            char value, minVal, maxVal;
            int  size, index;

            index = 0;
            size  = prev.Length - 1;
            while (index <= size && prev[index] == next[index])
            {
                index++;
            }
            if (index >= 0 && index < prev.Length)
            {
                minVal = prev[index];
            }
            else
            {
                minVal = DelphiFunctions.Pred('A');
            }
            if (index >= 0 && index < next.Length)
            {
                maxVal = next[index];
            }
            else
            {
                maxVal = DelphiFunctions.Succ('Z');
            }
            value = (char)(((int)minVal + (int)maxVal) >> 1);
            while (value == minVal || value == maxVal)
            {
                if (index <= size)
                {
                    index++;
                }
                maxVal = 'Z';
                if (index > size)
                {
                    minVal = 'A';
                }
                else
                {
                    minVal = prev[index];
                }
                value = (char)(((int)minVal + (int)maxVal) >> 1);
            }
            var result = prev;

            if (index > size)
            {
                DelphiFunctions.SetLength(ref result, index);
            }
            if (index >= size)
            {
                var resultArray = result.ToCharArray();
                resultArray[index] = value;
                result             = new string(resultArray);
            }
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Incrementa a sequencia
        /// </summary>
        /// <param name="value"></param>
        private void IncSequence(ref string value)
        {
            int step, index;

            step = 'E' - 'A';
            char[] array = value.ToCharArray();
            for (index = value.Length - 1; index >= 0; index--)
            {
                DelphiFunctions.Inc(ref array[index], step);
                if (array[index] > 'Z')
                {
                    step = 1;
                    DelphiFunctions.Dec(ref array[index], 'Z' - 'A' + 1);
                }
                else
                {
                    break;
                }
            }
            value = new string(array);
        }