]> jfr.im git - irc/rqf/shadowircd.git/blob - include/inline/stringops.h
Update omode so that it can set +ah.
[irc/rqf/shadowircd.git] / include / inline / stringops.h
1 /*
2 * charybdis: an advanced ircd.
3 * inline/stringops.h: inlined string operations used in a few places
4 *
5 * Copyright (c) 2005-2008 charybdis development team
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 */
22
23 #ifndef __INLINE_STRINGOPS_H
24 #define __INLINE_STRINGOPS_H
25
26 /*
27 * strip_colour - remove colour codes from a string
28 * -asuffield (?)
29 */
30 static inline char *
31 strip_colour(char *string)
32 {
33 char *c = string;
34 char *c2 = string;
35 char *last_non_space = NULL;
36
37 /* c is source, c2 is target */
38 for(; c && *c; c++)
39 switch (*c)
40 {
41 case 3:
42 if(isdigit(c[1]))
43 {
44 c++;
45 if(isdigit(c[1]))
46 c++;
47 if(c[1] == ',' && isdigit(c[2]))
48 {
49 c += 2;
50 if(isdigit(c[1]))
51 c++;
52 }
53 }
54 break;
55 case 2:
56 case 6:
57 case 7:
58 case 22:
59 case 23:
60 case 27:
61 case 31:
62 break;
63 case 32:
64 *c2++ = *c;
65 break;
66 default:
67 *c2++ = *c;
68 last_non_space = c2;
69 break;
70 }
71
72 *c2 = '\0';
73
74 if(last_non_space)
75 *last_non_space = '\0';
76
77 return string;
78 }
79
80 static inline char *
81 strip_unprintable(char *string)
82 {
83 char *c = string;
84 char *c2 = string;
85 char *last_non_space = NULL;
86
87 /* c is source, c2 is target */
88 for(; c && *c; c++)
89 switch (*c)
90 {
91 case 3:
92 if(isdigit(c[1]))
93 {
94 c++;
95 if(isdigit(c[1]))
96 c++;
97 if(c[1] == ',' && isdigit(c[2]))
98 {
99 c += 2;
100 if(isdigit(c[1]))
101 c++;
102 }
103 }
104 break;
105 case 32:
106 *c2++ = *c;
107 break;
108 default:
109 if (*c < 32)
110 break;
111 *c2++ = *c;
112 last_non_space = c2;
113 break;
114 }
115
116 *c2 = '\0';
117
118 if(last_non_space)
119 *last_non_space = '\0';
120
121 return string;
122 }
123
124 #endif