예제 #1
0
        public static ICharIterator ColorFormat(
            ICharIterator input, BitmapFont font, bool keepSequences, byte baseAlpha, IReferenceList <Color?> output)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }
            if (font == null)
            {
                throw new ArgumentNullException(nameof(font));
            }

            if (input.Length == 0)
            {
                return(input);
            }

            var builder = StringBuilderPool.Rent(input.Length);

            ColorFormat(input, builder, font, keepSequences, baseAlpha, output);
            var iterator = CharIteratorPool.Rent(builder, 0, builder.Length);

            StringBuilderPool.Return(builder);
            return(iterator);
        }
        public string ToFractionBase(double n, int radix)
        {
            // based on the repeated multiplication method
            // http://www.mathpath.org/concepts/Num/frac.htm

            const string digits = "0123456789abcdefghijklmnopqrstuvwxyz";

            if (n == 0)
            {
                return("0");
            }

            using (var result = StringBuilderPool.Rent())
            {
                while (n > 0 && result.Length < 50) // arbitrary limit
                {
                    var c = n * radix;
                    var d = (int)c;
                    n = c - d;

                    result.Builder.Append(digits[d]);
                }

                return(result.ToString());
            }
        }
예제 #3
0
        /// <summary>
        /// https://www.ecma-international.org/ecma-262/6.0/#sec-string.raw
        /// </summary>
        private JsValue Raw(JsValue thisObj, JsValue[] arguments)
        {
            var cooked = TypeConverter.ToObject(_realm, arguments.At(0));
            var raw    = TypeConverter.ToObject(_realm, cooked.Get(JintTaggedTemplateExpression.PropertyRaw, cooked));

            var operations = ArrayOperations.For(raw);
            var length     = operations.GetLength();

            if (length <= 0)
            {
                return(JsString.Empty);
            }

            using var result = StringBuilderPool.Rent();
            for (var i = 0; i < length; i++)
            {
                if (i > 0)
                {
                    if (i < arguments.Length && !arguments[i].IsUndefined())
                    {
                        result.Builder.Append(TypeConverter.ToString(arguments[i]));
                    }
                }

                result.Builder.Append(TypeConverter.ToString(operations.Get((ulong)i)));
            }

            return(result.ToString());
        }
예제 #4
0
        /// <summary>
        /// Returns a <see cref="string"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="string"/> that represents this instance.
        /// </returns>
        internal override string ToString(RecursionLevel level)
        {
            if (!level.TryIncrement())
            {
                return(MaximumRecursionLevelReachedToStringValue);
            }

            using var textBuilder = StringBuilderPool.Rent();
            var text = textBuilder.Builder;

            text.Append("[ ");

            foreach (var child in children)
            {
                if (text.Length > 2)
                {
                    text.Append(", ");
                }
                text.Append(child.ToString(level));
            }

            text.Append(" ]");

            level.Decrement();

            return(text.ToString());
        }
예제 #5
0
        public void CapacityTest(int capacity)
        {
            StringBuilder sb = StringBuilderPool.Rent(capacity);

            Assert.True(sb.Capacity >= capacity);
            StringBuilderPool.Return(sb);
        }
예제 #6
0
        /// <summary>Displays trace information</summary>
        /// <param name="context">Object BundleContext</param>
        /// <param name="response">Object BundleResponse</param>
        public void Process(BundleContext context, BundleResponse response)
        {
            StringBuilderPool shared        = StringBuilderPool.Shared;
            StringBuilder     stringBuilder = shared.Rent();

            stringBuilder.AppendLine("*************************************************************************************");
            stringBuilder.AppendLine("* BUNDLE RESPONSE                                                                   *");
            stringBuilder.AppendLine("*************************************************************************************");
            foreach (BundleFile file in response.Files)
            {
                stringBuilder.AppendLine("  " + file.IncludedVirtualPath);
            }
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("*************************************************************************************");
            stringBuilder.AppendLine("* BUNDLE COLLECTION                                                                 *");
            stringBuilder.AppendLine("*************************************************************************************");
            foreach (Bundle bundle in (IEnumerable <Bundle>)context.BundleCollection)
            {
                stringBuilder.AppendFormatLine("-= {0} =-", (object)bundle.Path);
                foreach (BundleFile enumerateFile in bundle.EnumerateFiles(context))
                {
                    stringBuilder.AppendLine("  " + enumerateFile.IncludedVirtualPath);
                }
                stringBuilder.AppendLine();
            }
            string str = stringBuilder.ToString();

            shared.Return(stringBuilder);
            response.ContentType = "text/plain";
            response.Content     = str;
        }
예제 #7
0
        public void TextTest(string input)
        {
            StringBuilder sb = StringBuilderPool.Rent(input);

            Assert.Equal(input, sb.ToString());
            StringBuilderPool.Return(sb);
        }
 private string ToNumberString(double m)
 {
     using (var stringBuilder = StringBuilderPool.Rent())
     {
         return(NumberToString(m, new DtoaBuilder(), stringBuilder.Builder));
     }
 }
예제 #9
0
        protected override string CombineAssetContent(IList <IAsset> assets)
        {
            StringBuilderPool shared        = StringBuilderPool.Shared;
            StringBuilder     stringBuilder = shared.Rent();
            int count = assets.Count;
            int num   = count - 1;

            for (int index = 0; index < count; ++index)
            {
                IAsset asset = assets[index];
                string str   = asset.Content.TrimEnd();
                if (this.EnableTracing)
                {
                    stringBuilder.AppendFormatLine("//#region URL: {0}", (object)asset.Url);
                }
                stringBuilder.Append(str);
                if (!str.EndsWith(";"))
                {
                    stringBuilder.Append(";");
                }
                if (this.EnableTracing)
                {
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("//#endregion");
                }
                if (index != num)
                {
                    stringBuilder.AppendLine();
                }
            }
            string str1 = stringBuilder.ToString();

            shared.Return(stringBuilder);
            return(str1);
        }
        private void Remove(ref StringBuilder tmpBuilder, ref int removals, int value)
        {
            for (int i = 0; i < CurrentText.Length; i++)
            {
                char current = CurrentText.GetCharacter16(i);
                if (current == value)
                {
                    if (tmpBuilder == null)
                    {
                        tmpBuilder = StringBuilderPool.Rent(CurrentText.Length);

                        // append the data that we were holding onto,
                        // excluding the char we are on currently
                        for (int j = 0; j < i; j++)
                        {
                            tmpBuilder.Append(CurrentText.GetCharacter16(j));
                        }
                    }

                    removals++;
                }
                else if (tmpBuilder != null) // we don't append if there are no changes yet
                {
                    tmpBuilder.Append(current);
                }
            }
        }
        protected override TextSegment.GlyphCallbackResult GlyphCallback(ICharIterator source)
        {
            if (_isObscured)
            {
                return(new TextSegment.GlyphCallbackResult(_obscureChar.ToRepeatingIterator(source.Length), leaveOpen: false));
            }

            if (!_isMultiLined)
            {
                var builder = StringBuilderPool.Rent(source.Length);
                for (int i = 0; i < source.Length; i++)
                {
                    char current = source.GetCharacter16(i);
                    if (current != '\n')
                    {
                        builder.Append(current);
                    }
                }

                var iter = builder.ToIterator();
                StringBuilderPool.Return(builder);
                return(new TextSegment.GlyphCallbackResult(iter, leaveOpen: false));
            }

            return(base.GlyphCallback(source));
        }
예제 #12
0
        /// <summary>
        /// Returns a string representation for the given transponders.
        /// </summary>
        public static String ToString(IEnumerable <FeigTransponder> transponders)
        {
            if (transponders == null)
            {
                return(String.Empty);
            }

            StringBuilder?sb = null;

            try
            {
                sb = StringBuilderPool.Rent();

                var i = 0;

                foreach (var item in transponders)
                {
                    if (i++ > 0)
                    {
                        sb.Append(", ");
                    }

                    sb.Append("{ ");
                    sb.Append(item);
                    sb.Append(" }");
                }

                return(sb.ToString());
            }
            finally
            {
                StringBuilderPool.Free(sb);
            }
        }
예제 #13
0
        public string GetString()
        {
            if (_sprites == null)
            {
                throw new System.Exception();
            }

            if (_cachedString == null)
            {
                var         builder    = StringBuilderPool.Rent(Length);
                Span <char> charBuffer = stackalloc char[2];

                for (int i = 0; i < Length; i++)
                {
                    int utf32 = _sprites[i].Character;
                    int count = TextFormat.ConvertFromUtf32(utf32, charBuffer);

                    for (int j = 0; j < count; j++)
                    {
                        builder.Append(charBuffer[j]);
                    }
                }

                _cachedString = builder.ToString();
                StringBuilderPool.Return(builder);
            }

            return(_cachedString);
        }
        private string CreateExponentialRepresentation(
            DtoaBuilder buffer,
            int exponent,
            bool negative,
            int significantDigits)
        {
            bool negativeExponent = false;

            if (exponent < 0)
            {
                negativeExponent = true;
                exponent         = -exponent;
            }

            using (var builder = StringBuilderPool.Rent())
            {
                if (negative)
                {
                    builder.Builder.Append('-');
                }
                builder.Builder.Append(buffer._chars[0]);
                if (significantDigits != 1)
                {
                    builder.Builder.Append('.');
                    builder.Builder.Append(buffer._chars, 1, buffer.Length - 1);
                    int length = buffer.Length;
                    builder.Builder.Append('0', significantDigits - length);
                }

                builder.Builder.Append('e');
                builder.Builder.Append(negativeExponent ? '-' : '+');
                builder.Builder.Append(exponent);
                return(builder.ToString());
            }
        }
        /// <summary>Gets a text content of the specified file</summary>
        /// <param name="virtualPath">The path to the virtual file</param>
        /// <returns>Text content</returns>
        public string GetFileTextContent(string virtualPath)
        {
            StringBuilderPool shared  = StringBuilderPool.Shared;
            StringBuilder     builder = shared.Rent();

            try
            {
                using (StreamReader streamReader = new StreamReader(BundleTable.VirtualPathProvider.GetFile(virtualPath).Open()))
                {
                    while (streamReader.Peek() >= 0)
                    {
                        builder.AppendLine(streamReader.ReadLine());
                    }
                }
                return(builder.ToString());
            }
            catch (FileNotFoundException ex)
            {
                throw new FileNotFoundException(string.Format(Strings.Common_FileNotExist, (object)virtualPath), virtualPath, (Exception)ex);
            }
            finally
            {
                shared.Return(builder);
            }
        }
예제 #16
0
        public void ValidTest()
        {
            StringBuilder sb = StringBuilderPool.Rent();

            Assert.NotNull(sb);
            Assert.True(sb.Length == 0);
            StringBuilderPool.Return(sb);
        }
예제 #17
0
        public void RenderMainText(BitmapFont font, Color color, Vector2 scale, int maxWidthInChars)
        {
            var builder = StringBuilderPool.Rent(Data.Title.Length + 5);

            DivideTextIntoLines(Data.Title, builder, maxWidthInChars);

            CachedMainText.Clear();
            MainTextSize = font.GetGlyphSprites(
                CachedMainText, builder, Vector2.Zero, color, 0, Vector2.Zero, scale, 0, null);

            StringBuilderPool.Return(builder);
        }
예제 #18
0
        internal static string ToString(double d)
        {
            if (d > long.MinValue && d < long.MaxValue && Math.Abs(d % 1) <= DoubleIsIntegerTolerance)
            {
                // we are dealing with integer that can be cached
                return(ToString((long)d));
            }

            using var stringBuilder = StringBuilderPool.Rent();
            // we can create smaller array as we know the format to be short
            return(NumberPrototype.NumberToString(d, new DtoaBuilder(17), stringBuilder.Builder));
        }
예제 #19
0
        public static string ToHex(this Color color)
        {
            var builder = StringBuilderPool.Rent(8);

            builder.AppendFormat("{0:x2}", color.R);
            builder.AppendFormat("{0:x2}", color.G);
            builder.AppendFormat("{0:x2}", color.B);
            builder.AppendFormat("{0:x2}", color.A);

            string result = builder.ToString();

            StringBuilderPool.Return(builder);
            return(result);
        }
예제 #20
0
        public string GetString()
        {
            AssertIsInUse();

            if (_cachedString == null)
            {
                var builder = StringBuilderPool.Rent(Length);
                builder.AppendIterator(this);

                _cachedString = builder.ToString();
                StringBuilderPool.Return(builder);
            }
            return(_cachedString);
        }
예제 #21
0
        private JsString BuildString(EvaluationContext context)
        {
            using var sb = StringBuilderPool.Rent();
            for (var i = 0; i < _templateLiteralExpression.Quasis.Count; i++)
            {
                var quasi = _templateLiteralExpression.Quasis[i];
                sb.Builder.Append(quasi.Value.Cooked);
                if (i < _expressions.Length)
                {
                    var completion = _expressions[i].GetValue(context);
                    sb.Builder.Append(completion.Value);
                }
            }

            return(JsString.Create(sb.ToString()));
        }
예제 #22
0
        private JsString BuildString()
        {
            using (var sb = StringBuilderPool.Rent())
            {
                for (var i = 0; i < _templateLiteralExpression.Quasis.Count; i++)
                {
                    var quasi = _templateLiteralExpression.Quasis[i];
                    sb.Builder.Append(quasi.Value.Cooked);
                    if (i < _expressions.Length)
                    {
                        sb.Builder.Append(_expressions[i].GetValue());
                    }
                }

                return(JsString.Create(sb.ToString()));
            }
        }
예제 #23
0
        public JavaScriptException SetCallstack(Engine engine, Location?location = null)
        {
            Location = location ?? default;

            using (var sb = StringBuilderPool.Rent())
            {
                foreach (var cse in engine.CallStack)
                {
                    sb.Builder.Append(" at ")
                    .Append(cse)
                    .Append("(");

                    for (var index = 0; index < cse.CallExpression.Arguments.Count; index++)
                    {
                        if (index != 0)
                        {
                            sb.Builder.Append(", ");
                        }
                        var arg = cse.CallExpression.Arguments[index];
                        if (arg is Expression pke)
                        {
                            sb.Builder.Append(GetPropertyKey(pke));
                        }
                        else
                        {
                            sb.Builder.Append(arg);
                        }
                    }

                    sb.Builder.Append(") @ ")
                    .Append(cse.CallExpression.Location.Source)
                    .Append(" ")
                    .Append(cse.CallExpression.Location.Start.Column)
                    .Append(":")
                    .Append(cse.CallExpression.Location.Start.Line)
                    .AppendLine();
                }
                CallStack = sb.ToString();
            }

            return(this);
        }
예제 #24
0
        /// <summary>
        /// Returns a string that represents the current instance.
        /// </summary>
        public override String ToString()
        {
            StringBuilder?sb = null;

            try
            {
                sb = StringBuilderPool.Rent();

                sb.Append("Type: ");
                sb.Append(TransponderType);
                sb.Append(", ID: ");
                sb.Append(Identifier);

                return(sb.ToString());
            }
            finally
            {
                StringBuilderPool.Free(sb);
            }
        }
        protected override string CombineAssetContent(IList <IAsset> assets)
        {
            StringBuilderPool shared        = StringBuilderPool.Shared;
            StringBuilder     stringBuilder = shared.Rent();
            string            empty         = string.Empty;
            List <string>     stringList    = new List <string>();
            int count = assets.Count;
            int num   = count - 1;

            for (int index = 0; index < count; ++index)
            {
                IAsset asset = assets[index];
                if (this.EnableTracing)
                {
                    stringBuilder.AppendFormatLine("/*#region URL: {0} */", (object)asset.Url);
                }
                stringBuilder.Append(StyleCombiner.EjectCssCharsetAndImports(asset.Content, ref empty, (IList <string>)stringList));
                if (this.EnableTracing)
                {
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("/*#endregion*/");
                }
                if (index != num)
                {
                    stringBuilder.AppendLine();
                }
            }
            if (stringList.Count > 0)
            {
                string format = this.EnableTracing ? "/*#region CSS Imports */{0}{1}{0}/*#endregion*/{0}{0}" : "{1}{0}";
                stringBuilder.Insert(0, string.Format(format, (object)Environment.NewLine, (object)string.Join(Environment.NewLine, (IEnumerable <string>)stringList)));
            }
            if (!string.IsNullOrWhiteSpace(empty))
            {
                stringBuilder.Insert(0, empty + Environment.NewLine);
            }
            string str = stringBuilder.ToString();

            shared.Return(stringBuilder);
            return(str);
        }
예제 #26
0
        /// <summary>
        /// Returns a string that represents the current instance.
        /// </summary>
        public override String ToString()
        {
            StringBuilder?sb = null;

            try
            {
                sb = StringBuilderPool.Rent();

                sb.Append("Status: ");
                sb.Append(Status);
                sb.Append(", Response: { ");
                sb.Append(Response?.ToString() ?? "<null>");
                sb.Append(" }");

                return(sb.ToString());
            }
            finally
            {
                StringBuilderPool.Free(sb);
            }
        }
        public string ToBase(long n, int radix)
        {
            const string digits = "0123456789abcdefghijklmnopqrstuvwxyz";

            if (n == 0)
            {
                return("0");
            }

            using (var result = StringBuilderPool.Rent())
            {
                while (n > 0)
                {
                    var digit = (int)(n % radix);
                    n = n / radix;
                    result.Builder.Insert(0, digits[digit]);
                }

                return(result.ToString());
            }
        }
예제 #28
0
        public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response)
        {
            StringBuilderPool sp          = new StringBuilderPool();
            StringBuilder     listBuilder = sp.Rent();

            listBuilder.AppendLine("Here are the available SCPs to swap (Some may be blacklisted):");
            foreach (KeyValuePair <string, RoleType> kvp in EventHandlers.valid)
            {
                listBuilder.Append(kvp.Key);
                listBuilder.Append(" (");
                listBuilder.Append((int)kvp.Value);
                listBuilder.AppendLine(")");
            }

            string message = listBuilder.ToString();

            listBuilder.Clear();

            sp.Return(listBuilder);
            response = message;
            return(true);
        }
        /// <summary>
        /// Returns a string that represents the current instance.
        /// </summary>
        public override String ToString()
        {
            StringBuilder?sb = null;

            try
            {
                sb = StringBuilderPool.Rent();

                sb.Append("Address: ");
                sb.Append(Address);
                sb.Append(", Command: ");
                sb.Append(Command);
                sb.Append(", Data: ");
                sb.Append(Data);

                return(sb.ToString());
            }
            finally
            {
                StringBuilderPool.Free(sb);
            }
        }
예제 #30
0
        public override string ToString()
        {
            // adapted custom version as logic differs between full framework and .NET Core
            var          className                   = GetType().ToString();
            var          message                     = Message;
            var          innerExceptionString        = InnerException?.ToString() ?? "";
            const string endOfInnerExceptionResource = "--- End of inner exception stack trace ---";
            var          stackTrace                  = StackTrace;

            using var rent = StringBuilderPool.Rent();
            var sb = rent.Builder;

            sb.Append(className);
            if (!string.IsNullOrEmpty(message))
            {
                sb.Append(": ");
                sb.Append(message);
            }

            if (InnerException != null)
            {
                sb.Append(Environment.NewLine);
                sb.Append(" ---> ");
                sb.Append(innerExceptionString);
                sb.Append(Environment.NewLine);
                sb.Append("   ");
                sb.Append(endOfInnerExceptionResource);
            }

            if (stackTrace != null)
            {
                sb.Append(Environment.NewLine);
                sb.Append(stackTrace);
            }

            return(rent.ToString());
        }