Skip to content

Add cast modifier for boolean values#36

Open
lucidstack wants to merge 2 commits into
kbrw:masterfrom
lucidstack:add-boolean-cast
Open

Add cast modifier for boolean values#36
lucidstack wants to merge 2 commits into
kbrw:masterfrom
lucidstack:add-boolean-cast

Conversation

@lucidstack

Copy link
Copy Markdown

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! 👋

@kagux

kagux commented Nov 21, 2016

Copy link
Copy Markdown

Hi,

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

@lucidstack

Copy link
Copy Markdown
Author

@awetzel any update on this?

@aeden

aeden commented Dec 29, 2017

Copy link
Copy Markdown
Collaborator

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

@doughsay

Copy link
Copy Markdown

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?

@chulkilee

chulkilee commented Jun 8, 2018

Copy link
Copy Markdown

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants