File Index
Files and directories
Sign in
FILE

string_choices.h

File preview with syntax highlighting.

linux-6.19.14/include/linux/string_choices.h C
 1/* SPDX-License-Identifier: GPL-2.0 */
 2#ifndef _LINUX_STRING_CHOICES_H_
 3#define _LINUX_STRING_CHOICES_H_
 4
 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.
16 */
17
18#include <linux/types.h>
19
20static inline const char *str_assert_deassert(bool v)
21{
22	return v ? "assert" : "deassert";
23}
24#define str_deassert_assert(v)		str_assert_deassert(!(v))
25
26static inline const char *str_enable_disable(bool v)
27{
28	return v ? "enable" : "disable";
29}
30#define str_disable_enable(v)		str_enable_disable(!(v))
31
32static inline const char *str_enabled_disabled(bool v)
33{
34	return v ? "enabled" : "disabled";
35}
36#define str_disabled_enabled(v)		str_enabled_disabled(!(v))
37
38static inline const char *str_hi_lo(bool v)
39{
40	return v ? "hi" : "lo";
41}
42#define str_lo_hi(v)		str_hi_lo(!(v))
43
44static inline const char *str_high_low(bool v)
45{
46	return v ? "high" : "low";
47}
48#define str_low_high(v)		str_high_low(!(v))
49
50static inline const char *str_input_output(bool v)
51{
52	return v ? "input" : "output";
53}
54#define str_output_input(v)	str_input_output(!(v))
55
56static inline const char *str_on_off(bool v)
57{
58	return v ? "on" : "off";
59}
60#define str_off_on(v)		str_on_off(!(v))
61
62static inline const char *str_read_write(bool v)
63{
64	return v ? "read" : "write";
65}
66#define str_write_read(v)		str_read_write(!(v))
67
68static inline const char *str_true_false(bool v)
69{
70	return v ? "true" : "false";
71}
72#define str_false_true(v)		str_true_false(!(v))
73
74static inline const char *str_up_down(bool v)
75{
76	return v ? "up" : "down";
77}
78#define str_down_up(v)		str_up_down(!(v))
79
80static inline const char *str_yes_no(bool v)
81{
82	return v ? "yes" : "no";
83}
84#define str_no_yes(v)		str_yes_no(!(v))
85
86/**
87 * str_plural - Return the simple pluralization based on English counts
88 * @num: Number used for deciding pluralization
89 *
90 * If @num is 1, returns empty string, otherwise returns "s".
91 */
92static inline const char *str_plural(size_t num)
93{
94	return num == 1 ? "" : "s";
95}
96
97#endif
~/ Read-only file preview.