How to recover substrings from text in a post given UTF-8 indices? #3019
Unanswered
r002
asked this question in
How to do it?
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone,
I'm new here, so apologies if this is a newbie question! I've been playing w/ the bsky APIs and ATProto for the past month and am currently trying to parse a hydrated post.
I have this:
![image](https://private-user-images.githubusercontent.com/45280066/386864680-fce1a808-d783-4f1c-90d0-ae1e56b9734f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzMDU3NTIsIm5iZiI6MTczOTMwNTQ1MiwicGF0aCI6Ii80NTI4MDA2Ni8zODY4NjQ2ODAtZmNlMWE4MDgtZDc4My00ZjFjLTkwZDAtYWUxZTU2Yjk3MzRmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjExVDIwMjQxMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTdmNTQ5NThmYjc1ZTY3YTU0Njg0MjgzOGQ4MmRiNWNhYzk2YmFkZDFiZjYwYTkwZWU5ZDc3NzZjYjhlNGI3N2YmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.v2PRkradrqfcu1spsIMxF0P5TSAsm_WphtOfbgMThAY)
but just need an easy way to map the
did
to thehandle
. I did read the docs and see here we're not supposed to use.slice()
bc JS isutf-16
vs ATProto'sutf-8
.So what is the best way to do this today? Basically, I just want a richText library function where I can put in the text and indices and get back the substring I'm interested in. Something like,
.getText(text, 113, 134)
and get backmmasnick.bsky.social
. Do I just write my own? Is there already an existing helper function in theATProto RichText
library that I'm unaware of?If someone could pls advise, I'd be grateful. TIA!! 🙏
Beta Was this translation helpful? Give feedback.
All reactions