]> jfr.im git - solanum.git/blob - include/inline/stringops.h
Add documentation for extensions/filter
[solanum.git] / include / inline / stringops.h
1 /*
2 * Solanum: a slightly 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 and formatting 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 4:
57 case 6:
58 case 7:
59 case 15:
60 case 17:
61 case 22:
62 case 23:
63 case 27:
64 case 29:
65 case 30:
66 case 31:
67 break;
68 case 32:
69 *c2++ = *c;
70 break;
71 default:
72 *c2++ = *c;
73 last_non_space = c2;
74 break;
75 }
76
77 *c2 = '\0';
78
79 if(last_non_space)
80 *last_non_space = '\0';
81
82 return string;
83 }
84
85 static inline char *
86 strip_unprintable(char *string)
87 {
88 char *c = string;
89 char *c2 = string;
90 char *last_non_space = NULL;
91
92 /* c is source, c2 is target */
93 for(; c && *c; c++)
94 switch (*c)
95 {
96 case 3:
97 if(IsDigit(c[1]))
98 {
99 c++;
100 if(IsDigit(c[1]))
101 c++;
102 if(c[1] == ',' && IsDigit(c[2]))
103 {
104 c += 2;
105 if(IsDigit(c[1]))
106 c++;
107 }
108 }
109 break;
110 case 32:
111 *c2++ = *c;
112 break;
113 default:
114 if ((unsigned char)*c < 32)
115 break;
116 *c2++ = *c;
117 last_non_space = c2;
118 break;
119 }
120
121 *c2 = '\0';
122
123 if(last_non_space)
124 *last_non_space = '\0';
125
126 return string;
127 }
128
129 #endif