sweet_xml icon indicating copy to clipboard operation
sweet_xml copied to clipboard

Add cast modifier for boolean values

Open lucidstack opened this issue 8 years ago • 5 comments

Hi there! Thank you for making sweet_xml, it works amazingly well. 😀

While parsing an XML with some boolean values, I realised that boolean values are actually standardised in the XML Schema specification, with values true and false (and non-canonically 0 and 1).

I think having a b modifier for the ~x sigil would be a nice addition! I have included a test case for casting with b, and checking for the sigil with b, bl, and lb

Please let me know what you think, and if I need to make any additional changes!

Thanks again! 👋

lucidstack avatar Sep 30 '16 19:09 lucidstack

Hi,

This would be a very helpful feature to have. Any reason this wasn't merged?

kagux avatar Nov 21 '16 09:11 kagux

@awetzel any update on this?

lucidstack avatar Nov 21 '16 15:11 lucidstack

@lucidstack If you can rebase and fix the conflicts, I can handle the merge.

aeden avatar Dec 29 '17 17:12 aeden

Hey there, I need this feature for a project I'm trying to use sweet_xml for. Can we get the conflicts fixed and get this merged?

doughsay avatar Mar 13 '18 23:03 doughsay

BTW you can do this using transform_by/2

 ~x"./first/text()" |> transform_to_boolean()

defp transform_to_boolean(arg) do
  transform_by(arg, fn
    'false' -> false
    'true' -> true
    "" -> nil
  end)
end

chulkilee avatar Jun 08 '18 08:06 chulkilee