[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs cutils.c cutils.h
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs cutils.c cutils.h |
Date: |
Mon, 11 Dec 2006 23:03:22 +0000 |
CVSROOT: /cvsroot/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 06/12/11 23:03:21
Modified files:
. : cutils.c cutils.h
Log message:
changed stristart to ignore space, - and _
addded stricmp: same as strcasecmp, and ignore , - and _
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/cutils.c?cvsroot=qemacs&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/qemacs/cutils.h?cvsroot=qemacs&r1=1.5&r2=1.6
Patches:
Index: cutils.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/cutils.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- cutils.c 9 Dec 2006 19:02:07 -0000 1.5
+++ cutils.c 11 Dec 2006 23:03:21 -0000 1.6
@@ -67,9 +67,10 @@
#endif
/**
- * Return TRUE if val is a prefix of str (case independent). If it
- * returns TRUE, ptr is set to the next character in 'str' after the
- * prefix.
+ * Return TRUE if val is a prefix of str (case independent).
+ * If it returns TRUE, ptr is set to the next character in 'str' after
+ * the prefix.
+ * Spaces, dashes and underscores are also ignored in this comparison.
*
* @param str input string
* @param val prefix to test
@@ -81,8 +82,19 @@
p = str;
q = val;
while (*q != '\0') {
- if (toupper(*(const unsigned char *)p) != toupper(*(const unsigned
char *)q))
+ if (toupper(*(const unsigned char *)p) !=
+ toupper(*(const unsigned char *)q))
+ {
+ if (*p == '-' || *p == '_' || *p == ' ') {
+ p++;
+ continue;
+ }
+ if (*q == '-' || *q == '_' || *q == ' ') {
+ q++;
+ continue;
+ }
return 0;
+ }
p++;
q++;
}
@@ -92,6 +104,42 @@
}
/**
+ * Compare strings str1 and str2 case independently.
+ * Spaces, dashes and underscores are also ignored in this comparison.
+ *
+ * @param str1 input string 1 (left operand)
+ * @param str2 input string 2 (right operand)
+ * @return -1, 0, +1 reflecting the sign of str1 <=> str2
+ */
+int stricmp(const char *str1, const char *str2)
+{
+ const char *p, *q;
+ p = str1;
+ q = str2;
+ for (;;) {
+ if (toupper(*(const unsigned char *)p) !=
+ toupper(*(const unsigned char *)q))
+ {
+ if (*p == '-' || *p == '_' || *p == ' ') {
+ p++;
+ continue;
+ }
+ if (*q == '-' || *q == '_' || *q == ' ') {
+ q++;
+ continue;
+ }
+ return (toupper(*(const unsigned char *)p) <
+ toupper(*(const unsigned char *)q)) ? -1 : +1;
+ }
+ if (!*p)
+ break;
+ p++;
+ q++;
+ }
+ return 0;
+}
+
+/**
* Copy the string str to buf. If str length is bigger than buf_size -
* 1 then it is clamped to buf_size - 1.
* NOTE: this function does what strncpy should have done to be
Index: cutils.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/cutils.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- cutils.h 27 Apr 2006 15:20:12 -0000 1.5
+++ cutils.h 11 Dec 2006 23:03:21 -0000 1.6
@@ -5,6 +5,7 @@
int strstart(const char *str, const char *val, const char **ptr);
int stristart(const char *str, const char *val, const char **ptr);
+int stricmp(const char *str1, const char *str2);
void pstrcpy(char *buf, int buf_size, const char *str);
char *pstrcat(char *buf, int buf_size, const char *s);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemacs-commit] qemacs cutils.c cutils.h,
Charlie Gordon <=