summaryrefslogtreecommitdiff
path: root/src/lib/evil/evil_string.c
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-09-11 16:13:11 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-09-11 16:13:11 +0000
commitcd69ef4c8a66e7155967a8b661a014856979cf31 (patch)
tree4a351ae4a4ca91abf29c85254b85ea8da71f74b0 /src/lib/evil/evil_string.c
parent59a9dfd11860888a35e96dfe51af63cea5cecfe1 (diff)
merge: add evil files
SVN revision: 76464
Diffstat (limited to 'src/lib/evil/evil_string.c')
-rw-r--r--src/lib/evil/evil_string.c128
1 files changed, 128 insertions, 0 deletions
diff --git a/src/lib/evil/evil_string.c b/src/lib/evil/evil_string.c
new file mode 100644
index 0000000..ffbe308
--- /dev/null
+++ b/src/lib/evil/evil_string.c
@@ -0,0 +1,128 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif /* HAVE_CONFIG_H */
4
5#include "Evil.h"
6
7
8#ifdef _WIN32_WCE
9
10/*
11 * Error related functions
12 *
13 */
14
15char *strerror (int errnum __UNUSED__)
16{
17 return "[Windows CE] error\n";
18}
19
20#endif /* _WIN32_WCE */
21
22
23/*
24 * bit related functions
25 *
26 */
27
28int ffs(int i)
29{
30 int size;
31 int x;
32
33 if (!i) return 1;
34
35 /* remove the sign bit */
36 x = i & -i;
37 size = sizeof(int) << 3;
38 for (i = size; i > 0; --i, x <<= 1)
39 if (x & (1 << (size - 1))) return i;
40
41 return x;
42}
43
44
45#ifdef _WIN32_WCE
46
47/*
48 * String manipulation related functions
49 *
50 */
51
52int
53strcoll (const char *s1, const char *s2)
54{
55#ifdef UNICODE
56 wchar_t *ws1;
57 wchar_t *ws2;
58 int res;
59
60 ws1 = evil_char_to_wchar(s1);
61 ws2 = evil_char_to_wchar(s2);
62 res = wcscmp(ws1, ws2);
63 if (ws1) free(ws1);
64 if (ws2) free(ws2);
65
66 return res;
67#else
68 return strcmp(s1, s2);
69#endif /* ! UNICODE */
70}
71
72
73#endif /* _WIN32_WCE */
74
75char *
76strrstr (const char *str, const char *substr)
77{
78 char *it;
79 char *ret = NULL;
80
81 while ((it = strstr(str, substr)))
82 ret = it;
83
84 return ret;
85}
86
87#ifdef _MSC_VER
88
89int strcasecmp(const char *s1, const char *s2)
90{
91 return lstrcmpi(s1, s2);
92}
93
94#endif /* _MSC_VER */
95
96char *strcasestr(const char *haystack, const char *needle)
97{
98 size_t length_needle;
99 size_t length_haystack;
100 size_t i;
101
102 if (!haystack || !needle)
103 return NULL;
104
105 length_needle = strlen(needle);
106 length_haystack = strlen(haystack) - length_needle + 1;
107
108 for (i = 0; i < length_haystack; i++)
109 {
110 size_t j;
111
112 for (j = 0; j < length_needle; j++)
113 {
114 unsigned char c1;
115 unsigned char c2;
116
117 c1 = haystack[i+j];
118 c2 = needle[j];
119 if (toupper(c1) != toupper(c2))
120 goto next;
121 }
122 return (char *) haystack + i;
123 next:
124 ;
125 }
126
127 return NULL;
128}