Text.ToList()は文字列を文字のListに変換するPower Query M関数ですが、サロゲートペアや異体字セレクタには対応していないようです。
これらに簡易的に対応した関数(TextToListEx)を試作してみました(関連ツイート)。
(え、結合文字? 知らない子ですね……)
Last active
May 13, 2022 09:47
-
-
Save furyutei/dfe4512c6de5d674f5d1a6af2408c30e to your computer and use it in GitHub Desktop.
[Excel][Power Query] TextToListEx():Text.ToList()でサポートされていないサロゲートペアや異体字セレクタに簡易的に対応した関数
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
(SpecifiedText as text) => | |
let | |
ResultCharList = List.Accumulate( | |
Text.ToList(SpecifiedText), | |
[charlist={}, stackchar=""], | |
(state, char) => [ | |
last_stackchar = state[stackchar], | |
charcode = try Character.ToNumber(char), | |
is_surrogate_start = charcode[HasError] and last_stackchar = "", | |
newchar = last_stackchar & char, | |
newcharcode = try Character.ToNumber(newchar) otherwise 0, | |
is_variant_selector = 0xE0100 <= newcharcode and newcharcode <= 0xE01EF, | |
last_charlist = state[charlist], | |
charlist = if is_variant_selector | |
then List.ReplaceRange(last_charlist, List.Count(last_charlist)-1, 1, {List.Last(last_charlist) & newchar}) | |
else (if is_surrogate_start then last_charlist else (last_charlist & {newchar})), | |
stackchar = if is_surrogate_start then char else "" | |
] | |
)[charlist] | |
in | |
ResultCharList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment