]> jfr.im git - solanum.git/blobdiff - include/inline/stringops.h
Remove Windows support
[solanum.git] / include / inline / stringops.h
index a809e75ad11e6bce90999d6c849423e984705258..6959a1a72f6320a9fd39d2a9bc96c867ef10000a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  charybdis: an advanced ircd.
+ *  Solanum: a slightly advanced ircd
  *  inline/stringops.h: inlined string operations used in a few places
  *
  *  Copyright (c) 2005-2008 charybdis development team
@@ -39,22 +39,24 @@ strip_colour(char *string)
                switch (*c)
                {
                case 3:
-                       if(isdigit(c[1]))
+                       if(IsDigit(c[1]))
                        {
                                c++;
-                               if(isdigit(c[1]))
+                               if(IsDigit(c[1]))
                                        c++;
-                               if(c[1] == ',' && isdigit(c[2]))
+                               if(c[1] == ',' && IsDigit(c[2]))
                                {
                                        c += 2;
-                                       if(isdigit(c[1]))
+                                       if(IsDigit(c[1]))
                                                c++;
                                }
                        }
                        break;
                case 2:
+               case 4:
                case 6:
                case 7:
+               case 15:
                case 22:
                case 23:
                case 27:
@@ -78,4 +80,48 @@ strip_colour(char *string)
        return string;
 }
 
+static inline char *
+strip_unprintable(char *string)
+{
+       char *c = string;
+       char *c2 = string;
+       char *last_non_space = NULL;
+
+       /* c is source, c2 is target */
+       for(; c && *c; c++)
+               switch (*c)
+               {
+               case 3:
+                       if(IsDigit(c[1]))
+                       {
+                               c++;
+                               if(IsDigit(c[1]))
+                                       c++;
+                               if(c[1] == ',' && IsDigit(c[2]))
+                               {
+                                       c += 2;
+                                       if(IsDigit(c[1]))
+                                               c++;
+                               }
+                       }
+                       break;
+               case 32:
+                       *c2++ = *c;
+                       break;
+               default:
+                       if ((unsigned char)*c < 32)
+                               break;
+                       *c2++ = *c;
+                       last_non_space = c2;
+                       break;
+               }
+
+       *c2 = '\0';
+
+       if(last_non_space)
+               *last_non_space = '\0';
+
+       return string;
+}
+
 #endif