simplify include
[apps/madmutt.git] / lib-lib / str.h
index 1beac83..86fd758 100644 (file)
@@ -94,6 +94,16 @@ extern char const __m_b36chars_upper[36];
 /* conversions                                                              */
 /****************************************************************************/
 
+/** \brief Converts an octal digit into an int.
+ * \param[in]  c    the octal char
+ * \return
+ *   - 0–7 if c is a valid octal digit,
+ *   - -1 on error.
+ */
+static inline int octval(int c) {
+    return !(c & ~127) && __m_strdigits[c] < 7 ? __m_strdigits[c] : -1;
+}
+
 /** \brief Converts an hexadecimal digit into an int.
  * \param[in]  c    the hexadecimal char
  * \return
@@ -199,6 +209,28 @@ ssize_t m_strwidth(const char *s);
 /* comparisons                                                              */
 /****************************************************************************/
 
+/** \brief Tells whether s begins with p.
+ *
+ * \param[in]  s     the input string
+ * \param[in]  p     the prefix
+ * \param[out] pp    position in s
+ *
+ * \return 1 if a match is found, 0 otherwise.
+ */
+static inline int m_strstart(const char *s, const char *p, const char **pp)
+{
+    if (!s)
+        return 0;
+
+    while (*p) {
+        if (*s++ != *p++)
+            return 0;
+    }
+    if (pp)
+        *pp = s;
+    return 1;
+}
+
 /** \brief \c NULL resistant strcmp.
  * \param[in]  a     the first string.
  * \param[in]  b     the second string.