Fan.Sys.FanInt.toDigit C# (CSharp) Method

toDigit() public static method

public static toDigit ( long self ) : Long
self long
return Long
        public static Long toDigit(long self)
        {
            long val = self;
              if (0 <= val && val <= 9) return Long.valueOf((int)val + '0');
              return null;
        }

Same methods

FanInt::toDigit ( long self, long radix ) : Long

Usage Example

Example #1
0
        private void writePropStr(string s)
        {
            int len = s.Length;

            for (int i = 0; i < len; ++i)
            {
                int ch   = s[i];
                int peek = i + 1 < len ? s[i + 1] : -1;

                // escape special chars
                switch (ch)
                {
                case '\n': writeChar('\\').writeChar('n'); continue;

                case '\r': writeChar('\\').writeChar('r'); continue;

                case '\t': writeChar('\\').writeChar('t'); continue;

                case '\\': writeChar('\\').writeChar('\\'); continue;
                }

                // escape control chars, comments, and =
                if ((ch < ' ') || (ch == '/' && (peek == '/' || peek == '*')) || (ch == '='))
                {
                    long nib1 = FanInt.toDigit((ch >> 4) & 0xf, 16).longValue();
                    long nib2 = FanInt.toDigit((ch >> 0) & 0xf, 16).longValue();

                    this.writeChar('\\').writeChar('u')
                    .writeChar('0').writeChar('0')
                    .writeChar(nib1).writeChar(nib2);
                    continue;
                }

                // normal character
                writeChar(ch);
            }
        }