Skip to main content

should_encode_as_blank_when_zero

Function should_encode_as_blank_when_zero 

Source
pub fn should_encode_as_blank_when_zero(value: &str, bwz_encode: bool) -> bool
Expand description

Determine whether a value should be encoded as all spaces under the COBOL BLANK WHEN ZERO clause.

Returns true when bwz_encode is enabled and the string value represents zero (including decimal zeros such as "0.00"). Callers use this check before encoding to decide whether to emit a space-filled field instead of the normal numeric encoding.

§Arguments

  • value - String representation of the numeric value to test
  • bwz_encode - Whether the BLANK WHEN ZERO clause is active for this field

§Returns

true if the field should be encoded as all spaces; false otherwise.

§Examples

use copybook_codec::numeric::should_encode_as_blank_when_zero;

assert!(should_encode_as_blank_when_zero("0", true));
assert!(should_encode_as_blank_when_zero("0.00", true));
assert!(!should_encode_as_blank_when_zero("42", true));
assert!(!should_encode_as_blank_when_zero("0", false)); // BWZ disabled

§See Also