Esempio n. 1
0
CMString WCPattern::parseHex()
{
#define to_low(x)   (((x) >= 'A' && (x) <= 'Z') ? ((x) - 'A' + 'a') : (x))
#define is_dig(x)   ((x) >= '0' && (x) <= '9')
#define is_hex(x)   (is_dig(x) || (to_low(x) >= 'a' && to_low(x) <= 'f'))
#define to_int(x)   ((is_dig(x)) ? ((x) - '0') : (to_low(x) - 'a' + 10))

	int ci = curInd;
	wchar_t ch1 = (ci + 0 < pattern.GetLength()) ? pattern[ci + 0] : USHRT_MAX;
	wchar_t ch2 = (ci + 1 < pattern.GetLength()) ? pattern[ci + 1] : USHRT_MAX;
	wchar_t ch3 = (ci + 2 < pattern.GetLength()) ? pattern[ci + 2] : USHRT_MAX;
	wchar_t ch4 = (ci + 3 < pattern.GetLength()) ? pattern[ci + 3] : USHRT_MAX;
	CMString s = L" ";

	if (is_hex(ch1) && is_hex(ch2) && is_hex(ch3) && is_hex(ch4)) {
		curInd += 2;
		s.SetAt(0, (to_int(ch1) << 12 & 0xF000) | (to_int(ch2) << 8 & 0x0F00) |
			(to_int(ch3) << 4 & 0x0F00) | (to_int(ch4) & 0x000F));
	}
	else if (is_hex(ch1) && is_hex(ch2)) {
		curInd += 2;
		s.SetAt(0, (to_int(ch1) << 4 & 0xF0) | (to_int(ch2) & 0x0F));
	}

	return s;
#undef to_low
#undef is_dig
#undef is_hex
#undef to_int
}
Esempio n. 2
0
CMString WCPattern::parseOctal()
{
#define islowoc(x)  ((x) >= '0' && (x) <= '3')
#define isoc(x)     ((x) >= '0' && (x) <= '7')
#define fromoc(x)   ((x) - '0')
	int ci = curInd;
	wchar_t ch1 = (ci + 0 < pattern.GetLength()) ? pattern[ci + 0] : USHRT_MAX;
	wchar_t ch2 = (ci + 1 < pattern.GetLength()) ? pattern[ci + 1] : USHRT_MAX;
	wchar_t ch3 = (ci + 2 < pattern.GetLength()) ? pattern[ci + 2] : USHRT_MAX;
	CMString s = L" ";

	if (islowoc(ch1) && isoc(ch2)) {
		curInd += 2;
		s.SetAt(0, fromoc(ch1) * 8 + fromoc(ch2));
		if (isoc(ch3)) {
			++curInd;
			s.SetAt(0, s[0] * 8 + fromoc(ch3));
		}
	}
	else if (isoc(ch1) && isoc(ch2)) {
		curInd += 2;
		s.SetAt(0, fromoc(ch1) * 8 + fromoc(ch2));
	}
	else raiseError();

	return s;
#undef islowoc
#undef isoc
#undef fromoc
}