Convert UTF8 string to a hex encoded string sutiable for use as a SSID hex encoded string
Normal characters are converted into 2x hex digits
Unicode encoded characters using \x are retained as hex characters
//SSID
//output_file << " ssid=\"" << ssid << "\"\n";
//Using the above will output any unicode characters as UTF8, but wpa_supplicant.conf will not interpret them correctly, it uses UTF16.
//This is a problem as SSID can contain unicode chaaracters, for instance the iPhone will have a SSID of "Adam\xE2\x80\x99s iPhone" for "Adam’s iPhone".
//When performing "sudo iwlist wlan0 scan" you will get \x values returned, so we have to convert them somehow.
//To support GCC 4.9 without built in UTF8 to UTF16 conversion functions we instead handle this by storing the SSID as hex characters.
//In wpa_supplicant.conf if the SSID is surrounded by quotes "" then its dealt with as a string, but otherwise it is dealt with as
//2 digit hex characters.
output_file << " ssid=";
for (Index = 0; Index < ssid.length(); Index++)
{
if ((ssid[Index] == '\\') && (ssid[(Index+1)] == 'x'))
{
Index++;
Index++;
output_file << (char)ssid[Index++];
output_file << (char)ssid[Index];
}
else
{
output_file << hex << uppercase << setfill('0') << setw(2) << (int)ssid[Index];
}
}
output_file << "\n";
