1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
std::vector <unsigned char> _colors (QD * 20);
struct RGB
{
RGB() : R(0), G(0), B(0) { }
unsigned char R, G, B;
};
bool RGB_Exist(char R, char G, char B, char delimiter)
{
return (R == 'R' && G == 'G' && B == 'B' && delimiter == ':');
}
void Formatter(std::string& RGBformat)
{
RGB rgb;
RGBformat.erase(0, 1); //remove the indicator '\r'
for (int i = 0;i < RGBformat.length(); ++i)
{
if (RGBformat[i] == '<')
{
if (RGB_Exist(RGBformat[i + 1], RGBformat[i + 2], RGBformat[i + 3], RGBformat[i + 4]))
{
RGB_Read(RGBformat, i, rgb);
i = 0;
}
}
_colors.push_back(rgb.R); _colors.push_back(rgb.G); _colors.push_back(rgb.B);
_colors.push_back(rgb.R); _colors.push_back(rgb.G); _colors.push_back(rgb.B);
_colors.push_back(rgb.R); _colors.push_back(rgb.G); _colors.push_back(rgb.B);
_colors.push_back(rgb.R); _colors.push_back(rgb.G); _colors.push_back(rgb.B);
}
}
void RGB_Read(std::string& RGBformat, int index, RGB& rgb)
{
int i = index + 5; //we are now next to character ':'
std::string value;
int toNumber;
while (RGBformat[i] != ',')
{
value += RGBformat[i++];
}
++i;
std::stringstream(value) >> toNumber;
rgb.R = toNumber;
value = "";
while (RGBformat[i] != ',')
{
value += RGBformat[i++];
}
++i;
std::stringstream(value) >> toNumber;
value = "";
rgb.G = toNumber;
while (RGBformat[i] != '>')
{
value += RGBformat[i++];
}
++i;
std::stringstream(value) >> toNumber;
value = "";
rgb.B = toNumber;
//I got the right result here which is
//start: <, end: >
printf("start: %c, end: %c\n", RGBformat[index], RGBformat[i]);
//but fail in this one
//this one should erase from '<' until it finds '>'
RGBformat.erase(index, i);
}
|