Exemplo n.º 1
0
 public void Read(Stream raf)
 {
     tag = new Tag();
     ei = new EncodingInfo();
     br = new BinaryReader(raf);
     Parse();
 }
Exemplo n.º 2
0
        private void DisplayEncodingCharacters(EncodingInfo encodingInfo)
        {
            if (encodingInfo == null) return;

            listView1.BeginUpdate();

            try
            {
                var encoding = Encoding.GetEncoding(encodingInfo.Name, new EncoderReplacementFallback(""), new DecoderReplacementFallback(""));
                listView1.Items.Clear();

                var chars = new[]
                    {
                        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'
                        , 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
                        , 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
                        , 'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ь', 'ы', 'ъ', 'э', 'ю', 'я'
                        , 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ь', 'Ы', 'Ъ', 'Э', 'Ю', 'Я'
                    };
                for (int i=0; i<chars.Length; i++)
                {
                    string s = chars[i].ToString();
                    var item = new ListViewItem(s);
                    item.SubItems.Add(ByteArrayToString(encoding.GetBytes(s)));
                    listView1.Items.Add(item);
                }
            }
            finally
            {
                listView1.EndUpdate();
            }
        }
Exemplo n.º 3
0
        private void InitEncodingsComboBox(EncodingInfo selectedEncoding)
        {
            selectedEncoding = selectedEncoding ?? _defaultEncodingInfo;

            comboBoxEncoding.BeginUpdate();
            try
            {
                comboBoxEncoding.SelectedItem = null;

                EncodingInfo[] encodings = checkBoxShowAllEncodings.Checked
                                               ? _allEncodingsInfo
                                               : _preferableEncodingsInfo;
                comboBoxEncoding.DataSource = encodings;

                int idx = comboBoxEncoding.Items.IndexOf(selectedEncoding);
                if (idx == -1)
                {
                    idx = comboBoxEncoding.Items.IndexOf(_defaultEncodingInfo);
                }
                comboBoxEncoding.SelectedIndex = idx;
            }
            finally
            {
                comboBoxEncoding.EndUpdate();
            }
        }
Exemplo n.º 4
0
        // FIXME: As everyone would agree, this implementation is so *hacky*
        // and could be very easily broken. But since there is a test for
        // this method to make sure that this method always returns
        // the same number and content of encoding infos, this won't
        // matter practically.
        public static EncodingInfo[] GetEncodings()
        {
            if (encoding_infos == null)
            {
                int [] codepages = new int [] {
                    37, 437, 500, 708,
                    850, 852, 855, 857, 858, 860, 861, 862, 863,
                    864, 865, 866, 869, 870, 874, 875,
                    932, 936, 949, 950,
                    1026, 1047, 1140, 1141, 1142, 1143, 1144,
                    1145, 1146, 1147, 1148, 1149,
                    1200, 1201, 1250, 1251, 1252, 1253, 1254,
                    1255, 1256, 1257, 1258,
                    10000, 10079, 12000, 12001,
                    20127, 20273, 20277, 20278, 20280, 20284,
                    20285, 20290, 20297, 20420, 20424, 20866,
                    20871, 21025, 21866, 28591, 28592, 28593,
                    28594, 28595, 28596, 28597, 28598, 28599,
                    28605, 38598,
                    50220, 50221, 50222, 51932, 51949, 54936,
                    57002, 57003, 57004, 57005, 57006, 57007,
                    57008, 57009, 57010, 57011,
                    65000, 65001
                };

                encoding_infos = new EncodingInfo [codepages.Length];
                for (int i = 0; i < codepages.Length; i++)
                {
                    encoding_infos [i] = new EncodingInfo(codepages [i]);
                }
            }
            return(encoding_infos);
        }
Exemplo n.º 5
0
        public override bool Equals(Object value)
        {
            EncodingInfo that = value as EncodingInfo;

            if (that != null)
            {
                return(this.CodePage == that.CodePage);
            }
            return(false);
        }
Exemplo n.º 6
0
        public MainForm()
        {
            InitializeComponent();

            _allEncodingsInfo = Encoding.GetEncodings().OrderBy(ei => ei.DisplayName).ToArray();

            var preferredEncodingNames = new[] {"windows-1251", "koi8-r", "us-ascii", "utf-8", "utf-16", "utf-16BE", "utf-32", "utf-32BE"};
            _preferableEncodingsInfo = _allEncodingsInfo.Where(ei => preferredEncodingNames.Contains(ei.Name)).ToArray();

            const string defaultEncodingName = "utf-8";
            _defaultEncodingInfo = _preferableEncodingsInfo.Single(ei => defaultEncodingName.Equals(ei.Name));
        }
Exemplo n.º 7
0
        // Return a list of all EncodingInfo objects describing all of our encodings
        internal static EncodingInfo[] GetEncodings()
        {
            EncodingInfo[] arrayEncodingInfo = new EncodingInfo[s_encodingDataTableItems.Length];

            for (int i = 0; i < s_encodingDataTableItems.Length; i++)
            {
                CodePageDataItem dataItem = s_encodingDataTableItems[i];

                arrayEncodingInfo[i] = new EncodingInfo(dataItem.CodePage, dataItem.WebName,
                                                        SR.GetResourceString(dataItem.DisplayNameResourceKey));
            }

            return(arrayEncodingInfo);
        }
Exemplo n.º 8
0
        // Return a list of all EncodingInfo objects describing all of our encodings
        internal static EncodingInfo[] GetEncodings()
        {
            EncodingInfo[] arrayEncodingInfo = new EncodingInfo[s_encodingDataTableItems.Length];

            for (int i = 0; i < s_encodingDataTableItems.Length; i++)
            {
                CodePageDataItem dataItem = s_encodingDataTableItems[i];

                arrayEncodingInfo[i] = new EncodingInfo(dataItem.CodePage, dataItem.WebName,
                    Environment.GetResourceString(dataItem.DisplayNameResourceKey));
            }

            return arrayEncodingInfo;
        }
        internal static unsafe EncodingInfo [] GetEncodings(CodePagesEncodingProvider provider)
        {
            lock (s_streamLock)
            {
                s_codePagesEncodingDataStream.Seek(CODEPAGE_DATA_FILE_HEADER_SIZE, SeekOrigin.Begin);

                int codePagesCount;
                fixed(byte *pBytes = &s_codePagesDataHeader[0])
                {
                    CodePageDataFileHeader *pDataHeader = (CodePageDataFileHeader *)pBytes;

                    codePagesCount = pDataHeader->CodePageCount;
                }

                EncodingInfo [] encodingInfoList = new EncodingInfo[codePagesCount];

                CodePageIndex codePageIndex  = default;
                Span <byte>   pCodePageIndex = new Span <byte>(&codePageIndex, Unsafe.SizeOf <CodePageIndex>());

                for (int i = 0; i < codePagesCount; i++)
                {
                    s_codePagesEncodingDataStream.Read(pCodePageIndex);

                    string codePageName;
                    switch (codePageIndex.CodePage)
                    {
                    // Fixup some encoding names.
                    case 950:   codePageName = "big5"; break;

                    case 10002: codePageName = "x-mac-chinesetrad"; break;

                    case 20833: codePageName = "x-ebcdic-koreanextended"; break;

                    default:    codePageName = new string(&codePageIndex.CodePageName); break;
                    }

                    string?resourceName = EncodingNLS.GetLocalizedEncodingNameResource(codePageIndex.CodePage);
                    string?displayName  = null;

                    if (resourceName != null && resourceName.StartsWith("Globalization_cp_", StringComparison.OrdinalIgnoreCase))
                    {
                        displayName = SR.GetResourceString(resourceName);
                    }

                    encodingInfoList[i] = new EncodingInfo(provider, codePageIndex.CodePage, codePageName, displayName ?? codePageName);
                }

                return(encodingInfoList);
            }
        }
Exemplo n.º 10
0
        // Return a list of all EncodingInfo objects describing all of our encodings
        internal static EncodingInfo[] GetEncodings()
        {
            EncodingInfo[] arrayEncodingInfo = new EncodingInfo[s_mappedCodePages.Length];

            for (int i = 0; i < s_mappedCodePages.Length; i++)
            {
                arrayEncodingInfo[i] = new EncodingInfo(
                    s_mappedCodePages[i],
                    s_webNames.Substring(s_webNameIndices[i], s_webNameIndices[i + 1] - s_webNameIndices[i]),
                    GetDisplayName(s_mappedCodePages[i], i)
                    );
            }

            return(arrayEncodingInfo);
        }
        public static string GetSerializedEncodingProperty(int?codepage, int?delimiter)
        {
            TxtCsvProperties oCsvProperties = new TxtCsvProperties();

            oCsvProperties.codepage  = codepage;
            oCsvProperties.delimiter = delimiter;
            System.Text.EncodingInfo[] aSystemEncodings = System.Text.Encoding.GetEncodings();
            for (int i = 0; i < aSystemEncodings.Length; i++)
            {
                System.Text.EncodingInfo oEncodingInfo = aSystemEncodings[i];
                oCsvProperties.encodings.Add(new TxtCsvPropertiesEncoding(oEncodingInfo.CodePage, oEncodingInfo.DisplayName));
            }
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return(serializer.Serialize(oCsvProperties));
        }
 internal static unsafe EncodingInfo[] GetEncodings()
 {
     if (lastCodePageItem == 0)
     {
         int index = 0;
         while (codePageDataPtr[index].codePage != 0)
         {
             index++;
         }
         lastCodePageItem = index;
     }
     EncodingInfo[] infoArray = new EncodingInfo[lastCodePageItem];
     for (int i = 0; i < lastCodePageItem; i++)
     {
         infoArray[i] = new EncodingInfo(codePageDataPtr[i].codePage, new string(codePageDataPtr[i].webName), Environment.GetResourceString("Globalization.cp_" + codePageDataPtr[i].codePage));
     }
     return infoArray;
 }
Exemplo n.º 13
0
        // Return a list of all EncodingInfo objects describing all of our encodings
        internal static unsafe EncodingInfo[] GetEncodings()
        {
            if (lastCodePageItem == 0)
            {
                int count;
                for (count = 0; codePageDataPtr[count].codePage != 0; count++)
                {
                    // Count them
                }
                lastCodePageItem = count;
            }

            EncodingInfo[] arrayEncodingInfo = new EncodingInfo[lastCodePageItem];

            int i;

            for (i = 0; i < lastCodePageItem; i++)
            {
                arrayEncodingInfo[i] = new EncodingInfo(codePageDataPtr[i].codePage, CodePageDataItem.CreateString(codePageDataPtr[i].Names, 0),
                                                        SR.GetResourceString("Globalization_cp_" + codePageDataPtr[i].codePage));
            }

            return(arrayEncodingInfo);
        }
Exemplo n.º 14
0
        /// <summary>Gets a value indicating whether the specified object is equal to the current <see cref="T:System.Text.EncodingInfo" /> object.</summary>
        /// <returns>true if <paramref name="value" /> is a <see cref="T:System.Text.EncodingInfo" /> object and is equal to the current <see cref="T:System.Text.EncodingInfo" /> object; otherwise, false.</returns>
        /// <param name="value">An object to compare to the current <see cref="T:System.Text.EncodingInfo" /> object.</param>
        /// <filterpriority>1</filterpriority>
        public override bool Equals(object value)
        {
            EncodingInfo encodingInfo = value as EncodingInfo;

            return(encodingInfo != null && encodingInfo.codepage == this.codepage);
        }
        public override bool Equals(object value)
        {
            EncodingInfo info = value as EncodingInfo;

            return((info != null) && (this.CodePage == info.CodePage));
        }
 private static int CompareEncodingInfoDisplayName(EncodingInfo x, EncodingInfo y)
 {
     return string.Compare(x.DisplayName, y.DisplayName);
 }
Exemplo n.º 17
0
	// FIXME: As everyone would agree, this implementation is so *hacky*
	// and could be very easily broken. But since there is a test for
	// this method to make sure that this method always returns
	// the same number and content of encoding infos, this won't
	// matter practically.
	public static EncodingInfo[] GetEncodings ()
	{
		if (encoding_infos == null) {
			int [] codepages = new int [] {
				37, 437, 500, 708,
				850, 852, 855, 857, 858, 860, 861, 862, 863, 
				864, 865, 866, 869, 870, 874, 875,
				932, 936, 949, 950,
				1026, 1047, 1140, 1141, 1142, 1143, 1144,
				1145, 1146, 1147, 1148, 1149,
				1200, 1201, 1250, 1251, 1252, 1253, 1254,
				1255, 1256, 1257, 1258,
				10000, 10079, 12000, 12001,
				20127, 20273, 20277, 20278, 20280, 20284,
				20285, 20290, 20297, 20420, 20424, 20866,
				20871, 21025, 21866, 28591, 28592, 28593,
				28594, 28595, 28596, 28597, 28598, 28599,
				28605, 38598,
				50220, 50221, 50222, 51932, 51949, 54936,
				57002, 57003, 57004, 57005, 57006, 57007,
				57008, 57009, 57010, 57011,
				65000, 65001};

			encoding_infos = new EncodingInfo [codepages.Length];
			for (int i = 0; i < codepages.Length; i++)
				encoding_infos [i] = new EncodingInfo (codepages [i]);
		}
		return encoding_infos;
	}
Exemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EncodingWrapper"/> class.
 /// </summary>
 /// <param name="encoding">The encoding.</param>
 /// <remarks>Documented by Dev02, 2008-02-13</remarks>
 public EncodingWrapper(EncodingInfo encoding)
 {
     this.encoding = encoding.GetEncoding();
 }
        [System.Security.SecuritySafeCritical]  // auto-generated
        internal static unsafe EncodingInfo[] GetEncodings()
        {
            if (lastCodePageItem == 0)
            {
                int count;
                for (count = 0; codePageDataPtr[count].codePage != 0; count++)
                {
                    // Count them
                }
                lastCodePageItem = count;
            }

            EncodingInfo[] arrayEncodingInfo = new EncodingInfo[lastCodePageItem];

            int i;
            for (i = 0; i < lastCodePageItem; i++)
            {
                arrayEncodingInfo[i] = new EncodingInfo(codePageDataPtr[i].codePage, CodePageDataItem.CreateString(codePageDataPtr[i].Names, 0),
#if MONO
                    Environment.GetResourceStringEncodingName(codePageDataPtr[i].codePage));
#else
                    Environment.GetResourceString("Globalization.cp_" + codePageDataPtr[i].codePage));
#endif
            }
            
            return arrayEncodingInfo;
        }        
Exemplo n.º 20
0
 public EncodingInfoWrapper(EncodingInfo info, byte[] preamble) {
     _info = info;
     _preamble = preamble;
 }
Exemplo n.º 21
0
 public EncodingInfoWrapper(EncodingInfo info) {
     _info = info;
 }
Exemplo n.º 22
0
        public void LoadFile(string path, EncodingInfo encodingInfo)
        {
            if (textEditControl.Modified || (textEditControl.Count != 1) || (textEditControl.GetLine(0).Length != 0))
            {
                Debug.Assert(false);
                throw new InvalidOperationException();
            }

            EditorConfig config = MainClass.Config.Find(Path.GetExtension(path));

            textEditControl.Font = config.Font;
            textEditControl.TabSize = config.TabSize;
            textEditControl.AutoIndent = config.AutoIndent;
            textEditControl.InsertTabAsSpaces = config.InsertTabAsSpaces;
            textEditControl.SimpleNavigation = config.SimpleNavigation;

            this.Text = Path.GetFileName(path);

            this.path = path;
            this.encoding = encodingInfo.Encoding;
            this.includeBom = encodingInfo.BomLength != 0;

            using (Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                long length = stream.Length;

                stream.Seek(encodingInfo.BomLength, SeekOrigin.Begin);

                // must use our own reader rather than TextReader since we want to also determine
                // which kind of line ending the file used.
                LineEndingInfo lineEndingInfo;
                ITextStorage text = textEditControl.TextStorageFactory.FromStream(
                    stream,
                    encoding,
                    out lineEndingInfo);
                linefeed = Environment.NewLine;
                string lineFeedName = "Windows";
                if (lineEndingInfo.unixLFCount > 2 * (lineEndingInfo.windowsLFCount + lineEndingInfo.macintoshLFCount))
                {
                    linefeed = "\n";
                    lineFeedName = "UNIX";
                }
                else if (lineEndingInfo.macintoshLFCount > 2 * (lineEndingInfo.windowsLFCount + lineEndingInfo.unixLFCount))
                {
                    linefeed = "\r";
                    lineFeedName = "Macintosh";
                }

                int m = 0;
                m += (lineEndingInfo.windowsLFCount != 0 ? 1 : 0);
                m += (lineEndingInfo.macintoshLFCount != 0 ? 1 : 0);
                m += (lineEndingInfo.unixLFCount != 0 ? 1 : 0);
                if (m > 1)
                {
                    if (!textEditControl.TextStorageFactory.PreservesLineEndings)
                    {
                        MessageBox.Show(String.Format("The file contains inconsistent line endings. All line endings will be converted to the most common one, {0}.", lineFeedName), "Text Editor", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("The file contains inconsistent line endings, which will be preserved. Select a new line ending on the menu to make all line endings consistent.", "Text Editor", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }

                if ((length >= 4096) && (length / text.Count >= 5000))
                {
                    DialogResult result = MessageBox.Show(
                        "The file data contains a small number of very long lines, indicating the encoding used to open it may be incorrect. Continue trying to open? (It may take a long time.)",
                        "Encoding",
                        MessageBoxButtons.OKCancel,
                        MessageBoxIcon.Warning);
                    if (result != DialogResult.OK)
                    {
                        throw new ApplicationException();
                    }
                }

                textEditControl.Reload(
                    textEditControl.TextStorageFactory,
                    text);
            }

            textEditControl.ClearUndoRedo();
            textEditControl.SetInsertionPoint(0, 0);
            textEditControl.Modified = false;

            startedEmpty = false;
        }
Exemplo n.º 23
0
 internal EncodingItem(EncodingInfo info)
 {
     EncodingInfo = info;
 }
Exemplo n.º 24
0
 internal void SetEncoding(EncodingInfo EncodingInfo)
 {
     this.SetEncoding(EncodingInfo.GetEncoding());
 }
Exemplo n.º 25
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        internal static unsafe EncodingInfo[] GetEncodings() 
        {
            if (lastCodePageItem == 0)
            {
                int count; 
                for (count = 0; codePageDataPtr[count].codePage != 0; count++)
                { 
                    // Count them 
                }
                lastCodePageItem = count; 
            }

            EncodingInfo[] arrayEncodingInfo = new EncodingInfo[lastCodePageItem];
 
            int i;
            for (i = 0; i < lastCodePageItem; i++) 
            { 
                arrayEncodingInfo[i] = new EncodingInfo(codePageDataPtr[i].codePage, new String(codePageDataPtr[i].webName),
                    Environment.GetResourceString("Globalization.cp_" + codePageDataPtr[i].codePage)); 
            }

            return arrayEncodingInfo;
        } 
Exemplo n.º 26
0
		protected GeneralAppSettingsPageBase(CommonEditorOptions options) {
			if (options == null)
				throw new ArgumentNullException(nameof(options));
			this.options = options;
			GroupSizeInBytesVM = new Int32VM(a => { }, useDecimal: true) { Min = 0, Max = int.MaxValue };
			HexOffsetFormatVM = new EnumListVM(hexOffsetFormatList);
			EncodingInfoVM = new EnumListVM(Encoding.GetEncodings().OrderBy(a => a.DisplayName, StringComparer.CurrentCultureIgnoreCase).Select(a => new EnumVM(a, a.DisplayName)).ToArray());

			EnableHighlightCurrentLine = options.EnableHighlightCurrentLine;
			HighlightCurrentValue = options.HighlightCurrentValue;
			HighlightActiveColumn = options.HighlightActiveColumn;
			ValuesLowerCaseHex = options.ValuesLowerCaseHex;
			OffsetLowerCaseHex = options.OffsetLowerCaseHex;
			EnableColorization = options.EnableColorization;
			GroupSizeInBytesVM.Value = options.GroupSizeInBytes;
			HexOffsetFormat = options.HexOffsetFormat;
			EncodingInfo = GetEncodingInfo(options.EncodingCodePage) ?? GetEncodingInfo(Encoding.UTF8.CodePage) ?? (EncodingInfo)EncodingInfoVM.Items.FirstOrDefault()?.Value;
		}