Created
February 28, 2016 20:41
-
-
Save duper/ac2c67cdc5e7be1ab9c8 to your computer and use it in GitHub Desktop.
Former inspircd/src/users.cpp code for ANSI coloring irc.security.chat PDU's (now replaced with much better syntax)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<ctime> | |
using namespace std; | |
/* | |
using clock() here precludes the need for any pseudo-random number generation | |
implementation which would take up tons of room.. get_text_color also makes a | |
nice anonymous function if C++11 funcptr lambda closure call syntax can be used | |
*/ | |
static inline unsigned int get_text_color(void) { | |
return (unsigned int)(2 + clock() % 13); | |
} | |
static std::string itoa(signed int n, const unsigned int base) { | |
std::string buf; | |
std::div_t dv; | |
dv.quot = n; | |
do { | |
dv = std::div(dv.quot, base); | |
buf += "0123456789abcdef"[std::abs(dv.rem)]; | |
} while(dv.quot); | |
if(n<0) | |
buf += '-'; | |
std::string aret(buf.rbegin(), buf.rend()); | |
return aret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment