Пример #1
0
ControlNodeType ControlNode::decodeText(std::string& text){
	strToLowerCase(text);
	return tlm[text];
}
Пример #2
0
String toLowerCase(const String &str) {
  String result(str);
  strToLowerCase(result.cstr());
  return result;
}
Пример #3
0
vector<uint8_t> Immediate::parse(std::string& in, ImmediateEncoding base)
{
		string::iterator it_fwd;
string::reverse_iterator it;
vector<uint8_t> out;
int padding = 0;
int bytes_written=0;
unsigned int tmp = 0;
int counter = 1;
std::string intermediate;

//pad with zero if not an even mult

switch(base)
{
	case BASE_HEX:
	strToLowerCase(in);

	if (in.length() % 2 != 0)
		in.insert(0,1,'0');
	
	//skip the delmiting commas.
	out.resize((in.length()) / 2);	
	//in.resize(4);
	for (it = in.rbegin();it!=in.rend();++it)
{
	
	out[bytes_written] = parseDigit(*it) | parseDigit(*++it) << 4 ;
	bytes_written++;	

}


	break;
	case BASE_BIN:
	strToLowerCase(in);
	padding =  8 - (in.length() % 8);
	if (padding != 8)
		in.insert(0, padding, (char)in[0]);
	out.resize(in.length() / 8);
	for (it = in.rbegin();it != in.rend();)
	{
	
		for (int i = 0; i < 8;i++)
		{
					out[bytes_written] |= parseDigit(*it) << i;
					it++;
			}
	}
	break;
	case BASE_ASC:
		out.resize(in.length() - 2);
		trim(in, '\'');
		for (it_fwd = in.begin(); it_fwd < in.end();it_fwd++)
			{
			out[bytes_written] = (uint8_t)*it_fwd;
			bytes_written++;
			}
			
		break;
	case BASE_DEC:

		intermediate = in.at(0) == '-'? in.substr(1,-1): in;

		for (it= intermediate.rbegin();it < intermediate.rend();it++){
			tmp = tmp + (counter) *  parseDigit(*it);
			counter*=10;
		}

		if (in.at(0) == '-')
			tmp = (tmp * -1) & 0xFFFF;

		do {
		out.push_back((uint8_t)(tmp & 0xFF));
		tmp >>= 8;
		} while (tmp > 0);
			
	default:
	break;

	//clear out any zero-padding to make sure it fits in smallest byte count.
	//zero bytes isn't valid though...
}

	while ((out.size() > 1) && out.back() == (out.back() >= 0x80 ? 0xFF : 0x00))
		out.pop_back();

	return out;
}