internal static bool ConvertTo(AdName.ConvertOption option, string input, int startIndex, int length, out string converted) { if (!AdName.TryConvertTo(option, input, startIndex, length, out converted)) { throw new FormatException(DirectoryStrings.InvalidDNFormat(input)); } return(converted != null); }
internal static bool TryConvertTo(AdName.ConvertOption option, string input, int startIndex, int length, out string converted) { converted = null; StringBuilder stringBuilder = null; int num = startIndex; int num2 = startIndex; int num3 = startIndex + length; switch (option) { case AdName.ConvertOption.Escape: num2 = AdName.EscapeChar(input, ref num, startIndex + 1, num3, num2, true, ref stringBuilder); if (num2 < num3 - 2) { num2 = AdName.EscapeChar(input, ref num, num3 - 1, num3, ++num2, false, ref stringBuilder); } if (num2 < num3 - 1) { AdName.EscapeChar(input, ref num, num3, num3, ++num2, true, ref stringBuilder); } break; case AdName.ConvertOption.Unescape: if (!AdName.UnescapeChar(input, ref num, startIndex + 1, num3, ref num2, true, ref stringBuilder)) { return(false); } if (num2 < num3 - 3) { num2++; if (!AdName.UnescapeChar(input, ref num, num3 - 2, num3, ref num2, false, ref stringBuilder)) { return(false); } } if (num2 < num3 - 1) { num2++; if (!AdName.UnescapeChar(input, ref num, num3, num3, ref num2, true, ref stringBuilder)) { return(false); } } break; case AdName.ConvertOption.Format: if (input[startIndex] == ' ') { while (++startIndex < num3 && input[startIndex] == ' ') { } if (startIndex >= num3) { return(false); } if (!AdName.TryConvertTo(AdName.ConvertOption.Format, input, startIndex, num3 - startIndex, out converted)) { return(false); } if (converted == null) { converted = input.Substring(startIndex, num3 - startIndex); } return(true); } else { if (!AdName.TryFormatChar(input, ref num, startIndex + 1, num3, ref num2, true, true, ref stringBuilder)) { return(false); } if (num2 < num3 - 3) { num2++; if (!AdName.TryFormatChar(input, ref num, num3 - 2, num3, ref num2, false, false, ref stringBuilder)) { return(false); } } if (num2 < num3 - 2 && input[num2 + 1] == ' ') { num2++; if (!AdName.TryFormatChar(input, ref num, num3 - 1, num3, ref num2, true, false, ref stringBuilder)) { return(false); } } if (num2 < num3 - 1) { num2++; if (!AdName.TryFormatChar(input, ref num, num3, num3, ref num2, true, true, ref stringBuilder)) { return(false); } } } break; } if (stringBuilder == null) { return(true); } if (num < num3) { stringBuilder.Append(input, num, num3 - num); } converted = stringBuilder.ToString(); if (converted.Equals(input)) { converted = input; } return(true); }