Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static struct _hex
- {
- unsigned int r;
- unsigned int g;
- unsigned int b;
- unsigned int a;
- _hex() {};
- _hex(const char* ch)
- {
- parse(ch);
- };
- unsigned int getHex(char _ch)
- {
- unsigned int v = 0;
- switch(_ch)
- {
- case '0': v=0; break;
- case '1': v=1; break;
- case '2': v=2; break;
- case '3': v=3; break;
- case '4': v=4; break;
- case '5': v=5; break;
- case '6': v=6; break;
- case '7': v=7; break;
- case '8': v=8; break;
- case '9': v=9; break;
- case 'a': case 'A': v=10; break;
- case 'b': case 'B': v=11; break;
- case 'c': case 'C': v=12; break;
- case 'd': case 'D': v=13; break;
- case 'e': case 'E': v=14; break;
- case 'f': case 'F': v=15; break;
- }
- return v;
- };
- void parse (const char* _chb)
- {
- char* _ch = (char*) _chb;
- bool simple = false;
- if (*_ch=='#') _ch++;
- int len = strlen(_ch);
- if (len<5) simple = true;
- unsigned int v = 0;
- v = getHex( *_ch++ );
- if (simple) v = v | v*16; else v = v*16 | getHex(*_ch++);
- r = v;
- v = getHex( *_ch++ );
- if (simple) v = v | v*16; else v = v*16 | getHex(*_ch++);
- g = v;
- v = getHex( *_ch++ );
- if (simple) v = v | v*16; else v = v*16 | getHex(*_ch++);
- b = v;
- v = getHex( *_ch++ );
- if (simple) v = v | v*16; else v = v*16 | getHex(*_ch++);
- a = v;
- if (len<8 || simple)
- if (len<4)
- a = 255;
- };
- } hex( htmlCor.c_str() );
Advertisement
Add Comment
Please, Sign In to add comment