printf: Remove unused 'bprintf'
[drm/drm-misc.git] / include / linux / string_choices.h
blob120ca0f28e9512641d3f142584b7b30640424340
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_STRING_CHOICES_H_
3 #define _LINUX_STRING_CHOICES_H_
5 /*
6 * Here provide a series of helpers in the str_$TRUE_$FALSE format (you can
7 * also expand some helpers as needed), where $TRUE and $FALSE are their
8 * corresponding literal strings. These helpers can be used in the printing
9 * and also in other places where constant strings are required. Using these
10 * helpers offers the following benefits:
11 * 1) Reducing the hardcoding of strings, which makes the code more elegant
12 * through these simple literal-meaning helpers.
13 * 2) Unifying the output, which prevents the same string from being printed
14 * in various forms, such as enable/disable, enabled/disabled, en/dis.
15 * 3) Deduping by the linker, which results in a smaller binary file.
18 #include <linux/types.h>
20 static inline const char *str_enable_disable(bool v)
22 return v ? "enable" : "disable";
24 #define str_disable_enable(v) str_enable_disable(!(v))
26 static inline const char *str_enabled_disabled(bool v)
28 return v ? "enabled" : "disabled";
30 #define str_disabled_enabled(v) str_enabled_disabled(!(v))
32 static inline const char *str_hi_lo(bool v)
34 return v ? "hi" : "lo";
36 #define str_lo_hi(v) str_hi_lo(!(v))
38 static inline const char *str_high_low(bool v)
40 return v ? "high" : "low";
42 #define str_low_high(v) str_high_low(!(v))
44 static inline const char *str_read_write(bool v)
46 return v ? "read" : "write";
48 #define str_write_read(v) str_read_write(!(v))
50 static inline const char *str_on_off(bool v)
52 return v ? "on" : "off";
54 #define str_off_on(v) str_on_off(!(v))
56 static inline const char *str_yes_no(bool v)
58 return v ? "yes" : "no";
60 #define str_no_yes(v) str_yes_no(!(v))
62 static inline const char *str_up_down(bool v)
64 return v ? "up" : "down";
66 #define str_down_up(v) str_up_down(!(v))
68 static inline const char *str_true_false(bool v)
70 return v ? "true" : "false";
72 #define str_false_true(v) str_true_false(!(v))
74 /**
75 * str_plural - Return the simple pluralization based on English counts
76 * @num: Number used for deciding pluralization
78 * If @num is 1, returns empty string, otherwise returns "s".
80 static inline const char *str_plural(size_t num)
82 return num == 1 ? "" : "s";
85 #endif