fehQlibs 26
Qlibs
Loading...
Searching...
No Matches
str.c
Go to the documentation of this file.
1#include "str.h"
2#include "stralloc.h"
3
11unsigned int str_copy(char *s,const char *t)
12{
13 int len;
14
15 len = 0;
16 for (;;) {
17 if (!(*s = *t)) { return len; } ++s; ++t; ++len;
18 if (!(*s = *t)) { return len; } ++s; ++t; ++len;
19 if (!(*s = *t)) { return len; } ++s; ++t; ++len;
20 if (!(*s = *t)) { return len; } ++s; ++t; ++len;
21 }
22}
23
24unsigned int str_copyb(char *s,const char *t,unsigned int max)
25{
26 int len;
27
28 len = 0;
29
30 while (max-- > 0) {
31 if (!(*s = *t)) { return len; } ++s; ++t; ++len;
32 if (!(*s = *t)) { return len; } ++s; ++t; ++len;
33 if (!(*s = *t)) { return len; } ++s; ++t; ++len;
34 if (!(*s = *t)) { return len; } ++s; ++t; ++len;
35 }
36
37 return len;
38}
39
40int str_diff(const char *s,const char *t)
41{
42 char x;
43
44 for (;;) {
45 x = *s; if (x != *t) { break; } if (!x) { break; } ++s; ++t;
46 x = *s; if (x != *t) { break; } if (!x) { break; } ++s; ++t;
47 x = *s; if (x != *t) { break; } if (!x) { break; } ++s; ++t;
48 x = *s; if (x != *t) { break; } if (!x) { break; } ++s; ++t;
49 }
50 return ((int)(unsigned int)(unsigned char) x)
51 - ((int)(unsigned int)(unsigned char) *t);
52}
53
54int str_diffn(const char *s,const char *t,unsigned int len)
55{
56 char x;
57
58 for (;;) {
59 if (!len--) { return 0; } x = *s; if (x != *t) { break; } if (!x) { break; } ++s; ++t;
60 if (!len--) { return 0; } x = *s; if (x != *t) { break; } if (!x) { break; } ++s; ++t;
61 if (!len--) { return 0; } x = *s; if (x != *t) { break; } if (!x) { break; } ++s; ++t;
62 if (!len--) { return 0; } x = *s; if (x != *t) { break; } if (!x) { break; } ++s; ++t;
63 }
64 return ((int)(unsigned int)(unsigned char) x)
65 - ((int)(unsigned int)(unsigned char) *t);
66}
67
68unsigned int str_len(const char *s)
69{
70 const char *t;
71
72 t = s;
73 for (;;) {
74 if (!*t) { return t - s; } ++t;
75 if (!*t) { return t - s; } ++t;
76 if (!*t) { return t - s; } ++t;
77 if (!*t) { return t - s; } ++t;
78 }
79}
80
81unsigned int str_chr(const char *s,int c)
82{
83 char ch;
84 const char *t;
85
86 ch = c;
87 t = s;
88 for (;;) {
89 if (!*t) { break; } if (*t == ch) { break; } ++t;
90 if (!*t) { break; } if (*t == ch) { break; } ++t;
91 if (!*t) { break; } if (*t == ch) { break; } ++t;
92 if (!*t) { break; } if (*t == ch) { break; } ++t;
93 }
94 return t - s;
95}
96
97unsigned int str_rchr(const char *s,int c)
98{
99 char ch;
100 const char *t;
101 const char *u;
102
103 ch = c;
104 t = s;
105 u = 0;
106 for (;;) {
107 if (!*t) { break; } if (*t == ch) { u = t; } ++t;
108 if (!*t) { break; } if (*t == ch) { u = t; } ++t;
109 if (!*t) { break; } if (*t == ch) { u = t; } ++t;
110 if (!*t) { break; } if (*t == ch) { u = t; } ++t;
111 }
112 if (!u) u = t;
113 return u - s;
114}
115
116int str_start(const char *s,const char *t)
117{
118 char x;
119
120 for (;;) {
121 x = *t++; if (!x) return 1; if (x != *s++) return 0;
122 x = *t++; if (!x) return 1; if (x != *s++) return 0;
123 x = *t++; if (!x) return 1; if (x != *s++) return 0;
124 x = *t++; if (!x) return 1; if (x != *s++) return 0;
125 }
126}
127
128char *str_append(char *dest, char const *s)
129{
130 static stralloc sa = {0};
131
132 stralloc_copys(&sa,dest);
133 stralloc_catb(&sa,s,sizeof(s));
134 return sa.s;
135}
unsigned int str_rchr(const char *s, int c)
Definition: str.c:97
char * str_append(char *dest, char const *s)
Definition: str.c:128
unsigned int str_len(const char *s)
Definition: str.c:68
int str_diff(const char *s, const char *t)
Definition: str.c:40
unsigned int str_copyb(char *s, const char *t, unsigned int max)
Definition: str.c:24
int str_diffn(const char *s, const char *t, unsigned int len)
Definition: str.c:54
int str_start(const char *s, const char *t)
Definition: str.c:116
unsigned int str_copy(char *s, const char *t)
Definition: str.c:11
unsigned int str_chr(const char *s, int c)
Definition: str.c:81
int stralloc_catb(stralloc *, const char *, unsigned int)
Definition: stralloc.c:26
int stralloc_copys(stralloc *, const char *)
Definition: stralloc.c:79
char * s
Definition: stralloc.h:18