]>
Commit | Line | Data |
---|---|---|
212380e3 | 1 | /* |
7e8e21a4 WP |
2 | * charybdis: an advanced ircd. |
3 | * inline/stringops.h: inlined string operations used in a few places | |
212380e3 | 4 | * |
7e8e21a4 | 5 | * Copyright (c) 2005-2008 charybdis development team |
212380e3 | 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 | |
212380e3 | 21 | */ |
22 | ||
7e8e21a4 WP |
23 | #ifndef __INLINE_STRINGOPS_H |
24 | #define __INLINE_STRINGOPS_H | |
212380e3 | 25 | |
7e8e21a4 WP |
26 | /* |
27 | * strip_colour - remove colour codes from a string | |
28 | * -asuffield (?) | |
29 | */ | |
30 | static inline char * | |
212380e3 | 31 | strip_colour(char *string) |
32 | { | |
33 | char *c = string; | |
34 | char *c2 = string; | |
35 | char *last_non_space = NULL; | |
7e8e21a4 | 36 | |
212380e3 | 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: | |
6f187f63 | 61 | case 29: |
212380e3 | 62 | case 31: |
63 | break; | |
64 | case 32: | |
65 | *c2++ = *c; | |
66 | break; | |
67 | default: | |
68 | *c2++ = *c; | |
69 | last_non_space = c2; | |
70 | break; | |
71 | } | |
7e8e21a4 | 72 | |
212380e3 | 73 | *c2 = '\0'; |
7e8e21a4 | 74 | |
212380e3 | 75 | if(last_non_space) |
76 | *last_non_space = '\0'; | |
7e8e21a4 | 77 | |
212380e3 | 78 | return string; |
79 | } | |
7e8e21a4 | 80 | |
114406d0 G |
81 | static inline char * |
82 | strip_unprintable(char *string) | |
83 | { | |
84 | char *c = string; | |
85 | char *c2 = string; | |
86 | char *last_non_space = NULL; | |
87 | ||
88 | /* c is source, c2 is target */ | |
89 | for(; c && *c; c++) | |
90 | switch (*c) | |
91 | { | |
92 | case 3: | |
93 | if(isdigit(c[1])) | |
94 | { | |
95 | c++; | |
96 | if(isdigit(c[1])) | |
97 | c++; | |
98 | if(c[1] == ',' && isdigit(c[2])) | |
99 | { | |
100 | c += 2; | |
101 | if(isdigit(c[1])) | |
102 | c++; | |
103 | } | |
104 | } | |
105 | break; | |
106 | case 32: | |
107 | *c2++ = *c; | |
108 | break; | |
109 | default: | |
110 | if (*c < 32) | |
111 | break; | |
112 | *c2++ = *c; | |
113 | last_non_space = c2; | |
114 | break; | |
115 | } | |
116 | ||
117 | *c2 = '\0'; | |
118 | ||
119 | if(last_non_space) | |
120 | *last_non_space = '\0'; | |
121 | ||
122 | return string; | |
123 | } | |
124 | ||
7e8e21a4 | 125 | #endif |