xref: /linux-6.15/include/linux/string_choices.h (revision c2708ba9)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_STRING_CHOICES_H_
3 #define _LINUX_STRING_CHOICES_H_
4 
5 #include <linux/types.h>
6 
7 static inline const char *str_enable_disable(bool v)
8 {
9 	return v ? "enable" : "disable";
10 }
11 #define str_disable_enable(v)		str_enable_disable(!(v))
12 
13 static inline const char *str_enabled_disabled(bool v)
14 {
15 	return v ? "enabled" : "disabled";
16 }
17 #define str_disabled_enabled(v)		str_enabled_disabled(!(v))
18 
19 static inline const char *str_hi_lo(bool v)
20 {
21 	return v ? "hi" : "lo";
22 }
23 #define str_lo_hi(v)		str_hi_lo(!(v))
24 
25 static inline const char *str_high_low(bool v)
26 {
27 	return v ? "high" : "low";
28 }
29 #define str_low_high(v)		str_high_low(!(v))
30 
31 static inline const char *str_read_write(bool v)
32 {
33 	return v ? "read" : "write";
34 }
35 #define str_write_read(v)		str_read_write(!(v))
36 
37 static inline const char *str_on_off(bool v)
38 {
39 	return v ? "on" : "off";
40 }
41 #define str_off_on(v)		str_on_off(!(v))
42 
43 static inline const char *str_yes_no(bool v)
44 {
45 	return v ? "yes" : "no";
46 }
47 #define str_no_yes(v)		str_yes_no(!(v))
48 
49 static inline const char *str_up_down(bool v)
50 {
51 	return v ? "up" : "down";
52 }
53 #define str_down_up(v)		str_up_down(!(v))
54 
55 static inline const char *str_true_false(bool v)
56 {
57 	return v ? "true" : "false";
58 }
59 #define str_false_true(v)		str_true_false(!(v))
60 
61 /**
62  * str_plural - Return the simple pluralization based on English counts
63  * @num: Number used for deciding pluralization
64  *
65  * If @num is 1, returns empty string, otherwise returns "s".
66  */
67 static inline const char *str_plural(size_t num)
68 {
69 	return num == 1 ? "" : "s";
70 }
71 
72 #endif
73