/// <summary> /// Changes fully translated Unicode data, e.g. with Japanaese Kanji characters, into /// a string of characters that represents the raw, ISO character repertoire representation, i.e. /// with escape sequences, but encoded as a Unicode string /// </summary> /// <param name="unicodeData">Fully translated Unicode data</param> /// <param name="repertoire">Target repertoire to be transformed into</param> /// <returns></returns> private static string Encode(string unicodeData, CharacterSetInfo repertoire) { byte[] rawBytes; Encode(unicodeData, repertoire, out rawBytes); char[] rawCharacters = IsomorphicEncoding.GetChars(rawBytes); return(new string(rawCharacters)); }
/// <summary> /// Takes a string that is a representation of the raw sequence of bytes /// encoded using an ISO repertoire, but current encoded as a Unicode string /// and gives back a true Unicode string, e.g. containing the Japanese Kanji /// characters /// </summary> /// <param name="rawData">Sequence of bytes formatted in Unicode</param> /// <param name="repertoire">Original ISO repertoire used in the encoding</param> /// <returns>True Unicode string</returns> private static string Decode(string rawData, CharacterSetInfo repertoire) { // get it back to byte array form using a character set that includes // both GR and GL areas (characters up to \xff in binary value) // and it seems Windows-1252 works better than ISO-8859-1 byte[] rawBytes = IsomorphicEncoding.GetBytes(rawData); return(Decode(rawBytes, repertoire)); }
public static byte[] GetIsomorphicBytes(string rawBytesEncodedAsString) { // add a null terminator, otherwise we're going to have problems in the unamanged world if (rawBytesEncodedAsString == null) { return(null); } return(IsomorphicEncoding.GetBytes(rawBytesEncodedAsString)); }
public static string GetIsomorphicString(byte[] rawBytes) { return(IsomorphicEncoding.GetString(rawBytes)); }