@@ -21,7 +21,7 @@ public int Compare(object a, object b) {
2121 }
2222 }
2323
24- class CryptoUtil {
24+ static class CryptoUtil {
2525 /// <summary>
2626 /// Computes the SHA256 hash of a given input.
2727 /// </summary>
@@ -50,27 +50,13 @@ public static byte[] ComputeHash(byte[] buffer, int offset, int count) {
5050 }
5151 }
5252
53- class HttpDate {
53+ static class HttpDate {
5454 private static readonly int [ ] s_tensDigit = { 0 , 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 } ;
55-
56- private static int Atoi2 ( string s , int startIndex ) {
57- try {
58- int tens = s [ 0 + startIndex ] - '0' ;
59- int ones = s [ 1 + startIndex ] - '0' ;
60-
61- return s_tensDigit [ tens ] + ones ;
62- }
63- catch {
64- throw new FormatException ( "Atio2Badstring" ) ;
65- }
66- }
67-
6855 private static readonly string [ ] s_months = {
6956 "Jan" , "Feb" , "Mar" , "Apr" ,
7057 "May" , "Jun" , "Jul" , "Aug" ,
7158 "Sep" , "Oct" , "Nov" , "Dec"
7259 } ;
73-
7460 // Custom table for make_month() for mapping "Apr" to 4
7561 private static readonly sbyte [ ] s_monthIndexTable = {
7662 - 1 , ( sbyte ) 'A' , 2 , 12 , - 1 , - 1 , - 1 , 8 , // A to G
@@ -82,54 +68,7 @@ private static int Atoi2(string s, int startIndex) {
8268 9 , - 1 , ( sbyte ) 'R' , - 1 , 10 , - 1 , 11 , - 1 , // p to w
8369 - 1 , 5 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 // x to z
8470 } ;
85-
86- private static int make_month ( string s , int startIndex ) {
87- //
88- // use the third character as the index
89- //
90- int i = ( s [ 2 + startIndex ] - 0x40 ) & 0x3F ;
91- sbyte monthIndex = s_monthIndexTable [ i ] ;
92- if ( monthIndex >= 13 ) {
93- //
94- // ok, we need to look at the second character
95- //
96- switch ( monthIndex ) {
97- case ( sbyte ) 'N' :
98- //
99- // we got an N which we need to resolve further
100- //
101- //
102- // if s[1] is 'u' then Jun, if 'a' then Jan
103- //
104- monthIndex =
105- ( sbyte ) ( s_monthIndexTable [ ( s [ 1 + startIndex ] - 0x40 ) & 0x3f ] == ( sbyte ) 'A' ? 1 : 6 ) ;
106- break ;
107- case ( sbyte ) 'R' :
108- //
109- // if s[1] is 'a' then March, if 'p' then April
110- //
111- monthIndex =
112- ( sbyte ) ( s_monthIndexTable [ ( s [ 1 + startIndex ] - 0x40 ) & 0x3f ] == ( sbyte ) 'A' ? 3 : 4 ) ;
113- break ;
114- default :
115- throw new FormatException ( "MakeMonthBadstring" ) ;
116- }
117- }
118- string monthstring = s_months [ monthIndex - 1 ] ;
119- if ( ( s [ 0 + startIndex ] == monthstring [ 0 ] ) &&
120- ( s [ 1 + startIndex ] == monthstring [ 1 ] ) &&
121- ( s [ 2 + startIndex ] == monthstring [ 2 ] ) ) {
122- return ( monthIndex ) ;
123- }
124- if ( ( char . ToUpper ( s [ 0 + startIndex ] , CultureInfo . InvariantCulture ) == monthstring [ 0 ] ) &&
125- ( char . ToLower ( s [ 1 + startIndex ] , CultureInfo . InvariantCulture ) == monthstring [ 1 ] ) &&
126- ( char . ToLower ( s [ 2 + startIndex ] , CultureInfo . InvariantCulture ) == monthstring [ 2 ] ) ) {
127- return monthIndex ;
128- }
129- throw new FormatException ( "MakeMonthBadstring" ) ;
130- }
131-
132- public static DateTime UtcParse ( string time ) {
71+ public static DateTime UtcParse ( string time ) {
13372 int i ;
13473 int year , month , day , hour , minute , second ;
13574 if ( time == null ) {
@@ -190,9 +129,67 @@ public static DateTime UtcParse(string time) {
190129 }
191130 return new DateTime ( year , month , day , hour , minute , second , DateTimeKind . Utc ) ;
192131 }
193- }
194132
195- class StringUtil {
133+ private static int Atoi2 ( string s , int startIndex ) {
134+ try {
135+ int tens = s [ 0 + startIndex ] - '0' ;
136+ int ones = s [ 1 + startIndex ] - '0' ;
137+
138+ return s_tensDigit [ tens ] + ones ;
139+ }
140+ catch {
141+ throw new FormatException ( "Atio2Badstring" ) ;
142+ }
143+ }
144+
145+ private static int make_month ( string s , int startIndex ) {
146+ //
147+ // use the third character as the index
148+ //
149+ int i = ( s [ 2 + startIndex ] - 0x40 ) & 0x3F ;
150+ sbyte monthIndex = s_monthIndexTable [ i ] ;
151+ if ( monthIndex >= 13 ) {
152+ //
153+ // ok, we need to look at the second character
154+ //
155+ switch ( monthIndex ) {
156+ case ( sbyte ) 'N' :
157+ //
158+ // we got an N which we need to resolve further
159+ //
160+ //
161+ // if s[1] is 'u' then Jun, if 'a' then Jan
162+ //
163+ monthIndex =
164+ ( sbyte ) ( s_monthIndexTable [ ( s [ 1 + startIndex ] - 0x40 ) & 0x3f ] == ( sbyte ) 'A' ? 1 : 6 ) ;
165+ break ;
166+ case ( sbyte ) 'R' :
167+ //
168+ // if s[1] is 'a' then March, if 'p' then April
169+ //
170+ monthIndex =
171+ ( sbyte ) ( s_monthIndexTable [ ( s [ 1 + startIndex ] - 0x40 ) & 0x3f ] == ( sbyte ) 'A' ? 3 : 4 ) ;
172+ break ;
173+ default :
174+ throw new FormatException ( "MakeMonthBadstring" ) ;
175+ }
176+ }
177+ string monthstring = s_months [ monthIndex - 1 ] ;
178+ if ( ( s [ 0 + startIndex ] == monthstring [ 0 ] ) &&
179+ ( s [ 1 + startIndex ] == monthstring [ 1 ] ) &&
180+ ( s [ 2 + startIndex ] == monthstring [ 2 ] ) ) {
181+ return ( monthIndex ) ;
182+ }
183+ if ( ( char . ToUpper ( s [ 0 + startIndex ] , CultureInfo . InvariantCulture ) == monthstring [ 0 ] ) &&
184+ ( char . ToLower ( s [ 1 + startIndex ] , CultureInfo . InvariantCulture ) == monthstring [ 1 ] ) &&
185+ ( char . ToLower ( s [ 2 + startIndex ] , CultureInfo . InvariantCulture ) == monthstring [ 2 ] ) ) {
186+ return monthIndex ;
187+ }
188+ throw new FormatException ( "MakeMonthBadstring" ) ;
189+ }
190+ }
191+
192+ static class StringUtil {
196193 public static bool StringArrayEquals ( string [ ] a , string [ ] b ) {
197194 if ( ( a == null ) != ( b == null ) ) {
198195 return false ;
0 commit comments