Hey there. I was recently writing a function to write our who list to an html file and I noticed that the color codes didn't look too darn pretty inside people's titles. So, I wrote a couple of functions that will remove the color codes (\cxx only, I don't use & codes) from any string <= MAX_INPUT_LENGTH. I'm no wiz or anything on string manipulation, so if anyone sees anything wrong with these, gimme a holler. Otherwise, these would probably be usefull elsewhere in code if you want to have player/god manipulated strings that can't contain color. For instance, you don't want to allow color on the gossip channel, simply add remove_color_codes(buf); at the end of the function. Anyhow, here they are. int is_color_code(char *buf, int pos) { char code[3]; strcpy(code, "\\c"); if(buf[pos] == code[0] && buf[pos + 1] == code[1]) { if(buf[pos + 2] >= 48 && buf[pos + 2] <= 50) if(buf[pos + 3] >= 48 && buf[pos + 3] <= 57) return 1; } return 0; } char *remove_color_codes(char *buf) { char new1[MAX_INPUT_LENGTH], new2[MAX_INPUT_LENGTH]; unsigned int i, j; int found = 1; strcpy(new1, buf); strcpy(new2, new1); while(found == 1) { for(i=0;i<strlen(new2);i++) if(is_color_code(new2, i)) for(j=i;j<strlen(new2);j++) new1[j] = new2[j + 4]; found = 0; for(i=0;i<strlen(new1);i++) if(is_color_code(new1, i)) found = 1; strcpy(new2, new1); } return new1; } Chuck Reed +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST