23 using System.Globalization;
25 namespace Lucene.Net.Support
35 public const int MIN_RADIX = 2;
39 public const int MAX_RADIX = 36;
41 private const System.String digits =
"0123456789abcdefghijklmnopqrstuvwxyz";
49 public static System.String ToString(
long number)
51 System.Text.StringBuilder s =
new System.Text.StringBuilder();
67 char c = digits[(int)number % 36];
82 public static System.String ToString(
float f)
84 if (((
float)(
int)f) == f)
86 return ((
int)f).ToString() +
".0";
90 return f.ToString(NumberFormatInfo.InvariantInfo);
100 public static System.String ToString(
long i,
int radix)
102 if (radix < MIN_RADIX || radix > MAX_RADIX)
105 char[] buf =
new char[65];
107 bool negative = (i < 0);
116 buf[charPos--] = digits[(int)(-(i % radix))];
119 buf[charPos] = digits[(int)(-i)];
123 buf[--charPos] =
'-';
126 return new System.String(buf, charPos, (65 - charPos));
135 public static long Parse(System.String s,
int radix)
139 throw new ArgumentException(
"null");
142 if (radix < MIN_RADIX)
144 throw new NotSupportedException(
"radix " + radix +
145 " less than Number.MIN_RADIX");
147 if (radix > MAX_RADIX)
149 throw new NotSupportedException(
"radix " + radix +
150 " greater than Number.MAX_RADIX");
158 for (
int i = s.Length - 1; i >= 0; i--)
160 int weight = digits.IndexOf(s[i]);
162 throw new FormatException(
"Invalid number for the specified radix");
164 result += (weight * mult);
177 public static int URShift(
int number,
int bits)
179 return (
int)(((uint)number) >> bits);
189 public static long URShift(
long number,
int bits)
191 return (
long)(((ulong)number) >> bits);
203 public static int NextSetBit(System.Collections.BitArray bits,
int fromIndex)
205 for (
int i = fromIndex; i < bits.Length; i++)
220 public static long ToInt64(System.String s)
226 if (s.StartsWith(
"-"))
237 for (
int i = s.Length - 1; i > -1; i--)
239 int n = digits.IndexOf(s[i]);
243 throw new System.ArgumentException(
"Invalid or unsupported character in number: " + s[i]);
245 number += (n * factor);