Beispiel #1
0
RakNet::RakString& RakString::URLEncode(void)
{
	RakString result;
	size_t strLen = strlen(sharedString->c_str);
	result.Allocate(strLen*3);
	char *output=result.sharedString->c_str;
	unsigned int outputIndex=0;
	unsigned i;
	char c;
	for (i=0; i < strLen; i++)
	{
		c=sharedString->c_str[i];
		if (
			(c<=47) ||
			(c>=58 && c<=64) ||
			(c>=91 && c<=96) ||
			(c>=123)
			)
		{
			RakNet::RakString tmp("%2X", c);
			output[outputIndex++]='%';
			output[outputIndex++]=tmp.sharedString->c_str[0];
			output[outputIndex++]=tmp.sharedString->c_str[1];
		}
		else
		{
			output[outputIndex++]=c;
		}
	}

	output[outputIndex]=0;

	*this = result;
	return *this;
}
Beispiel #2
0
RakNet::RakString& RakString::URLDecode(void)
{
	RakString result;
	size_t strLen = strlen(sharedString->c_str);
	result.Allocate(strLen);
	char *output=result.sharedString->c_str;
	unsigned int outputIndex=0;
	char c;
	char hexDigits[2];
	char hexValues[2];
	unsigned int i;
	for (i=0; i < strLen; i++)
	{
		c=sharedString->c_str[i];
		if (c=='%')
		{
			hexDigits[0]=sharedString->c_str[++i];
			hexDigits[1]=sharedString->c_str[++i];
			
			if (hexDigits[0]==' ')
				hexValues[0]=0;
			
			if (hexDigits[0]>='A' && hexDigits[0]<='F')
				hexValues[0]=hexDigits[0]-'A'+10;
			if (hexDigits[0]>='a' && hexDigits[0]<='f')
				hexValues[0]=hexDigits[0]-'a'+10;
			else
				hexValues[0]=hexDigits[0]-'0';

			if (hexDigits[1]>='A' && hexDigits[1]<='F')
				hexValues[1]=hexDigits[1]-'A'+10;
			if (hexDigits[1]>='a' && hexDigits[1]<='f')
				hexValues[1]=hexDigits[1]-'a'+10;
			else
				hexValues[1]=hexDigits[1]-'0';

			output[outputIndex++]=hexValues[0]*16+hexValues[1];
		}
		else
		{
			output[outputIndex++]=c;
		}
	}

	output[outputIndex]=0;

	*this = result;
	return *this;
}
Beispiel #3
0
RakString RakString::SubStr(unsigned int index, unsigned int count) const
{
	size_t length = GetLength();
	if (index >= length || count==0)
		return RakString();
	RakString copy;
	size_t numBytes = length-index;
	if (count < numBytes)
		numBytes=count;
	copy.Allocate(numBytes+1);
	size_t i;
	for (i=0; i < numBytes; i++)
		copy.sharedString->c_str[i]=sharedString->c_str[index+i];
	copy.sharedString->c_str[i]=0;
	return copy;
}