]>
Commit | Line | Data |
---|---|---|
212380e3 | 1 | /* |
a6f63a82 | 2 | * Solanum: a slightly advanced ircd |
ab428518 | 3 | * inline/stringops.h: inlined string operations used in a few places |
212380e3 | 4 | * |
ab428518 | 5 | * Copyright (c) 2005-2008 charybdis development team |
212380e3 AC |
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 AC |
21 | */ |
22 | ||
ab428518 AC |
23 | #ifndef __INLINE_STRINGOPS_H |
24 | #define __INLINE_STRINGOPS_H | |
212380e3 | 25 | |
ab428518 AC |
26 | /* |
27 | * strip_colour - remove colour codes from a string | |
28 | * -asuffield (?) | |
29 | */ | |
30 | static inline char * | |
212380e3 AC |
31 | strip_colour(char *string) |
32 | { | |
33 | char *c = string; | |
34 | char *c2 = string; | |
35 | char *last_non_space = NULL; | |
ab428518 | 36 | |
212380e3 AC |
37 | /* c is source, c2 is target */ |
38 | for(; c && *c; c++) | |
39 | switch (*c) | |
40 | { | |
41 | case 3: | |
57b1cd5f | 42 | if(IsDigit(c[1])) |
212380e3 AC |
43 | { |
44 | c++; | |
57b1cd5f | 45 | if(IsDigit(c[1])) |
212380e3 | 46 | c++; |
57b1cd5f | 47 | if(c[1] == ',' && IsDigit(c[2])) |
212380e3 AC |
48 | { |
49 | c += 2; | |
57b1cd5f | 50 | if(IsDigit(c[1])) |
212380e3 AC |
51 | c++; |
52 | } | |
53 | } | |
54 | break; | |
55 | case 2: | |
aba43ba8 | 56 | case 4: |
212380e3 AC |
57 | case 6: |
58 | case 7: | |
bd96349c | 59 | case 15: |
212380e3 AC |
60 | case 22: |
61 | case 23: | |
62 | case 27: | |
545f0a0f | 63 | case 29: |
212380e3 AC |
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 | } | |
ab428518 | 74 | |
212380e3 | 75 | *c2 = '\0'; |
ab428518 | 76 | |
212380e3 AC |
77 | if(last_non_space) |
78 | *last_non_space = '\0'; | |
ab428518 | 79 | |
212380e3 AC |
80 | return string; |
81 | } | |
ab428518 | 82 | |
87d38e8c BG |
83 | static inline char * |
84 | strip_unprintable(char *string) | |
85 | { | |
12b3a184 JK |
86 | char *c = string; |
87 | char *c2 = string; | |
88 | char *last_non_space = NULL; | |
87d38e8c BG |
89 | |
90 | /* c is source, c2 is target */ | |
91 | for(; c && *c; c++) | |
92 | switch (*c) | |
93 | { | |
94 | case 3: | |
57b1cd5f | 95 | if(IsDigit(c[1])) |
87d38e8c BG |
96 | { |
97 | c++; | |
57b1cd5f | 98 | if(IsDigit(c[1])) |
87d38e8c | 99 | c++; |
57b1cd5f | 100 | if(c[1] == ',' && IsDigit(c[2])) |
87d38e8c BG |
101 | { |
102 | c += 2; | |
57b1cd5f | 103 | if(IsDigit(c[1])) |
87d38e8c BG |
104 | c++; |
105 | } | |
106 | } | |
107 | break; | |
108 | case 32: | |
109 | *c2++ = *c; | |
110 | break; | |
111 | default: | |
12b3a184 | 112 | if ((unsigned char)*c < 32) |
87d38e8c BG |
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 | ||
ab428518 | 127 | #endif |