This commit is contained in:
Brandon Thomas committed 2025-10-28 14:36:35 -04:00
1 parent 4acdc0f9f6
commit 213c1e9283
3 files changed
+73 -2

No files matched your search

@@ -1,2 +1,3 @@
pub mod signature_xs;
pub mod generate_sign_for_new_conversation;
pub mod generate_sign_for_new_conversation;
mod signature_xa;
@@ -0,0 +1,69 @@
use once_cell::sync::Lazy;
use regex::Regex;
use crate::error::grok_client_error::GrokClientError;
static CLEAN_NON_DIGIT_REGEX : Lazy<Regex> = Lazy::new(|| {
Regex::new(r#"[^\d]+"#)
.expect("Regex should parse")
});
/*
@staticmethod
def xa(svg: str) -> List[List[int]]:
s = (svg)
substr = s[9:]
parts = substr.split("C")
out = []
for part in parts:
cleaned = sub(r"[^\d]+", " ", part).strip()
if cleaned == "":
nums = [0]
else:
nums = [int(tok) for tok in cleaned.split() if tok != ""]
out.append(nums)
return out
*/
/// Based on "Grok-Api/core/xctid.py"
/// `svg_data` is the <path d="" /> svg path stroke data
pub fn signature_xa(svg_data: &str) -> Result<Vec<Vec<u32>>, GrokClientError> {
// s = (svg) -- not this is needed, looks like a NO-OP to me.
let s = svg_data;
println!("s.len() ={}", s.len());
// substr = s[9:]
let substr = &s[9..];
println!("Substr ={}", substr);
println!("substr.len() ={}", substr.len());
// parts = substr.split("C")
let parts = substr.split("C").collect::<Vec<_>>();
println!("parts.len() = {}", parts.len());
println!("parts = {:?}", parts);
let mut out = Vec::new();
for part in parts {
// cleaned = sub(r"[^\d]+", " ", part).strip()
let cleaned = CLEAN_NON_DIGIT_REGEX.replace_all(part, " ").to_string().trim().to_string();
println!("cleaned len = {} value = {}", cleaned.len(), cleaned);
}
Ok(out)
}
#[cfg(test)]
mod tests {
use crate::requests::index_page::signature::signature_xa::signature_xa;
#[test]
fn test() {
let svg_data = "M 10,30 C 147,16 51,222 136,87 h 31 s 177,77 40,114 C 68,166 18,188 114,44 h 220 s 148,210 202,25 C 220,36 246,218 12,120 h 244 s 34,154 56,161 C 211,204 208,60 174,14 h 155 s 157,116 220,95 C 116,164 53,210 174,232 h 139 s 148,151 135,221 C 167,196 118,27 149,247 h 233 s 129,238 113,21 C 73,44 215,158 218,29 h 68 s 13,98 243,134 C 44,98 149,35 20,178 h 163 s 219,104 41,152 C 237,107 118,120 127,117 h 57 s 41,167 43,136 C 116,168 44,246 182,209 h 143 s 238,93 237,119 C 142,36 64,67 97,111 h 71 s 230,247 119,27 C 206,56 158,51 71,115 h 135 s 120,186 74,57 C 197,165 180,214 102,16 h 88 s 252,48 189,166 C 163,237 57,253 154,60 h 96 s 84,56 15,66 C 177,101 10,202 185,227 h 29 s 204,55 115,219 C 103,82 127,143 194,99 h 102 s 179,63 84,110";
signature_xa(&svg_data).unwrap();
assert_eq!(1,2);
}
}
@@ -22,6 +22,7 @@ use crate::error::grok_client_error::GrokClientError;
return cleaned
*/
/// Based on "Grok-Api/core/xctid.py"
/// `bytes` is
/// `svg_data` is the <path d="" /> svg path stroke data
/// `x_values` are the magic numbers from the script
@@ -87,4 +88,4 @@ mod tests {
assert_eq!(1,2);
}
}
}