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