<commit_before>#include "Color.h"

using namespace canvas;

static int get_xdigit(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  } else if (c >= 'A' && c <= 'F') {
    return c - 'A' + 10;
  } else if (c >= 'a' && c <= 'f') {
    return c - 'a' + 10;
  } else {
    return 0;
  }
}

Color::Color(const std::string & s) {
  red = green = blue = 0;
  setValue(s);
}

Color & operator=(const std::string & s) {
  setValue(s);
}

void
Color::setValue(const std::string & s) {
  if (s == "black") {
    red = green = blue = 0;
  } else if (s == "white") {
    red = green = blue = 255;
  } else {
    unsigned int pos = 0;
    if (s.size() && s[0] == '#') pos++;
    if (s.size() >= pos + 6) {
      red = get_xdigit(s[pos]) * 16 + get_xdigit(s[pos+1]);
      green = get_xdigit(s[pos+2]) * 16 + get_xdigit(s[pos+3]);
      blue = get_xdigit(s[pos+4]) * 16 + get_xdigit(s[pos+5]);
    } else if (s.size() >= pos + 3) {
      red = get_xdigit(s[pos]);
      green = get_xdigit(s[pos+1]);
      blue = get_xdigit(s[pos+2]);
      red = red * 16 + red;
      green = green * 16 + green;
      blue = blue * 16 + blue;
    } else {
      red = green = blue = 0;
    }
  }
}
<commit_msg>fix assignment operator<commit_after>#include "Color.h"

using namespace canvas;

static int get_xdigit(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  } else if (c >= 'A' && c <= 'F') {
    return c - 'A' + 10;
  } else if (c >= 'a' && c <= 'f') {
    return c - 'a' + 10;
  } else {
    return 0;
  }
}

Color::Color(const std::string & s) {
  red = green = blue = 0;
  setValue(s);
}

Color &
Color::operator=(const std::string & s) {
  setValue(s);
  return *this;
}

void
Color::setValue(const std::string & s) {
  if (s == "black") {
    red = green = blue = 0;
  } else if (s == "white") {
    red = green = blue = 255;
  } else {
    unsigned int pos = 0;
    if (s.size() && s[0] == '#') pos++;
    if (s.size() >= pos + 6) {
      red = get_xdigit(s[pos]) * 16 + get_xdigit(s[pos+1]);
      green = get_xdigit(s[pos+2]) * 16 + get_xdigit(s[pos+3]);
      blue = get_xdigit(s[pos+4]) * 16 + get_xdigit(s[pos+5]);
    } else if (s.size() >= pos + 3) {
      red = get_xdigit(s[pos]);
      green = get_xdigit(s[pos+1]);
      blue = get_xdigit(s[pos+2]);
      red = red * 16 + red;
      green = green * 16 + green;
      blue = blue * 16 + blue;
    } else {
      red = green = blue = 0;
    }
  }
}

{'fraction_non_alphanumeric': 0.21017790649565576, 'fraction_numerical': 0.03061646669424907, 'mean_word_length': 2.3443983402489628, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1944875', 'n_tokens_mistral': 1060, 'n_tokens_neox': 989, 'n_words': 254}