コード例 #1
0
        public void Eof_Op_Bwd()
        {
            var dtb = new Dev2TokenizerBuilder
            {
                ToTokenize   = Search.ToStringBuilder(),
                ReverseOrder = true
            };


            dtb.AddEoFOp();

            var dt = dtb.Generate();

            var result = string.Empty;

            var cnt = 0;

            while (dt.HasMoreOps())
            {
                result += dt.NextToken();
                cnt++;
            }

            Assert.AreEqual("AB-CD-DE-FG-HI", result);
            Assert.IsTrue(cnt == 1);
        }
コード例 #2
0
        public void More_Then_One_Op_Fwd()
        {
            var dtb = new Dev2TokenizerBuilder {
                ToTokenize = Search.ToStringBuilder()
            };


            dtb.AddIndexOp(2);
            dtb.AddEoFOp();

            var dt = dtb.Generate();

            var result = string.Empty;

            var cnt = 0;

            while (dt.HasMoreOps())
            {
                result += dt.NextToken();
                cnt++;
            }

            Assert.AreEqual("AB-CD-DE-FG-HI", result);
            Assert.IsTrue(cnt == 2);
        }
コード例 #3
0
        public void Empty_String_Error()
        {
            Dev2TokenizerBuilder dtb = new Dev2TokenizerBuilder();

            dtb.ToTokenize = string.Empty;

            dtb.AddEoFOp();

            try {
                IDev2Tokenizer dt = dtb.Generate();

                Assert.Fail();
            }
            catch (Exception) {
                Assert.IsTrue(1 == 1);
            }
        }
コード例 #4
0
        public void Empty_String_Error()
        {
            var dtb = new Dev2TokenizerBuilder {
                ToTokenize = string.Empty.ToStringBuilder()
            };


            dtb.AddEoFOp();

            try
            {
                dtb.Generate();

                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.IsTrue(true);
            }
        }
コード例 #5
0
        public void Eof_Op_Fwd()
        {
            Dev2TokenizerBuilder dtb = new Dev2TokenizerBuilder();

            dtb.ToTokenize = search;

            dtb.AddEoFOp();

            IDev2Tokenizer dt = dtb.Generate();

            string result = string.Empty;

            int cnt = 0;

            while (dt.HasMoreOps())
            {
                result += dt.NextToken();
                cnt++;
            }

            Assert.AreEqual("AB-CD-DE-FG-HI", result);
            Assert.IsTrue(cnt == 1);
        }
コード例 #6
0
        private IDev2Tokenizer CreateSplitPattern(ref string stringToSplit, IEnumerable <DataSplitDTO> args, IExecutionEnvironment compiler, out ErrorResultTO errors, int update)
        {
            Dev2TokenizerBuilder dtb = new Dev2TokenizerBuilder {
                ToTokenize = stringToSplit, ReverseOrder = ReverseOrder
            };

            errors = new ErrorResultTO();

            foreach (DataSplitDTO t in args)
            {
                t.At = t.At ?? "";
                string entry;

                switch (t.SplitType)
                {
                case "Index":
                    try
                    {
                        entry = compiler.EvalAsListOfStrings(t.At, update).FirstOrDefault();
                        if (entry == null)
                        {
                            throw new Exception("null iterator expression");
                        }
                        string index    = entry;
                        int    indexNum = Convert.ToInt32(index);
                        if (indexNum > 0)
                        {
                            dtb.AddIndexOp(indexNum);
                        }
                    }
                    catch (Exception ex)
                    {
                        errors.AddError(ex.Message);
                    }
                    break;

                case "End":
                    dtb.AddEoFOp();
                    break;

                case "Space":
                    dtb.AddTokenOp(" ", t.Include);
                    break;

                case "Tab":
                    dtb.AddTokenOp("\t", t.Include);
                    break;

                case "New Line":
                    if (stringToSplit.Contains("\r\n"))
                    {
                        dtb.AddTokenOp("\r\n", t.Include);
                    }
                    else if (stringToSplit.Contains("\n"))
                    {
                        dtb.AddTokenOp("\n", t.Include);
                    }
                    else if (stringToSplit.Contains("\r"))
                    {
                        dtb.AddTokenOp("\r", t.Include);
                    }
                    break;

                case "Chars":
                    if (!string.IsNullOrEmpty(t.At))
                    {
                        entry = compiler.EvalAsListOfStrings(t.At, update).FirstOrDefault();
                        if (entry != null && (entry.Contains(@"\r\n") || entry.Contains(@"\n")))
                        {
                            var match = Regex.Match(stringToSplit, @"[\r\n]+");
                            if (match.Success && !SkipBlankRows)
                            {
                                stringToSplit  = Regex.Escape(stringToSplit);
                                dtb.ToTokenize = stringToSplit;
                            }
                        }
                        string escape = t.EscapeChar;
                        if (!String.IsNullOrEmpty(escape))
                        {
                            escape = compiler.EvalAsListOfStrings(t.EscapeChar, update).FirstOrDefault();
                        }
                        dtb.AddTokenOp(entry, t.Include, escape);
                    }
                    break;
                }
                _indexCounter++;
            }
            return(string.IsNullOrEmpty(dtb.ToTokenize) || errors.HasErrors() ? null : dtb.Generate());
        }
コード例 #7
0
        private IDev2Tokenizer CreateSplitPattern(ref string stringToSplit, IEnumerable <DataSplitDTO> args, IDataListCompiler compiler, Guid dlId, out ErrorResultTO errors)
        {
            Dev2TokenizerBuilder dtb = new Dev2TokenizerBuilder {
                ToTokenize = stringToSplit, ReverseOrder = ReverseOrder
            };

            errors = new ErrorResultTO();

            foreach (DataSplitDTO t in args)
            {
                var fieldName = t.OutputVariable;
                t.At = t.At ?? "";
                if (!string.IsNullOrEmpty(_datalistString))
                {
                    var isValidExpr = new IsValidExpressionRule(() => fieldName, _datalistString)
                    {
                        LabelText = fieldName
                    };

                    var errorInfo = isValidExpr.Check();
                    if (errorInfo != null)
                    {
                        errors.AddError(errorInfo.Message);
                        continue;
                    }
                }

                IBinaryDataListEntry entry;
                string error;
                switch (t.SplitType)
                {
                case "Index":
                    try
                    {
                        entry = compiler.Evaluate(dlId, enActionType.User, t.At, false, out errors);
                        string index    = DataListUtil.GetValueAtIndex(entry, 1, out error);
                        int    indexNum = Convert.ToInt32(index);
                        if (indexNum > 0)
                        {
                            dtb.AddIndexOp(indexNum);
                        }
                    }
                    catch (Exception ex)
                    {
                        errors.AddError(ex.Message);
                    }
                    break;

                case "End":
                    dtb.AddEoFOp();
                    break;

                case "Space":
                    dtb.AddTokenOp(" ", t.Include);
                    break;

                case "Tab":
                    dtb.AddTokenOp("\t", t.Include);
                    break;

                case "New Line":
                    if (stringToSplit.Contains("\r\n"))
                    {
                        dtb.AddTokenOp("\r\n", t.Include);
                    }
                    else if (stringToSplit.Contains("\n"))
                    {
                        dtb.AddTokenOp("\n", t.Include);
                    }
                    else if (stringToSplit.Contains("\r"))
                    {
                        dtb.AddTokenOp("\r", t.Include);
                    }
                    break;

                case "Chars":
                    if (!string.IsNullOrEmpty(t.At))
                    {
                        entry = compiler.Evaluate(dlId, enActionType.User, t.At, false, out errors);

                        string val    = DataListUtil.GetValueAtIndex(entry, 1, out error);
                        string escape = t.EscapeChar;
                        if (!String.IsNullOrEmpty(escape))
                        {
                            entry  = compiler.Evaluate(dlId, enActionType.User, t.EscapeChar, false, out errors);
                            escape = DataListUtil.GetValueAtIndex(entry, 1, out error);
                        }

                        dtb.AddTokenOp(val, t.Include, escape);
                    }
                    break;
                }
                _indexCounter++;
            }
            return(string.IsNullOrEmpty(dtb.ToTokenize) || errors.HasErrors() ? null : dtb.Generate());
        }