Skip to content

Instantly share code, notes, and snippets.

@vshapenko
Created December 18, 2020 15:30
Show Gist options
  • Save vshapenko/8dc7f9ae274bc3909ab787b20429b943 to your computer and use it in GitHub Desktop.
Save vshapenko/8dc7f9ae274bc3909ab787b20429b943 to your computer and use it in GitHub Desktop.
let (|MessageTextAsEmoji|_|) (text: string) =
let isEmojiString (str:string) =
let mutable idx = 0
let mutable res = true
while(idx<str.Length) do
if(Char.IsHighSurrogate(str,idx) || Char.IsLowSurrogate(str,idx)) then
idx <- idx + 1
else
idx <- str.Length
res <- false
res
let symbols = text.Split (char 0x200d,StringSplitOptions.None)
let mutable failed = false
if(symbols.Length) <= 3 then
let mutable res = false
let mutable idx = 0
while (idx<symbols.Length) do
if(isEmojiString symbols.[idx]) then
idx <- idx + 1
else
failed <- true
idx <- symbols.Length
if (failed) then None else Some text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment