Function malachite_base::chars::char_is_graphic

source ·
pub fn char_is_graphic(c: char) -> bool
Expand description

Determines whether a char is graphic.

There is an official Unicode definition of graphic character, but that definition is not followed here. In Malachite, a char is considered graphic if it is ASCII and not a C0 control, or non-ASCII and its debug string does not begin with a backslash. This function can be used as a guide to whether a char can be displayed on a screen without resorting to some sort of escape sequence. Of course, many typefaces will not be able to render many graphic chars.

The ASCII space ' ' is the only graphic whitespace char.

§Worst-case complexity

Constant time and additional memory.

§Examples

use malachite_base::chars::char_is_graphic;

assert_eq!(char_is_graphic('a'), true);
assert_eq!(char_is_graphic(' '), true);
assert_eq!(char_is_graphic('\n'), false);
assert_eq!(char_is_graphic('ñ'), true);
assert_eq!(char_is_graphic('\u{5f771}'), false);