Skip to contentSkip to conversation

lib/string_choices: Add str_true_false()/str_false_true() helper

PATCH Superseded Hongbo Li 2 participants 3 messages Aug 24, 2024 Generic string library

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Hongbo Li

author
#0 lore raw

PATCH v2 1/1 lib/string_choices: Add str_true_false()/str_false_true() helper

Add str_true_false()/str_false_true() helper to return "true" or "false" string literal.

---
v2:
- Squash into a single patch as Andy Shevchenko' suggesstion.

v1:
- https://lore.kernel.org/all/[email protected]/T/

---
 include/linux/string_choices.h | 6 ++++++
 1 file changed, 6 insertions(+)
include/linux/string_choices.h +6 -0
index 1320bcdcb89c..ebcc56b28ede 100644
@@ -48,6 +48,12 @@ static inline const char *str_up_down(bool v)
 }
 #define str_down_up(v)		str_up_down(!(v))
 
+static inline const char *str_true_false(bool v)
+{
+	return v ? "true" : "false";
+}
+#define str_false_true(v)		str_true_false(!(v))
+
 /**
  * str_plural - Return the simple pluralization based on English counts
  * @num: Number used for deciding pluralization
Signature · 1 line
2.34.1
author
#1 lore raw

As discussed in the previous thread, the coccinelle rules and some replacements will be added in the future.

Thanks,
Hongbo

Quoted 32 lines · Hongbo Li

Add str_true_false()/str_false_true() helper to return "true" or "false" string literal.

---
v2:
- Squash into a single patch as Andy Shevchenko' suggesstion.

v1:
- https://lore.kernel.org/all/[email protected]/T/

---
  include/linux/string_choices.h | 6 ++++++
  1 file changed, 6 insertions(+)
include/linux/string_choices.h +6 -0
index 1320bcdcb89c..ebcc56b28ede 100644
@@ -48,6 +48,12 @@ static inline const char *str_up_down(bool v)
  }
  #define str_down_up(v)		str_up_down(!(v))
 
+static inline const char *str_true_false(bool v)
+{
+	return v ? "true" : "false";
+}
+#define str_false_true(v)		str_true_false(!(v))
+
  /**
   * str_plural - Return the simple pluralization based on English counts
   * @num: Number used for deciding pluralization
#2 lore raw
Quoted 2 lines · Hongbo Li

As discussed in the previous thread, the coccinelle rules and some replacements will be added in the future.

Then we have to wait for this one until then. Remember, we can not take functions that no one calls, as they will be noticed and someone will remove them.

Please make a patch series with the function being used, that's the only way we can actually determine if the addition is correct or not.

thanks,

greg k-h