Novell.Directory.Ldap.Rfc2251.RfcFilter.byteString C# (CSharp) Method

byteString() private static method

Convert a UTF8 encoded string, or binary data, into a String encoded for a string filter.
private static byteString ( sbyte value_Renamed ) : System.String
value_Renamed sbyte
return System.String
        private static System.String byteString(sbyte[] value_Renamed)
        {
            System.String toReturn = null;
            if (Novell.Directory.Ldap.Utilclass.Base64.isValidUTF8(value_Renamed, true))
            {
                try
                {
                    System.Text.Encoding encoder = System.Text.Encoding.GetEncoding("utf-8");
                    char[] dchar = encoder.GetChars(SupportClass.ToByteArray(value_Renamed));
                    toReturn = new String(dchar);

            //					toReturn = new String(value_Renamed, "UTF-8");
                }
                catch (System.IO.IOException e)
                {
                    throw new System.SystemException("Default JVM does not support UTF-8 encoding" + e);
                }
            }
            else
            {
                System.Text.StringBuilder binary = new System.Text.StringBuilder();
                for (int i = 0; i < value_Renamed.Length; i++)
                {
                    //TODO repair binary output
                    //Every octet needs to be escaped
                    if (value_Renamed[i] >= 0)
                    {
                        //one character hex string
                        binary.Append("\\0");
                        binary.Append(System.Convert.ToString(value_Renamed[i], 16));
                    }
                    else
                    {
                        //negative (eight character) hex string
                        binary.Append("\\" + System.Convert.ToString(value_Renamed[i], 16).Substring(6));
                    }
                }
                toReturn = binary.ToString();
            }
            return toReturn;
        }