Hey,
Here is a patch that format a bit ecore_str.c and Ecore_Str.h, and that
adds 2 functions: ecore_str_has_prefix and ecore_str_has suffix. These
functions might be useful when dealing with paths, file names, theme
path, or mime types.
May I commit it ?
regards
Vincent
? ecore_str.diff
Index: Ecore_Str.h
===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore/Ecore_Str.h,v
retrieving revision 1.2
diff -u -r1.2 Ecore_Str.h
--- Ecore_Str.h 10 Jan 2007 11:33:33 -0000 1.2
+++ Ecore_Str.h 24 Jan 2007 05:24:12 -0000
@@ -38,10 +38,17 @@
# endif
# endif
- /* strlcpy implementation for libc's lacking it */
- EAPI size_t ecore_strlcpy(char *dst, const char *src, size_t siz);
+
+/* strlcpy implementation for libc's lacking it */
+EAPI size_t ecore_strlcpy(char *dst, const char *src, size_t siz);
+
+EAPI int ecore_str_has_prefix(const char *str, const char *prefix);
+
+EAPI int ecore_str_has_suffix(const char *str, const char *suffix);
+
#ifdef __cplusplus
}
#endif
+
#endif /* _ECORE_STR_H */
Index: ecore_str.c
===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore/ecore_str.c,v
retrieving revision 1.1
diff -u -r1.1 ecore_str.c
--- ecore_str.c 10 Jan 2007 11:28:41 -0000 1.1
+++ ecore_str.c 24 Jan 2007 05:24:12 -0000
@@ -29,28 +29,65 @@
ecore_strlcpy(char *dst, const char *src, size_t siz)
{
#ifdef HAVE_STRLCPY
- return strlcpy(dst, src, siz);
+ return strlcpy(dst, src, siz);
#else
- char *d = dst;
- const char *s = src;
- size_t n = siz;
-
- /* Copy as many bytes as will fit */
- if (n != 0) {
- while (--n != 0) {
- if ((*d++ = *s++) == '\0')
- break;
- }
- }
-
- /* Not enough room in dst, add NUL and traverse rest of src */
- if (n == 0) {
- if (siz != 0)
- *d = '\0'; /* NUL-terminate dst */
- while (*s++)
- ;
- }
+ char *d = dst;
+ const char *s = src;
+ size_t n = siz;
- return(s - src - 1); /* count does not include NUL */
+ /* Copy as many bytes as will fit */
+ if (n != 0)
+ {
+ while (--n != 0)
+ {
+ if ((*d++ = *s++) == '\0')
+ break;
+ }
+ }
+
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0)
+ {
+ if (siz != 0)
+ *d = '\0'; /* NUL-terminate dst */
+ while (*s++)
+ ;
+ }
+
+ return(s - src - 1); /* count does not include NUL */
#endif
+}
+
+int
+ecore_str_has_prefix(const char *str, const char *prefix)
+{
+ int str_len;
+ int prefix_len;
+
+ if (!str || !prefix)
+ return 0;
+
+ str_len = strlen(str);
+ prefix_len = strlen(prefix);
+ if (prefix_len > str_len)
+ return 0;
+
+ return (strncmp(str, prefix, prefix_len) == 0);
+}
+
+int
+ecore_str_has_suffix(const char *str, const char *suffix)
+{
+ int str_len;
+ int suffix_len;
+
+ if (!str || !suffix)
+ return 0;
+
+ str_len = strlen(str);
+ suffix_len = strlen(suffix);
+ if (suffix_len > str_len)
+ return 0;
+
+ return (strncmp(str + str_len - suffix_len, suffix, suffix_len) == 0);
}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel