Ejemplo n.º 1
0
        internal void ToString(TextBuilder text)
        {
            if (this.ILGeneratorMethod != ILGeneratorMethod.None)
            {
                text.Append(this.ILGeneratorMethod)
                .Append('(');
                if (this.Argument is IEnumerable args)
                {
                    text.AppendDelimit(',', args.AsObjectEnumerable(), (tb, a) => tb.AppendDump(a));
                }
                else
                {
                    text.AppendDump(this.Argument);
                }

                text.Append(')');
            }
            else
            {
                var opCode = this.OpCode;
                AppendLabel(text, this);
                text.Append(": ")
                .Append(opCode.Name);
                var operand = this.Argument;
                if (operand is null)
                {
                    return;
                }
                AppendOperand(text, opCode.OperandType, operand);
            }
        }
Ejemplo n.º 2
0
        public void Draw(TextBuilder text, TextBatcher textBatcher, DemoSet demoSet, Vector2 position, float textHeight, Vector3 textColor, Font font)
        {
            if (TrackingInput)
            {
                text.Clear().Append("Swap demo to: ");
                if (TargetDemoIndex >= 0)
                {
                    text.Append(TargetDemoIndex);
                }
                else
                {
                    text.Append("_");
                }
                textBatcher.Write(text, position, textHeight, textColor, font);

                var lineSpacing = textHeight * 1.1f;
                position.Y += textHeight * 0.5f;
                textHeight *= 0.8f;
                for (int i = 0; i < demoSet.Count; ++i)
                {
                    position.Y += lineSpacing;
                    text.Clear().Append(demoSet.GetName(i));
                    textBatcher.Write(text.Clear().Append(i).Append(": ").Append(demoSet.GetName(i)), position, textHeight, textColor, font);
                }
            }
        }
Ejemplo n.º 3
0
        public string Cut(string value, int startIndex, char endChar, bool WriteEndChar, int selectedIndex)
        {
            using (TextBuilder b = new TextBuilder())
            {
                int number = 0;
                for (int i = startIndex; i < value.Length; i++)
                {
                    number++;
                    if (value[i] == endChar)
                    {
                        if (WriteEndChar == true)
                        {
                            b.Append(value[i]);
                        }

                        break;
                    }
                    else
                    {
                        b.Append(value[i]);
                    }
                }
                selectedIndex = selectedIndex + number;
                GC.SuppressFinalize(number);
                return(b.ToString());
            }
        }
Ejemplo n.º 4
0
        public void UndoTest()
        {
            TextBuilder tb = new TextBuilder();

            tb.CanUndo = true;
            string original = "Ahoj";

            tb.Append(original);
            tb.Append("Svete");

            tb.Undo();
            Assert.Equal(original, tb.ToString());
        }
Ejemplo n.º 5
0
 public static TextBuilder AppendDump(this TextBuilder textBuilder, object?obj, DumpOptions options = default)
 {
     return(obj switch
     {
         // Big ol' switch statement
         null when options.Verbose => textBuilder.Append("null"),
         null => textBuilder,
         Type type => AppendDump(textBuilder, type, options),
         Array array => AppendDump(textBuilder, array, options),
         string str => textBuilder.Append(str),
         IEnumerable enumerable => AppendDump(textBuilder, enumerable, options),
         TimeSpan timeSpan => textBuilder.AppendDump(timeSpan, options),
         DateTime dateTime => textBuilder.AppendDump(dateTime, options),
         Guid guid => textBuilder.AppendDump(guid, options),
         _ => textBuilder.Append(obj)
     });
Ejemplo n.º 6
0
        public async Task <bool?> Handle(MessageEntityEx entity, PollMessage context = default, CancellationToken cancellationToken = default)
        {
            if (!this.ShouldProcess(entity, context))
            {
                return(null);
            }

            var from  = myClock.GetCurrentInstant().ToDateTimeOffset() - myJitterOffset;
            var polls = await myDB.Set <Poll>()
                        .Where(poll => poll.Time >= from)
                        .Where(poll => poll.Votes.Any(vote => vote.UserId == entity.Message.From.Id))
                        .IncludeRelatedData()
                        .ToListAsync(cancellationToken);

            var builder = new TextBuilder();

            if (polls.Count == 0)
            {
                builder.Append($"No upcoming raids.");
            }
            else
            {
                foreach (var poll in polls.OrderBy(poll => poll.Time))
                {
                    builder.Bold(b =>
                                 b.Code(bb => bb.AppendFormat("{0:t} ", poll.Time)));
                    poll.GetTitle(builder).NewLine();
                }
            }

            var content = builder.ToTextMessageContent(disableWebPreview: true);
            await myBot.SendTextMessageAsync(entity.Message.Chat, content, true, cancellationToken : cancellationToken);

            return(false);
        }
Ejemplo n.º 7
0
        public static TextBuilder AppendDump(this TextBuilder builder, TimeSpan timeSpan, DumpOptions options = default)
        {
            string?format = options.Format;

            if (format.IsNullOrWhiteSpace())
            {
                if (options.Verbose)
                {
                    format = "G";
                }
                else
                {
                    format = "g";
                }
            }
            if (timeSpan.TryFormat(builder.Available,
                                   out int charsWritten,
                                   format,
                                   options.FormatProvider))
            {
                builder.Length += charsWritten;
                return(builder);
            }

            return(builder.Append(timeSpan.ToString(format, options.FormatProvider)));
        }
Ejemplo n.º 8
0
        public static TextBuilder AppendDump(this TextBuilder builder, DateTime dateTime, DumpOptions options = default)
        {
            string?format = options.Format;

            if (format.IsNullOrWhiteSpace())
            {
                if (options.Verbose)
                {
                    format = "O";
                }
                else
                {
                    format = "yyyy-MM-dd HH:mm:ss";
                }
            }
            if (dateTime.TryFormat(builder.Available,
                                   out int charsWritten,
                                   format,
                                   options.FormatProvider))
            {
                builder.Length += charsWritten;
                return(builder);
            }

            return(builder.Append(dateTime.ToString(format, options.FormatProvider)));
        }
Ejemplo n.º 9
0
        public void TextBuilder()
        {
            string selectSql = @"
                select 
                    * 
                from 
                    Customers Customer    
                where 
                    {{condition}}";

            TextBuilder textBuilder = new TextBuilder(
                selectSql,
                new { condition = "Customer.CustomerId > @CustomerId" }
                );

            string orderSql = @"
                order by
                    {{sort}}";

            textBuilder.Append(
                orderSql,
                new { sort = "Customer.Name" }
                );

            string sqlSelectOrder = textBuilder.Generate();

            DagentDatabase db = new DagentDatabase("connectionStringName");

            List <Customer> customers =
                db.Query <Customer>(sqlSelectOrder, new { CustomerId = 10 }).List();
        }
Ejemplo n.º 10
0
        public async Task <bool?> Process(User user, string nickname, CancellationToken cancellationToken = default)
        {
            var player = await myContext.Set <Player>().Get(user, cancellationToken);

            if (!string.IsNullOrEmpty(nickname))
            {
                if (player == null)
                {
                    player = new Player
                    {
                        UserId = user.Id
                    };
                    myContext.Add(player);
                }

                player.Nickname = nickname;
                await myContext.SaveChangesAsync(cancellationToken);
            }

            IReplyMarkup?replyMarkup = null;
            var          builder     = new TextBuilder();

            if (!string.IsNullOrEmpty(player?.Nickname))
            {
                builder
                .Append($"Your IGN is {player.Nickname:bold}")
                .NewLine()
                .NewLine();

                replyMarkup = new InlineKeyboardMarkup(InlineKeyboardButton.WithCallbackData("Clear IGN",
                                                                                             $"{PlayerCallbackQueryHandler.ID}:{PlayerCallbackQueryHandler.Commands.ClearIGN}"));
            }

            builder
            .Append($"To set up your in-game-name reply with it to this message.").NewLine()
            .Append($"Or use /{COMMAND} command.").NewLine()
            .Code("/ign your-in-game-name");

            await myBot.SendTextMessageAsync(user.Id, builder.ToTextMessageContent(), cancellationToken : cancellationToken,
                                             replyMarkup : replyMarkup ?? new ForceReplyMarkup {
                InputFieldPlaceholder = "in-game-name"
            });

            return(false); // processed, but not pollMessage
        }
Ejemplo n.º 11
0
 public static TextBuilder AppendDump(this TextBuilder textBuilder, Array?array, DumpOptions options = default)
 {
     textBuilder.Write('[');
     if (array != null)
     {
         textBuilder.AppendDelimit <object?>(", ", array.AsArrayEnumerable(), (tb, value) => tb.AppendDump(value, options));
     }
     return(textBuilder.Append(']'));
 }
Ejemplo n.º 12
0
 public static TextBuilder AppendDump(this TextBuilder textBuilder, IEnumerable?enumerable, DumpOptions options = default)
 {
     textBuilder.Write('(');
     if (enumerable != null)
     {
         textBuilder.AppendDelimit <object?>(", ", enumerable.AsObjectEnumerable(), (tb, value) => tb.AppendDump(value, options));
     }
     return(textBuilder.Append(')'));
 }
Ejemplo n.º 13
0
        public override bool VisitTerminal(ITerminalNode node)
        {
            if (!node.GetText().Contains("EOF"))
            {
                output.Append(node);
            }

            return(base.VisitTerminal(node));
        }
Ejemplo n.º 14
0
        public static TextBuilder AppendDump(this TextBuilder textBuilder, MemberInfo?member, DumpOptions options = default)
        {
            if (member is null)
            {
                if (options.Verbose)
                {
                    return(textBuilder.Append("(MemberInfo)null"));
                }
                return(textBuilder);
            }

            if (member is FieldInfo fieldInfo)
            {
                return(AppendDump(textBuilder, fieldInfo, options));
            }

            // Fallback
            return(textBuilder.Append(member));
        }
Ejemplo n.º 15
0
 public static void Format(TextBuilder textBuilder, EventProperties properties)
 {
     if (properties.ContainsKey(String.Empty))
     {
         textBuilder.Append("EventData");
     }
     ObjectDumper.DumpObject(
         properties.OrderBy(pair => pair.Key),
         textBuilder);
 }
Ejemplo n.º 16
0
        public void FetchForOneToOneByTextBuilder()
        {
            TextBuilder textBuilder = new TextBuilder(@"
                select 
                    *
                from 
                    customers c");

            textBuilder.Append(@"
                inner join
                    {{join}}
                on
                    c.businessId = b.businessId",
                               new { join = "business b" });

            textBuilder.Append(@"
                inner join 
                    customerPurchases cp 
                on 
                    {{on}}
	            order by 
                    {{order}}",
                               new { on = "c.customerId = cp.customerId", order = "c.customerId, cp.no" });

            string sql = textBuilder.Generate();

            IDagentDatabase             database  = new DagentDatabase("SQLite");
            List <CustomerWithBusiness> customers = database.Query <CustomerWithBusiness>(sql)
                                                    .Unique("customerId")
                                                    .Each((model, row) => {
                row.Map(model, x => x.Business, "businessName").Do();
                row.Map(model, x => x.CustomerPurchases, "no").Do();
            })
                                                    .List();

            ValidList(customers);

            sql = textBuilder.Clear().Generate();

            Assert.AreEqual("", sql);
        }
Ejemplo n.º 17
0
        internal static TextBuilder AppendTransform(this TextBuilder builder, ReadOnlySpan <char> text, UnicodeTransformation transformation)
        {
            switch (transformation)
            {
            case UnicodeTransformation.Bold:
                return(UnicodeBold(builder, text));

            case UnicodeTransformation.Italic:
                return(UnicodeItalic(builder, text));

            case UnicodeTransformation.BoldItalic:
                return(UnicodeBoldItalic(builder, text));

            case UnicodeTransformation.Script:
                return(UnicodeScript(builder, text));

            case UnicodeTransformation.BoldScript:
                return(UnicodeBoldScript(builder, text));

            case UnicodeTransformation.Fraktur:
                return(UnicodeFraktur(builder, text));

            case UnicodeTransformation.DoubleStruck:
                return(UnicodeDoubleStruck(builder, text));

            case UnicodeTransformation.BoldFraktur:
                return(UnicodeBoldFraktur(builder, text));

            case UnicodeTransformation.SansSerif:
                return(UnicodeSansSerif(builder, text));

            case UnicodeTransformation.SansSerifBold:
                return(UnicodeSansSerifBold(builder, text));

            case UnicodeTransformation.SansSerifItalic:
                return(UnicodeSansSerifItalic(builder, text));

            case UnicodeTransformation.SansSerifBoldItalic:
                return(UnicodeSansSerifBoldItalic(builder, text));

            case UnicodeTransformation.Monospace:
                return(UnicodeMonospace(builder, text));

            case UnicodeTransformation.Underline:
                return(UnicodeUnderline(builder, text));

            case UnicodeTransformation.None:
            default:
                return(builder.Append(text));
            }
        }
Ejemplo n.º 18
0
        public string Cut(string value, int startIndex, char endChar, bool WriteEndChar)
        {
            using (TextBuilder b = new TextBuilder())
            {
                for (int i = startIndex; i < value.Length; i++)
                {
                    if (value[i] == endChar)
                    {
                        if (WriteEndChar == true)
                        {
                            b.Append(value[i]);
                        }

                        break;
                    }
                    else
                    {
                        b.Append(value[i]);
                    }
                }
                return(b.ToString());
            }
        }
Ejemplo n.º 19
0
        public static TextBuilder AppendDump(this TextBuilder builder, Guid guid, DumpOptions options = default)
        {
            string format = options.Format ?? "D";

            if (guid.TryFormat(builder.Available,
                               out int charsWritten,
                               format))
            {
                builder.Available.Slice(0, charsWritten).ConvertToUpper();
                builder.Length += charsWritten;
                return(builder);
            }
            return(builder.Append(guid.ToString(format).ToUpper()));
        }
Ejemplo n.º 20
0
        public static TextBuilder AppendDump(this TextBuilder textBuilder, FieldInfo?field, DumpOptions options = default)
        {
            if (field is null)
            {
                if (options.Verbose)
                {
                    return(textBuilder.Append("(FieldInfo)null"));
                }
                return(textBuilder);
            }

            if (options.Verbose)
            {
                var fieldAttributes = Attribute.GetCustomAttributes(field, true);
                if (fieldAttributes.Length > 0)
                {
                    textBuilder.AppendDelimit(Environment.NewLine,
                                              fieldAttributes,
                                              (tb, attr) => tb.Append('[').Append(attr).Append(']'))
                    .AppendLine();
                }

                var visibility = field.GetVisibility();
                if (visibility.HasFlag <Visibility>(Visibility.Private))
                {
                    textBuilder.Write("private ");
                }
                if (visibility.HasFlag <Visibility>(Visibility.Protected))
                {
                    textBuilder.Write("protected ");
                }
                if (visibility.HasFlag <Visibility>(Visibility.Internal))
                {
                    textBuilder.Write("internal ");
                }
                if (visibility.HasFlag <Visibility>(Visibility.Public))
                {
                    textBuilder.Write("public ");
                }
                if (field.IsStatic)
                {
                    textBuilder.Write("static ");
                }
            }

            return(textBuilder.AppendDump(field.FieldType, options)
                   .Append(' ')
                   .Append(field.Name));
        }
Ejemplo n.º 21
0
 public string Cut(string value, int startIndex, int endIndex)
 {
     using (TextBuilder b = new TextBuilder())
     {
         for (int i = startIndex; i <= endIndex; i++)
         {
             try
             {
                 b.Append(value[i]);
             }
             catch
             {
                 break;
             }
         }
         return(b.ToString());
     }
 }
Ejemplo n.º 22
0
 public int ConvertNumber(string value)
 {
     using (TextBuilder builder = new TextBuilder())
     {
         for (int i = 0; i < value.Length; i++)
         {
             try
             {
                 if (chs.Contains(value[i]) == true)
                 {
                     builder.Append(value[i]);
                 }
             }
             catch
             {
             }
         }
         return(Convert.ToInt32(builder.ToString().Trim()));
     }
 }
Ejemplo n.º 23
0
        public IndexInfo CutOfWriteChar(string value, int startIndex)
        {
            int l = 0;

            using (TextBuilder builder = new TextBuilder())
            {
                for (int i = startIndex; i < value.Length; i++)
                {
                    if (char.IsWhiteSpace(value[i]) == true)
                    {
                        l = i;
                        break;
                    }
                    else
                    {
                        builder.Append(value[i]);
                    }
                }
                return(new IndexInfo(l, builder.ToString(), true));
            }
        }
Ejemplo n.º 24
0
        // Boşluk karakteri
        public IndexInfo CutOfWhiteChar(string value)
        {
            int loc = 0;

            using (TextBuilder builder = new TextBuilder())
            {
                for (int i = 0; i < value.Length; i++)
                {
                    if (char.IsWhiteSpace(value[i]))
                    {
                        loc = i;
                        break;
                    }
                    else
                    {
                        builder.Append(value[i]);
                    }
                }
                return(new IndexInfo(loc, builder.ToString(), loc > 0));
            }
        }
Ejemplo n.º 25
0
        public char[] ReverseToArray(char[] value)
        {
            using (TextBuilder b = new TextBuilder())
            {
                int index = value.Length - 1;
                while (true)
                {
                    if (index == -1)
                    {
                        break;
                    }
                    else
                    {
                        b.Append(value[index]);

                        index--;
                    }
                }
                GC.SuppressFinalize(index);
                return(b.ToString().ToCharArray());
            }
        }
Ejemplo n.º 26
0
        public List <string> SplitOfChar(string value, char c)
        {
            List <string> s = new List <string>();

            using (TextBuilder b = new TextBuilder())
            {
                for (int i = 0; i < value.Length; i++)
                {
                    if (i == value.Length - 1)
                    {
                        b.Append(value[i]);
                        s.Add(b.ToString());
                        b.Clear();
                    }
                    if (value[i] == c)
                    {
                        s.Add(b.ToString());
                        b.Clear();
                    }
                }
            }
            return(s);
        }
Ejemplo n.º 27
0
 public string Cut(string value, char startChar, char endChar)
 {
     using (TextBuilder b = new TextBuilder())
     {
         bool starting = false;
         for (int i = 0; i < value.Length; i++)
         {
             if (value[i] == startChar)
             {
                 starting = true;
             }
             if (value[i] == endChar)
             {
                 break;
             }
             else if (starting == true)
             {
                 b.Append(value[i]);
             }
         }
         return(b.ToString());
     }
 }
Ejemplo n.º 28
0
        public bool StringContains(string value, string searchvalue)
        {
            bool b = false;

            using (TextBuilder builder = new TextBuilder())
            {
                for (int i = 0; i < value.Length; i++)
                {
                    if (char.IsWhiteSpace(value[i]))
                    {
                        if (builder.Length > 0)
                        {
                            if (builder.ToString() == searchvalue)
                            {
                                b = true;
                                builder.Clear();
                                break;
                            }
                        }
                    }
                    if (i == value.Length - 1)
                    {
                        builder.Append(value[i]);
                        if (builder.Length > 0)
                        {
                            if (builder.ToString() == searchvalue)
                            {
                                b = true;
                                builder.Clear();
                                break;
                            }
                        }
                    }
                }
            }
            return(b);
        }
Ejemplo n.º 29
0
 public static TextBuilder AppendDump <T>(this TextBuilder textBuilder, ReadOnlySpan <T> values, DumpOptions options = default)
 {
     return(textBuilder.Append('|')
            .AppendDelimit <T>(", ", values, (tb, value) => tb.AppendDump((object?)value, options))
            .Append('|'));
 }
Ejemplo n.º 30
0
        public string ExpandSql(string rawSql)
        {
            Context ctx = Ctx; // The database connection
            TextBuilder b = new TextBuilder(); // Accumulate the _output here
            TextBuilder.Init(b, 100, ctx.Limits[(int)LIMIT.LENGTH]);
            b.Tag = ctx;
            int rawSqlIdx = 0;
            int nextIndex = 1; // Index of next ? host parameter
            int idx = 0; // Index of a host parameter
            if (ctx.VdbeExecCnt > 1)
                while (rawSqlIdx < rawSql.Length)
                {
                    while (rawSql[rawSqlIdx++] != '\n' && rawSqlIdx < rawSql.Length) ;
                    b.Append("-- ", 3);
                    b.Append(rawSql, (int)rawSqlIdx);
                }
            else
                while (rawSqlIdx < rawSql.Length)
                {
                    int tokenLength = 0; // Length of the parameter token
                    int n = FindNextHostParameter(rawSql, rawSqlIdx, ref tokenLength); // Length of a token prefix
                    Debug.Assert(n > 0);
                    b.Append(rawSql.Substring(rawSqlIdx, n), n);
                    rawSqlIdx += n;
                    Debug.Assert(rawSqlIdx < rawSql.Length || tokenLength == 0);
                    if (tokenLength == 0) break;
                    if (rawSql[rawSqlIdx] == '?')
                    {
                        if (tokenLength > 1)
                        {
                            Debug.Assert(char.IsDigit(rawSql[rawSqlIdx + 1]));
                            ConvertEx.Atoi(rawSql, rawSqlIdx + 1, ref idx);
                        }
                        else
                            idx = nextIndex;
                    }
                    else
                    {
                        Debug.Assert(rawSql[rawSqlIdx] == ':' || rawSql[rawSqlIdx] == '$' || rawSql[rawSqlIdx] == '@');
                        C.ASSERTCOVERAGE(rawSql[rawSqlIdx] == ':');
                        C.ASSERTCOVERAGE(rawSql[rawSqlIdx] == '$');
                        C.ASSERTCOVERAGE(rawSql[rawSqlIdx] == '@');
                        idx = ParameterIndex(this, rawSql.Substring(rawSqlIdx, tokenLength), tokenLength);
                        Debug.Assert(idx > 0);
                    }
                    rawSqlIdx += tokenLength;
                    nextIndex = idx + 1;
                    Debug.Assert(idx > 0 && idx <= Vars.length);
                    Mem var = Vars[idx - 1]; // Value of a host parameter
                    if ((var.Flags & MEM.Null) != 0) b.Append("NULL", 4);
                    else if ((var.Flags & MEM.Int) != 0) b.AppendFormat("%lld", var.u.I);
                    else if ((var.Flags & MEM.Real) != 0) b.AppendFormat("%!.15g", var.R);
                    else if ((var.Flags & MEM.Str) != 0)
                    {
#if !OMIT_UTF16
                        TEXTENCODE encode = E.CTXENCODE(ctx);
                        if (encode != TEXTENCODE.UTF8)
                        {
                            Mem utf8;
                            //C._memset(&utf8, 0, sizeof(utf8));
                            utf8.Ctx = ctx;
                            MemSetStr(utf8, var.Z, var.N, encode, C.DESTRUCTOR_STATIC);
                            ChangeEncoding(utf8, TEXTENCODE.UTF8);
                            b.AppendFormat("'%.*q'", utf8.N, utf8.Z);
                            MemRelease(utf8);
                        }
                        else
#endif
                            b.AppendFormat("'%.*q'", var.N, var.Z);
                    }
                    else if ((var.Flags & MEM.Zero) != 0) b.AppendFormat("zeroblob(%d)", var.u.Zeros);
                    else
                    {
                        Debug.Assert((var.Flags & MEM.Blob) != 0);
                        b.Append("x'", 2);
                        for (int i = 0; i < var.N; i++) b.AppendFormat("%02x", var.u.Zeros[i] & 0xff);
                        b.Append("'", 1);
                    }
                }
            return b.ToString();
        }
Ejemplo n.º 31
0
 public static TextBuilder AppendDump <T>(this TextBuilder textBuilder, IEnumerable <T> values, DumpOptions options = default)
 {
     return(textBuilder.Append('(')
            .AppendDelimit(", ", values, (tb, value) => tb.AppendDump((object?)value, options))
            .Append(')'));
 }