unicode

Branch: main

Switch branches or tags

Branch: main
Go to file t

413 files indexed

History
Code

idna/contexto.mbt
1///|2/// RFC 5892 Appendix A.3-A.9: contextual rules other than join controls.3/// The caller passes a mapped, normalized label containing a CONTEXTO4/// character. Script tests use the Unicode Script property, not blocks or5/// Script_Extensions.6fn validate_contexto(7  label : StringView,8  has_katakana_middle_dot~ : Bool,9) -> Unit raise IdnaError {10  // U+0000 cannot satisfy any of the preceding-character conditions.11  let mut previous = '\u{0000}'12  let mut has_japanese = false13  let mut has_arabic_indic_digits = false14  let mut has_extended_arabic_indic_digits = false15  for c in label {16    // Check a required successor when it arrives, before the current17    // character's own rule, so the earlier violation still takes precedence.18    if previous == '\u{00B7}' && c != 'l' {19      raise InvalidContextO(cp=0x00B7)20    }21    if previous == '\u{0375}' || (has_katakana_middle_dot && !has_japanese) {22      let properties = @idna_data.lookup_idna_properties(c)23      if previous == '\u{0375}' && !properties.is_greek() {24        raise InvalidContextO(cp=0x0375)25      }26      if properties.is_japanese() {27        has_japanese = true28      }29    }30    match c {31      '\u{00B7}' => {32        // The following l is checked on the next iteration.33        guard previous == 'l' else { raise InvalidContextO(cp=c.to_int()) }34      }35      '\u{05F3}' | '\u{05F4}' => {36        guard @idna_data.lookup_idna_properties(previous).is_hebrew() else {37          raise InvalidContextO(cp=c.to_int())38        }39      }40      '\u{0660}'..<='\u{0669}' => {41        guard !has_extended_arabic_indic_digits else {42          raise InvalidContextO(cp=c.to_int())43        }44        has_arabic_indic_digits = true45      }46      '\u{06F0}'..<='\u{06F9}' => {47        guard !has_arabic_indic_digits else {48          raise InvalidContextO(cp=c.to_int())49        }50        has_extended_arabic_indic_digits = true51      }52      _ => ()53    }54    previous = c55  }56  // A final middle dot or Greek numeral sign has no required successor.57  if previous is ('\u{00B7}' | '\u{0375}') {58    raise InvalidContextO(cp=previous.to_int())59  }60  // U+30FB itself has Script=Common, so it cannot satisfy its own rule.61  if has_katakana_middle_dot && !has_japanese {62    raise InvalidContextO(cp=0x30FB)63  }64}65