+/** \brief Convert ascii digits into ints.
+ *
+ * Convert ascii digits into its integer value in base 36.
+ * Non convertible values are converted to 255.
+ *
+ * Translating a digit \c c into its numerical value in base \c x is just doing:
+ * \code
+ * return !(c & ~127) && __m_strdigits[c] < x ? __m_strdigits[c] : -1;
+ * \endcode
+ */
+extern unsigned char const __m_strdigits[128];
+/** \brief Convert an ascii base64 digit into ints.
+ *
+ * Convert an a char base64 digit into its int value.
+ * Used by base64val(). Unlike #__m_strdigits, the invalid values are set to
+ * -1 instead of 255.
+ */
+extern signed char const __m_b64digits[128];
+
+/** \brief Convert ints from 0–64 into the corresponding base64 digit. */
+extern char const __m_b64chars[64];
+/** \brief Convert ints from 0–36 into a base36 lowercase digit. */
+extern char const __m_b36chars_lower[36];
+/** \brief Convert ints from 0–36 into a base36 uppercase digit. */
+extern char const __m_b36chars_upper[36];
+
+/****************************************************************************/
+/* conversions */
+/****************************************************************************/
+
+/** \brief Converts an hexadecimal digit into an int.
+ * \param[in] c the hexadecimal char
+ * \return
+ * - 0–15 if c is a valid hexadecimal digit,
+ * - -1 on error.
+ */
+static inline int hexval(int c) {
+ return !(c & ~127) && __m_strdigits[c] < 16 ? __m_strdigits[c] : -1;
+}
+
+/** \brief Converts a base64 digit into an int.
+ * \param[in] c the base64 char
+ * \return
+ * - 0–15 if c is a valid base64 digit,
+ * - -1 on error.
+ */
+static inline int base64val(int c) {
+ return (c & ~127) ? -1 : __m_b64digits[c];
+}
+
+/** \brief Converts a string to lowercase.
+ * \param[in] p the string, shall not be \c NULL.
+ * \return a pointer to the terminating \c \\0.
+ */
+__attribute__((nonnull(1)))
+static inline char *m_strtolower(char *p) {
+ for (; *p; p++)
+ *p = tolower((unsigned char)*p);
+ return p;
+}
+
+/** \brief Converts a lower case ascii char to upper case.
+ * \param[in] c the character.
+ * \return the upper case character.
+ */
+static inline int ascii_toupper(int c) {
+ if ('a' <= c && c <= 'z')
+ return c & ~32;
+
+ return c;
+}
+
+/** \brief Converts a upper case ascii char to lower case.
+ * \param[in] c the character.
+ * \return the lower case character.
+ */
+static inline int ascii_tolower(int c) {
+ if ('A' <= c && c <= 'Z')
+ return c | 32;
+
+ return c;
+}
+
+/****************************************************************************/
+/* length related */
+/****************************************************************************/
+
+/** \brief Short hand to test if a string is empty or not.
+ * \param[in] s the string.
+ * \return \c true iff s is an empty string.
+ */
+static inline int m_strisempty(const char *s) {
+ return !s || !*s;
+}
+
+/** \brief \c NULL resistant strlen.
+ *
+ * Unlinke it's libc sibling, m_strlen returns a ssize_t, and supports its
+ * argument beeing NULL.
+ *
+ * \param[in] s the string.
+ * \return the string length (or 0 if \c s is \c NULL).
+ */