Esempio n. 1
0
        public string ReadAllText(string path)
        {
            var text = File.ReadAllText(path, Encoding.UTF8);
            //Occurrence of the character � is interpreted as invalid UTF-8
            var invalidCharIndex = text.IndexOf((char)65533);

            if (invalidCharIndex != -1)
            {
                bool tryDefault = !Encoding.Default.Equals(Encoding.UTF8);

                _logger.Info($"WARNING: File '{path}' contains invalid UTF-8 character at line {ScriptPositionReporting.Line(text, invalidCharIndex)}." +
                             (tryDefault ? $" Reading with default system encoding instead." : "") +
                             $" Save text file as UTF-8.");

                if (tryDefault)
                {
                    text = File.ReadAllText(path, Encoding.Default);
                }
            }
            return(text);
        }
Esempio n. 2
0
        public string ReadAllText(string path)
        {
            var text = File.ReadAllText(path, Encoding.UTF8);
            //Occurrence of the character � is interpreted as invalid UTF-8
            var invalidCharIndex = text.IndexOf((char)65533);

            if (invalidCharIndex != -1)
            {
                bool tryDefault = !Encoding.Default.Equals(Encoding.UTF8);

                _logger.Warning($"Warning: File '{path}' contains invalid UTF-8 character at line {ScriptPositionReporting.Line(text, invalidCharIndex)}." +
                                (tryDefault ? $" Reading with default system encoding instead." : "") +
                                $" Save the text file as UTF-8.");

                if (tryDefault)
                {
                    text = File.ReadAllText(path, CodePagesEncodingProvider.Instance.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage));
                }
            }
            return(text);
        }