+EAPI Eina_Error eina_error_find(const char *msg)
authordiscomfitor <discomfitor@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 19 Mar 2011 00:07:23 +0000 (00:07 +0000)
committerdiscomfitor <discomfitor@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 19 Mar 2011 00:07:23 +0000 (00:07 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@57863 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

ChangeLog
src/include/eina_error.h
src/lib/eina_error.c

index 831d360..27d46b1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -36,3 +36,4 @@
 2011-03-18  Mike Blumenkrantz
 
         * Use stringshare for eina_error messages
+        * add eina_error_find to match an error message with its Eina_Error
index 1e4e5a4..3e43112 100644 (file)
@@ -54,6 +54,7 @@ EAPI Eina_Bool   eina_error_msg_modify(Eina_Error  error,
 EAPI Eina_Error  eina_error_get(void);
 EAPI void        eina_error_set(Eina_Error err);
 EAPI const char *eina_error_msg_get(Eina_Error error) EINA_PURE;
+EAPI Eina_Error  eina_error_find(const char *msg) EINA_ARG_NONNULL(1) EINA_PURE;
 
 /**
  * @}
index ff47405..34a85a5 100644 (file)
@@ -460,5 +460,34 @@ eina_error_set(Eina_Error err)
 }
 
 /**
+ * @brief Find the #Eina_Error corresponding to a message string
+ * @param msg The error message string to match (NOT #NULL)
+ * @return The #Eina_Error matching @p msg, or 0 on failure
+ * This function attempts to match @p msg with its corresponding #Eina_Error value.
+ * If no such value is found, 0 is returned.
+ */
+EAPI Eina_Error
+eina_error_find(const char *msg)
+{
+   size_t i;
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(msg, 0);
+
+   for (i = 0; i < _eina_errors_count; i++)
+     {
+        if (_eina_errors[i].string_allocated)
+          {
+             if (_eina_errors[i].string == msg)
+               return i;
+          }
+        else
+          {
+             if (!strcmp(_eina_errors[i].string, msg))
+               return i;
+          }
+     }
+   return 0;
+}
+/**
  * @}
  */