Xray is an academic exploration of strings and encodings in Elixir.
It offers utility functions useful for inspecting strings and their code points to better understand strings and encodings.
See the related article on Medium.
The Xray.inspect/1 function gives you a deep introspection on a string:
iex>Xray.inspect("cät")======================================================
Input String: cätCharacterCount: 3ByteCount: 4Is valid? trueIsprintable?true======================================================
cCodepoint: 99(\u0063)https://codepoints.net/U+0063Isprintable?trueScript(s): latinByteCount: 1UTF-8: <<99>>Base2: 01100011äCodepoint: 228(\u00E4)https://codepoints.net/U+00E4
Is printable?trueScript(s): latinByteCount: 2UTF-8: <<195,164>>Base2: 1100001110100100tCodepoint: 116(\u0074)https://codepoints.net/U+0074Isprintable?trueScript(s): latinByteCount: 1UTF-8: <<116>>Base2: 01110100[:ok,:ok,:ok]The Xray.codepoint/2 function provides the code point for a single character -- functionally, this is equivalent to what the question-mark operator ? does, but Xray.codepoint/2 allows you to inspect a variable (whereas ? only operates on literal values):
iex>Xray.codepoint("ä")228Xray.codepoints/2 allows you to inspect the component codepoint numbers that make up the given string:
iex>Xray.codepoints("cät")"99, 228, 116"See Xray Hex Docs for more info.
If available in Hex, the package can be installed
by adding xray to your list of dependencies in mix.exs:
defdepsdo[{:xray,"~> 1.2.0"}]endDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/xray.
iex>String.codepoints("🇺🇸")["🇺","🇸"]iex>String.split("🇺🇸","",trim: true)["🇺🇸"]iex>"🇺🇸"<><<0>><<240,159,135,186,240,159,135,184,0>>Some interesting articles