<commit_before>import os, re, sublime, sublime_plugin, colorsys

#	RGBA	rgba(RRR, GGG, BBB, A.A)
# rgb(50, 150, 200)
# rgba(50, 150, 200, 0.5)
#	ARGB	argb(AAA, RRR, GGG, BBB)
# argb(255, 50, 150, 200)
#	HEX		#RRGGBBAA
# #A98
# #A98F
# #AA9988
# #AA9988FF
#	INT		0xAARRGGBB
# 0x5599FF
# 0xFFAA443F
#	HSLA	hsla(HHH, SSS, LLL, A.A)
# hsl(100, 50, 50)
# hsla(100, 50%, 50%, 0.5)
#	Float Array	[ R, G, B, A ]
# [0.55555, 0.1, 0.8, 0.5]
# {0.55555F, 0.1F, 0.8F, 1F}
#

float_r = '\s*(0(?:\.[0-9]+)?|1(?:\.0+)?)[fF]?\s*'

rgb_regex = re.compile('a?rgba?\( *(\d{1,3}) *, *(\d{1,3}) *, *(\d{1,3}) *(?:, *(\d{0,3}(?:\.\d+)?) *)?\)')
hsl_regex = re.compile('hsla?\( *(\d{1,3}) *, *(\d{1,3})%? *, *(\d{1,3})%? *(?:, *(\d?(?:\.\d+)?) *)?\)')
float_regex = re.compile('(?:\{|\[)'+ float_r +','+ float_r +','+ float_r +'(?:,'+ float_r +')?(?:\}|\])')

class Color():

	r = 0
	g = 0
	b = 0
	a = 255
	valid = True

	def __init__(self, color):
		if color.find("rgb") == 0:
			s = re.search(rgb_regex, color)
			(r, g, b, a) = s.groups()
			self.r = int('0'+ r)
			self.g = int('0'+ g)
			self.b = int('0'+ b)
			if a == None:
				self.a = 255
			else:
				self.a = int(float('0'+ a) * 255)
		elif color.find("argb") == 0:
			s = re.search(rgb_regex, color)
			(a, r, g, b) = s.groups()
			if b == None:
				self.valid = False
			else:
				self.r = int('0'+ r)
				self.g = int('0'+ g)
				self.b = int('0'+ b)
				self.a = int('0'+ a)
		elif color.find("hsl") == 0:
			s = re.search(hsl_regex, color)
			(h, s, l, a) = s.groups()
			rgb = colorsys.hls_to_rgb(float('0'+ h) / 360, float('0'+ s) / 100, float('0'+ l) / 100)
			self.r = int(rgb[0] * 255)
			self.g = int(rgb[1] * 255)
			self.b = int(rgb[2] * 255)
			if a == None:
				self.a = 255
			else:
				self.a = int(float('0'+ a) * 255)
		elif color.find("0x") == 0:
			length = len(color) - 2
			if length == 6:
				(a, r, g, b) = ("00", color[2:4], color[4:6], color[6:8])
			elif length == 8:
				(a, r, g, b) = (color[2:4], color[4:6], color[6:8], color[8:])
			else:
				self.valid = False
				return
			self.r = self._htoi(r)
			self.g = self._htoi(g)
			self.b = self._htoi(b)
			self.a = self._htoi(a)
		elif color.find("#") == 0:
			length = len(color) - 1
			if length == 3 or length == 4:
				if length == 3:<commit_msg>Allow int colors without alpha (mlx)<commit_after>import os, re, sublime, sublime_plugin, colorsys

#	RGBA	rgba(RRR, GGG, BBB, A.A)
# rgb(50, 150, 200)
# rgba(50, 150, 200, 0.5)
#	ARGB	argb(AAA, RRR, GGG, BBB)
# argb(255, 50, 150, 200)
#	HEX		#RRGGBBAA
# #A98
# #A98F
# #AA9988
# #AA9988FF
#	INT		0xAARRGGBB
# 0x5599FF
# 0xFFAA443F
#	HSLA	hsla(HHH, SSS, LLL, A.A)
# hsl(100, 50, 50)
# hsla(100, 50%, 50%, 0.5)
#	Float Array	[ R, G, B, A ]
# [0.55555, 0.1, 0.8, 0.5]
# {0.55555F, 0.1F, 0.8F, 1F}
#

float_r = '\s*(0(?:\.[0-9]+)?|1(?:\.0+)?)[fF]?\s*'

rgb_regex = re.compile('a?rgba?\( *(\d{1,3}) *, *(\d{1,3}) *, *(\d{1,3}) *(?:, *(\d{0,3}(?:\.\d+)?) *)?\)')
hsl_regex = re.compile('hsla?\( *(\d{1,3}) *, *(\d{1,3})%? *, *(\d{1,3})%? *(?:, *(\d?(?:\.\d+)?) *)?\)')
float_regex = re.compile('(?:\{|\[)'+ float_r +','+ float_r +','+ float_r +'(?:,'+ float_r +')?(?:\}|\])')

class Color():

	r = 0
	g = 0
	b = 0
	a = 255
	valid = True

	def __init__(self, color):
		if color.find("rgb") == 0:
			s = re.search(rgb_regex, color)
			(r, g, b, a) = s.groups()
			self.r = int('0'+ r)
			self.g = int('0'+ g)
			self.b = int('0'+ b)
			if a == None:
				self.a = 255
			else:
				self.a = int(float('0'+ a) * 255)
		elif color.find("argb") == 0:
			s = re.search(rgb_regex, color)
			(a, r, g, b) = s.groups()
			if b == None:
				self.valid = False
			else:
				self.r = int('0'+ r)
				self.g = int('0'+ g)
				self.b = int('0'+ b)
				self.a = int('0'+ a)
		elif color.find("hsl") == 0:
			s = re.search(hsl_regex, color)
			(h, s, l, a) = s.groups()
			rgb = colorsys.hls_to_rgb(float('0'+ h) / 360, float('0'+ s) / 100, float('0'+ l) / 100)
			self.r = int(rgb[0] * 255)
			self.g = int(rgb[1] * 255)
			self.b = int(rgb[2] * 255)
			if a == None:
				self.a = 255
			else:
				self.a = int(float('0'+ a) * 255)
		elif color.find("0x") == 0:
			length = len(color) - 2
			if length == 6:
				(a, r, g, b) = ("FF", color[2:4], color[4:6], color[6:8])
			elif length == 8:
				(a, r, g, b) = (color[2:4], color[4:6], color[6:8], color[8:])
			else:
				self.valid = False
				return
			self.r = self._htoi(r)
			self.g = self._htoi(g)
			self.b = self._htoi(b)
			self.a = self._htoi(a)
		elif color.find("#") == 0:
			length = len(color) - 1
			if length == 3 or length == 4:
				if length == 3:
{'fraction_non_alphanumeric': 0.27143170357377766, 'fraction_numerical': 0.08199956149967112, 'mean_word_length': 2.7890365448504983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3922552', 'n_tokens_mistral': 2708, 'n_tokens_neox': 2241, 'n_words': 508}