Exemple #1
0
        private int AddUnmarkedSegment(int segmentTextStart, int segmentTextEnd)
        {
            if (segmentTextEnd < segmentTextStart)
            {
                return(-1);
            }

            var originalSegmentText =
                OriginalText.Substring(
                    segmentTextStart,
                    segmentTextEnd - segmentTextStart + 1
                    );

            var segmentTextHash = originalSegmentText.GetHashSha256();

            MappingComposerSegment segment;

            if (_segmentsDictionary.TryGetValue(segmentTextHash, out segment) == false)
            {
                segment = new MappingComposerSegment(UniqueSegmentsCount, UniqueUnmarkedSegmentsCount, originalSegmentText);

                _segmentsDictionary.Add(segmentTextHash, segment);

                UniqueUnmarkedSegmentsCount++;
            }

            _segmentsList.Add(segment);

            return(segmentTextEnd + 1);
        }
Exemple #2
0
 /// <summary>
 /// メタデータを含むテキストデータを解析
 /// </summary>
 /// <param name="text">解析するテキスト</param>
 protected virtual void Parse()
 {
     try
     {
         //テキストを先頭から1文字づつ解析
         int max   = OriginalText.Length;
         int index = 0;
         while (index < max)
         {
             if (ParseEscapeSequence(index))
             {
                 //エスケープシーケンスの処理
                 index += 2;
             }
             else
             {
                 string tagName  = "";
                 string tagArg   = "";
                 int    endIndex = ParserUtil.ParseTag(OriginalText, index,
                                                       (name, arg) =>
                 {
                     bool ret = ParseTag(name, arg);
                     if (ret)
                     {
                         tagName = name;
                         tagArg  = arg;
                     }
                     return(ret);
                 });
                 if (index == endIndex)
                 {
                     //タグがなかった
                     //通常パターンのテキストを1文字追加
                     AddChar(OriginalText[index]);
                     ++index;
                 }
                 else
                 {
                     //タグデータを挿入
                     string tagString = OriginalText.Substring(index, endIndex - index + 1);
                     PoolList.Insert(0, MakeTag(tagString, tagName, tagArg));
                     index = endIndex + 1;
                 }
             }
             ParsedDataList.AddRange(PoolList);
             PoolList.Clear();
         }
         PoolList.Clear();
     }
     catch (System.Exception e)
     {
         AddErrorMsg(e.Message + e.StackTrace);
     }
 }
Exemple #3
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);
            }
        }
Exemple #4
0
        public int Execute()
        {
            try
            {
                string subText = "";

                subText = OriginalText.Substring(StartIndex, Length);

                if (VariableStorage.SubTextVar.ContainsKey(SubTextStorVar))
                {
                    VariableStorage.SubTextVar.Remove(SubTextStorVar);
                }
                VariableStorage.SubTextVar.Add(SubTextStorVar, Tuple.Create(this.ID, subText));


                return(1);
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
Exemple #5
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);
            }
        }
Exemple #6
0
 public override string GetValue()
 {
     return(OriginalText.Substring(Start, Length));
 }