Add to_c_str_opt/with_c_str_opt functions and fix an ICE

Add to_c_str_opt and with_c_str_opt functions to the ToCStr trait. These functions return an Option if the string they are passed contains a null byte, rather than failing the task like to_c_str/with_c_str.

Updated get_item_val in middle/trans/base to use these functions to fix the ICE in issue #16478.

Fixes #16478