Beispiel #1
0
        private void Update(EvaluationContext context)
        {
            var stringBuilder = InputBuffer.GetValue(context);

            Builder.Value = stringBuilder;
            if (stringBuilder == null)
            {
                return;
            }

            var bufferLength = stringBuilder.Length;

            if (TriggerChop.GetValue(context))
            {
                //if (stringBuilder.Length < MaxLength.GetValue(context))
                //    stringBuilder.Append(String.GetValue(context));
                var minRandomLength = MinLength.GetValue(context);
                if (minRandomLength < 0)
                {
                    minRandomLength = 0;
                }

                var maxRandomLength = MaxLength.GetValue(context);
                if (maxRandomLength < minRandomLength)
                {
                    maxRandomLength = minRandomLength;
                }

                var lenRemove = (int)_random.NextLong(minRandomLength, maxRandomLength);

                var maxRandPos = bufferLength - lenRemove;
                if (maxRandPos < 0)
                {
                    maxRandPos = 0;
                }

                var randPos = (int)_random.NextLong(0, maxRandPos);
                if (lenRemove > 0 && lenRemove < bufferLength)
                {
                    stringBuilder.Remove(randPos, lenRemove);
                }
            }

            var fillString = FillString.GetValue(context);

            bufferLength = stringBuilder.Length;
            if (TriggerFill.GetValue(context) && fillString.Length > 0 && bufferLength > 0)
            {
                if (TriggerFillJump.GetValue(context))
                {
                    _fillIndex = (int)_random.NextLong(0, bufferLength);
                }
                _fillIndex += FillDirection.GetValue(context);
                _fillIndex %= bufferLength;
                if (_fillIndex < 0)
                {
                    _fillIndex += bufferLength;
                }

                stringBuilder[_fillIndex] = fillString[_fillIndex % fillString.Length];
            }
        }
Beispiel #2
0
        private void Update(EvaluationContext context)
        {
            var maxLength     = MaxLength.GetValue(context);
            var stringBuilder = InputBuffer.GetValue(context);
            var lastIndex     = _index;

            if (maxLength <= 0)
            {
                Result.Value = String.Empty;
                return;
            }

            if (!InputBuffer.IsConnected || stringBuilder == null)
            {
                stringBuilder = _fallbackBuffer;
            }

            if (ClearTrigger.GetValue(context))
            {
                stringBuilder.Clear();
                _index = 0;
            }

            //var mode = (Modes)WriteMode.GetValue(context);

            try
            {
                if (Insert.GetValue(context))
                {
                    if (TriggerRandomPos.GetValue(context))
                    {
                        _index = (int)_random.NextLong(0, stringBuilder.Length);
                    }

                    var separator = Separator.GetValue(context);;
                    if (!string.IsNullOrEmpty(separator))
                    {
                        separator = separator.Replace("\\n", "\n");
                    }

                    var str           = InsertString.GetValue(context);
                    var insertString  = str + separator;
                    var insertLength  = insertString.Length;
                    var currentLength = stringBuilder.Length;
                    var lineWrap      = (WrapLinesModes)WrapLines.GetValue(context);
                    var mode          = (Modes)WriteMode.GetValue(context);

                    if (_index > maxLength)
                    {
                        _index = 0;
                    }

                    var pos = _index;
                    if (pos + insertLength > maxLength)
                    {
                        insertLength = maxLength - pos;
                    }

                    if (mode != Modes.Insert && pos < currentLength - insertLength)
                    {
                        stringBuilder.Remove(pos, insertLength);
                    }

                    if (pos > currentLength)
                    {
                        var fillString = FillCharacter.GetValue(context);
                        var fillChar   = string.IsNullOrEmpty(fillString) ?  '_' : fillString[0];
                        stringBuilder.Append(new string(fillChar, pos - currentLength));
                    }

                    stringBuilder.Insert(pos, insertString);

                    InsertLineWraps(lineWrap, stringBuilder, pos, insertLength, WrapLineColumn.GetValue(context).Clamp(1, 1000));
                    switch (mode)
                    {
                    case Modes.Insert:
                    {
                        _index += insertLength;
                        break;
                    }

                    case Modes.Overwrite:
                    {
                        _index += insertLength;
                        _index %= maxLength;
                        break;
                    }

                    case Modes.OverwriteAtFixedOffset:
                        _index += FillOffset.GetValue(context);
                        if (_index > maxLength)
                        {
                            _index = _index % maxLength;
                        }
                        else if (_index < 0)
                        {
                            _index += maxLength - insertLength;
                        }

                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }


                    //InsertLineWraps(lineWrap, stringBuilder);

                    if (stringBuilder.Length > maxLength)
                    {
                        stringBuilder.Length = maxLength;
                    }
                }
            }
            catch (Exception e)
            {
                Log.Warning($"Failed to manipulate string at index {_index} " + e.Message);
            }

            //

            Builder.Value = stringBuilder;
            Result.Value  = stringBuilder.ToString();
        }