Ejemplo n.º 1
0
        private int NextDelimitedSegmentText(string leftDel, string rightDel, int startAt, out string transSegmentText)
        {
            //Find the first occurance of a left delimiter starting from startAt
            var leftDelIndex =
                OriginalText.IndexOf(
                    leftDel,
                    startAt,
                    StringComparison.Ordinal
                    );

            while (true)
            {
                //No left delimiter is found. end search for segment placeholder
                if (leftDelIndex < 0)
                {
                    transSegmentText = null;
                    return(-1);
                }

                //Find first occurance of a right delimiter starting after the left delimiter that was found
                var rightDelIndex =
                    OriginalText.IndexOf(
                        rightDel,
                        leftDelIndex + leftDel.Length,
                        StringComparison.Ordinal
                        );

                //A right delimiter is not found. End search for segment placeholder
                if (rightDelIndex <= leftDelIndex)
                {
                    transSegmentText = null;
                    return(-1);
                }

                //A right delimiter is found
                var startIndex = leftDelIndex + leftDel.Length;
                var endIndex   = rightDelIndex - 1;
                var length     = endIndex - startIndex + 1;

                //Read the text between the left and right delimiters
                var segmentText = OriginalText.Substring(startIndex, length);

                transSegmentText = segmentText;

                return(leftDelIndex);
            }
        }
Ejemplo n.º 2
0
        private int NextIdentifiedSegmentText(string leftDel, int startAt, out string transSegmentText)
        {
            //Find the first occurance of a left delimiter starting from startAt
            var leftDelIndex =
                OriginalText.IndexOf(
                    leftDel,
                    startAt,
                    StringComparison.Ordinal
                    );

            while (true)
            {
                //No left delimiter is found. end search for segment placeholder
                if (leftDelIndex < 0)
                {
                    transSegmentText = null;
                    return(-1);
                }

                //Search for a legal identifier name
                var lastIdntIndex = leftDelIndex + 1;

                while (lastIdntIndex < OriginalText.Length)
                {
                    var c = OriginalText[lastIdntIndex];

                    if (c == '_' || char.IsLetterOrDigit(c))
                    {
                        lastIdntIndex++;
                    }
                    else
                    {
                        break;
                    }
                }

                //A legal identifier name is not found. Continue search for a following left delimiter
                if (lastIdntIndex == leftDelIndex + 1)
                {
                    leftDelIndex =
                        OriginalText.IndexOf(
                            leftDel,
                            leftDelIndex + 1,
                            StringComparison.Ordinal
                            );

                    continue;
                }

                //A right delimiter is found
                var startIndex = leftDelIndex + leftDel.Length;
                var endIndex   = lastIdntIndex - 1;
                var length     = endIndex - startIndex + 1;

                //Read the identifier name
                var segmentText = OriginalText.Substring(startIndex, length);

                transSegmentText = segmentText;

                return(leftDelIndex);
            }
        }