Beispiel #1
0
        /// <summary>
        /// Transforme un nom d'objet ou de fichier de façon à ce qu'il respecte une longueur de 8 caractères maxi et son unicité.
        /// This transformation is used with 3D meshes, materials, texture names.
        /// </summary>
        /// <param name="objectName">nom à convertir, sans chemin s'il s'agit d'un fichier</param>
        /// <returns>Un nom unique, ou null s'il s'agit d'une chaîne vide ou nulle</returns>
        public static string NormalizeName(string objectName)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                return(null);
            }

            // Récupération du nom sans extension
            string name = File2.GetNameFromFilename(objectName);

            if (name.Length <= 8)
            {
                // Length <= 8: string is filled with 0s
                for (int i = name.Length; i < 8; i++)
                {
                    name += "\0";
                }
                // BUG_: name is returned
                return(name);
            }

            // Récupération des caractères dépassant le 8e
            char[] nameChars = name.Substring(0, 8).ToCharArray();
            char[] overFlow  = name.Substring(8).ToCharArray();

            // Pour chaque caractère dépassant, on va ajouter sa valeur ASCII aux caractères de début de chaîne
            // EVO_84: found how to manage >16 characters : modulo 8
            for (int pos = 0; pos < overFlow.Length; pos++)
            {
                nameChars[pos % 8] = (char)(nameChars[pos % 8] + overFlow[pos]);
            }

            return(String2.CharArrayToString(nameChars));
        }