unicode

Branch: main

Switch branches or tags

Branch: main
Go to file t

413 files indexed

History
Code

unicode/idna/facade.mbt
1///|2pub(all) suberror IdnaError {3  PunycodeError(@legacy_punycode.PunycodeError)4  DisallowedCodePoint(cp~ : Int32)5  InvalidLabel(String)6  InvalidHyphen7  LabelTooLong8  DomainTooLong9  EmptyLabel10  InvalidBidi11  InvalidJoiner12  InvalidContextO(cp~ : Int32)13  InvalidAcePrefix14  LeadingCombiningMark15}1617///|18pub extend IdnaError with Show::{to_string, output}1920///|21pub impl Show for IdnaError with fn output(self, logger) {22  match self {23    PunycodeError(error) =>24      logger.write_string("PunycodeError(\{error.to_string()})")25    DisallowedCodePoint(cp~) =>26      logger.write_string("DisallowedCodePoint(cp=\{cp.to_string()})")27    InvalidLabel(label) =>28      logger.write_string("InvalidLabel(\{label.to_string()})")29    InvalidHyphen => logger.write_string("InvalidHyphen")30    LabelTooLong => logger.write_string("LabelTooLong")31    DomainTooLong => logger.write_string("DomainTooLong")32    EmptyLabel => logger.write_string("EmptyLabel")33    InvalidBidi => logger.write_string("InvalidBidi")34    InvalidJoiner => logger.write_string("InvalidJoiner")35    InvalidContextO(cp~) =>36      logger.write_string("InvalidContextO(cp=\{cp.to_string()})")37    InvalidAcePrefix => logger.write_string("InvalidAcePrefix")38    LeadingCombiningMark => logger.write_string("LeadingCombiningMark")39  }40}4142///|43fn legacy_punycode_error(44  error : @punycode_impl.PunycodeError,45) -> @legacy_punycode.PunycodeError {46  match error {47    @punycode_impl.Overflow => @legacy_punycode.Overflow48    @punycode_impl.InvalidInput => @legacy_punycode.InvalidInput49    @punycode_impl.BadInput => @legacy_punycode.BadInput50  }51}5253///|54fn legacy_error(error : @impl.IdnaError) -> IdnaError {55  match error {56    @impl.PunycodeError(error) => PunycodeError(legacy_punycode_error(error))57    @impl.DisallowedCodePoint(cp~) => DisallowedCodePoint(cp~)58    @impl.InvalidLabel(label) => InvalidLabel(label)59    @impl.InvalidHyphen => InvalidHyphen60    @impl.LabelTooLong => LabelTooLong61    @impl.DomainTooLong => DomainTooLong62    @impl.EmptyLabel => EmptyLabel63    @impl.InvalidBidi => InvalidBidi64    @impl.InvalidJoiner => InvalidJoiner65    @impl.InvalidContextO(cp~) => InvalidContextO(cp~)66    @impl.InvalidAcePrefix => InvalidAcePrefix67    @impl.LeadingCombiningMark => LeadingCombiningMark68  }69}7071///|72pub fn to_ascii(73  domain : String,74  use_std3_ascii_rules~ : Bool = true,75  check_hyphens~ : Bool = true,76  check_bidi~ : Bool = true,77  check_joiners~ : Bool = true,78  check_idna2008~ : Bool = false,79  check_contexto~ : Bool = false,80  verify_dns_length~ : Bool = true,81) -> String raise IdnaError {82  @impl.to_ascii(83    domain,84    use_std3_ascii_rules~,85    check_hyphens~,86    check_bidi~,87    check_joiners~,88    check_idna2008~,89    check_contexto~,90    verify_dns_length~,91  ) catch {92    error => raise legacy_error(error)93  }94}9596///|97pub fn to_unicode(98  domain : String,99  use_std3_ascii_rules~ : Bool = true,100  check_hyphens~ : Bool = true,101  check_bidi~ : Bool = true,102  check_joiners~ : Bool = true,103  check_idna2008~ : Bool = false,104  check_contexto~ : Bool = false,105) -> String raise IdnaError {106  @impl.to_unicode(107    domain,108    use_std3_ascii_rules~,109    check_hyphens~,110    check_bidi~,111    check_joiners~,112    check_idna2008~,113    check_contexto~,114  ) catch {115    error => raise legacy_error(error)116  }117}118