MCPcopy Create free account
hub / github.com/apache/arrow-rs / cast_single_string_to_boolean

Function cast_single_string_to_boolean

arrow-cast/src/cast/string.rs:413–427  ·  view source on GitHub ↗
(
    value: &str,
    cast_options: &CastOptions,
)

Source from the content-addressed store, hash-verified

411
412#[inline]
413fn cast_single_string_to_boolean(
414 value: &str,
415 cast_options: &CastOptions,
416) -> Result<Option<bool>, ArrowError> {
417 match value.to_ascii_lowercase().trim() {
418 "t" | "tr" | "tru" | "true" | "y" | "ye" | "yes" | "on" | "1" => Ok(Some(true)),
419 "f" | "fa" | "fal" | "fals" | "false" | "n" | "no" | "of" | "off" | "0" => Ok(Some(false)),
420 invalid_value => match cast_options.safe {
421 true => Ok(None),
422 false => Err(ArrowError::CastError(format!(
423 "Cannot cast value '{invalid_value}' to value of Boolean type",
424 ))),
425 },
426 }
427}
428
429/// Cast a single string to boolean with default cast option(safe=true).
430pub fn cast_single_string_to_boolean_default(value: &str) -> Option<bool> {

Callers 2

cast_string_to_booleanFunction · 0.85

Calls 1

trimMethod · 0.80

Tested by

no test coverage detected