247 {
248 if (unicode.Length == 0)
249 {
251 }
253 int num = 0;
254 int num2 = 0;
255 int num3 = 0;
256 while (num < unicode.Length)
257 {
259 if (num < 0)
260 {
261 num = unicode.Length;
262 }
263 if (num == num2)
264 {
265 if (num == unicode.Length)
266 {
267 break;
268 }
270 }
271 stringBuilder.
Append(
"xn--");
272 bool flag = false;
275 {
276 flag = true;
277 int num4 = num - 1;
278 if (char.IsLowSurrogate(unicode, num4))
279 {
280 num4--;
281 }
282 bidiCategory = CharUnicodeInfo.GetBidiCategory(unicode, num4);
284 {
286 }
287 }
288 int num5 = 0;
289 for (
int i = num2;
i < num;
i++)
290 {
293 {
295 }
297 {
299 }
300 if (
Basic(unicode[i]))
301 {
303 num5++;
304 }
305 else if (char.IsSurrogatePair(unicode, i))
306 {
308 }
309 }
310 int num6 = num5;
311 if (num6 == num - num2)
312 {
313 stringBuilder.
Remove(num3,
"xn--".Length);
314 }
315 else
316 {
317 if (unicode.Length - num2 >=
"xn--".Length && unicode.Substring(num2,
"xn--".Length).Equals(
"xn--",
StringComparison.OrdinalIgnoreCase))
318 {
320 }
321 int num7 = 0;
322 if (num6 > 0)
323 {
324 stringBuilder.
Append(
'-');
325 }
326 int num8 = 128;
327 int num9 = 0;
328 int num10 = 72;
329 while (num5 < num - num2)
330 {
331 int num11 = 0;
332 int num12 = 134217727;
334 {
335 num11 = char.ConvertToUtf32(unicode, j);
336 if (num11 >= num8 && num11 < num12)
337 {
338 num12 = num11;
339 }
340 }
341 num9 += (num12 - num8) * (num5 - num7 + 1);
342 num8 = num12;
344 {
345 num11 = char.ConvertToUtf32(unicode, j);
346 if (num11 < num8)
347 {
348 num9++;
349 }
350 if (num11 != num8)
351 {
352 continue;
353 }
354 int num13 = num9;
355 int num14 = 36;
356 while (true)
357 {
358 int num15 = ((num14 <= num10) ? 1 : ((num14 >= num10 + 26) ? 26 : (num14 - num10)));
359 if (num13 < num15)
360 {
361 break;
362 }
364 num13 = (num13 - num15) / (36 - num15);
365 num14 += 36;
366 }
368 num10 =
Adapt(num9, num5 - num7 + 1, num5 == num6);
369 num9 = 0;
370 num5++;
372 {
373 num5++;
374 num7++;
375 }
376 }
377 num9++;
378 num8++;
379 }
380 }
381 if (stringBuilder.
Length - num3 > 63)
382 {
384 }
385 if (num != unicode.Length)
386 {
387 stringBuilder.
Append(
'.');
388 }
389 num2 = num + 1;
390 num3 = stringBuilder.
Length;
391 }
392 if (stringBuilder.
Length > 255 - ((!
IsDot(unicode[^1])) ? 1 : 0))
393 {
394 throw new ArgumentException(SR.Format(SR.Argument_IdnBadNameSize, 255 - ((!
IsDot(unicode[^1])) ? 1 : 0)),
"unicode");
395 }
397 }
static bool IsDot(char c)
static char EncodeDigit(int d)
static readonly char[] s_dotSeparators
static char EncodeBasic(char bcp)
static bool IsSupplementary(int cTest)
static int Adapt(int delta, int numpoints, bool firsttime)
StringBuilder Remove(int startIndex, int length)
override string ToString()
StringBuilder Append(char value, int repeatCount)