Example #1
0
        void IConverter <float> .Convert(ref char *dst, char *end, float value, FormatSpec formatSpec)
        {
            if (formatSpec.fractWidth == 0)
            {
                formatSpec.fractWidth = 2;
            }

            var intWidth = formatSpec.argWidth - formatSpec.fractWidth - 1;
            // Very crappy version for now
            bool neg = false;

            if (value < 0.0f)
            {
                neg   = true;
                value = -value;
            }

            int   v1        = Mathf.FloorToInt(value);
            float fractMult = (int)Mathf.Pow(10.0f, formatSpec.fractWidth);
            int   v2        = Mathf.FloorToInt(value * fractMult) % (int)(fractMult);

            ConvertInt(ref dst, end, neg ? -v1 : v1, intWidth, formatSpec.integerWidth, formatSpec.leadingZero);
            if (dst < end)
            {
                *dst++ = '.';
            }
            ConvertInt(ref dst, end, v2, formatSpec.fractWidth, formatSpec.fractWidth, true);
        }
Example #2
0
        void IConverter <string> .Convert(ref char *dst, char *end, string value, FormatSpec formatSpec)
        {
            int lpadding = 0, rpadding = 0;

            if (formatSpec.argWidth < 0)
            {
                rpadding = -formatSpec.argWidth - value.Length;
            }
            else
            {
                lpadding = formatSpec.argWidth - value.Length;
            }

            while (lpadding-- > 0 && dst < end)
            {
                *dst++ = ' ';
            }

            for (int i = 0, l = value.Length; i < l && dst < end; i++)
            {
                *dst++ = value[i];
            }

            while (rpadding-- > 0 && dst < end)
            {
                *dst++ = ' ';
            }
        }
Example #3
0
 void IConverter <byte> .Convert(ref char *dst, char *end, byte value, FormatSpec formatSpec)
 {
     ConvertInt(ref dst, end, value, formatSpec.argWidth, formatSpec.integerWidth, formatSpec.leadingZero);
 }