<div>So you want to find a tuple in a list converted from JSON so the key is binary. And not only that, you want it to be case insensitive! </div><div><br></div><div>Now as far as I found, I'm only now bothering to go back to this code and ask why, there is only string:equal/2 and it doesn't support case insensitive matching. And not only that but string:to_lower/1 only supports lists. So I ended up with a conversion to a list, then to_lower and then back to a binary....</div>
<div><br></div><div>It is too ugly to think it was right... Does anyone know a better way of doing this? I feel I am missing something obvious.</div><div><br></div><div>case_insensitive_binary_string_keyfind(_String, _Pos, []) -> </div>
<div> false;</div><div>case_insensitive_binary_string_keyfind(String, Pos, [H|T]) -> </div><div> case list_to_binary(</div><div> string:to_lower(</div><div> binary_to_list(</div><div> element(Pos, H)))) of</div>
<div> String -></div><div> H;</div><div> _ -></div><div> case_insensitive_binary_string_keyfind(String, Pos, T)</div><div> end.</div><div><br></div>