ADDED: '$first_non_octet'/2, for much more efficient domain checks in library(crypto).
'$first_non_octet'(Cs, C) <=> C is the leftmost character in the string Cs whose character code is not in 0..255.
This commit is contained in:
@@ -296,6 +296,7 @@ pub(crate) enum SystemClauseType {
|
||||
Ed25519NewKeyPair,
|
||||
Ed25519KeyPairPublicKey,
|
||||
Curve25519ScalarMult,
|
||||
FirstNonOctet,
|
||||
LoadHTML,
|
||||
LoadXML,
|
||||
GetEnv,
|
||||
@@ -588,6 +589,7 @@ impl SystemClauseType {
|
||||
clause_name!("$ed25519_keypair_public_key")
|
||||
}
|
||||
&SystemClauseType::Curve25519ScalarMult => clause_name!("$curve25519_scalar_mult"),
|
||||
&SystemClauseType::FirstNonOctet => clause_name!("$first_non_octet"),
|
||||
&SystemClauseType::LoadHTML => clause_name!("$load_html"),
|
||||
&SystemClauseType::LoadXML => clause_name!("$load_xml"),
|
||||
&SystemClauseType::GetEnv => clause_name!("$getenv"),
|
||||
@@ -810,6 +812,7 @@ impl SystemClauseType {
|
||||
("$ed25519_new_keypair", 1) => Some(SystemClauseType::Ed25519NewKeyPair),
|
||||
("$ed25519_keypair_public_key", 2) => Some(SystemClauseType::Ed25519KeyPairPublicKey),
|
||||
("$curve25519_scalar_mult", 3) => Some(SystemClauseType::Curve25519ScalarMult),
|
||||
("$first_non_octet", 2) => Some(SystemClauseType::FirstNonOctet),
|
||||
("$load_html", 3) => Some(SystemClauseType::LoadHTML),
|
||||
("$load_xml", 3) => Some(SystemClauseType::LoadXML),
|
||||
("$getenv", 2) => Some(SystemClauseType::GetEnv),
|
||||
|
||||
@@ -5340,6 +5340,18 @@ impl MachineState {
|
||||
let cstr = self.heap.put_complete_string(&string);
|
||||
(self.unify_fn)(self, self[temp_v!(3)], cstr);
|
||||
}
|
||||
&SystemClauseType::FirstNonOctet => {
|
||||
for c in self.heap_pstr_iter(self[temp_v!(1)]).to_string().chars() {
|
||||
if c as u32 > 255 {
|
||||
let chars = clause_name!(String::from(c.to_string()), self.atom_tbl);
|
||||
let non_octet = self.heap.to_unifiable(HeapCellValue::Atom(chars, None));
|
||||
(self.unify_fn)(self, self[temp_v!(2)], non_octet);
|
||||
return return_from_clause!(self.last_call, self);
|
||||
}
|
||||
}
|
||||
self.fail = true;
|
||||
return Ok(());
|
||||
}
|
||||
&SystemClauseType::LoadHTML => {
|
||||
let string = self.heap_pstr_iter(self[temp_v!(1)]).to_string();
|
||||
let doc = select::document::Document::from_read(string.as_bytes()).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user