Created
December 18, 2020 15:30
-
-
Save vshapenko/8dc7f9ae274bc3909ab787b20429b943 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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