Selaa lähdekoodia

[char.h] Adding function that work on char

Vinicius Teshima 1 vuosi sitten
vanhempi
sitoutus
e7e2ee5d19
1 muutettua tiedostoa jossa 27 lisäystä ja 0 poistoa
  1. 27 0
      src/char.h

+ 27 - 0
src/char.h

@@ -0,0 +1,27 @@
+#ifndef CHAR_H
+#define CHAR_H
+
+char char_to_upper(char c);
+char char_to_lower(char c);
+
+#if defined(CHAR_IMP) || defined(IMP)
+
+#include <stdint.h>
+
+char
+char_to_upper(char c)
+{
+	int8_t cond = (c >= 'a' && c <= 'z');
+	return (char)(cond * (c - 32) + (!cond) * c);
+}
+
+char
+char_to_lower(char c)
+{
+	int8_t cond = (c >= 'A' && c <= 'Z');
+	return (char)(cond * (c + 32) + (!cond) * c);
+}
+
+#endif /* defined(CHAR_IMP) || defined(IMP) */
+
+#endif