Ejemplo n.º 1
0
        public void TestUTF8()
        {
            var src = "Hello World\u2122";

            byte[] input = Encoding.UTF8.GetBytes(src);
            Assert.AreEqual(src, TextFileUtility.GetText(input));
        }
Ejemplo n.º 2
0
        public void TestGB18030()
        {
            var src = "南北西东";

            byte[] input = Encoding.GetEncoding(54936).GetBytes(src);
            Assert.AreEqual(src, TextFileUtility.GetText(input));
        }
Ejemplo n.º 3
0
        public void TestUTF16BESimpleText()
        {
            var src = "Hello World";

            byte[] input = Encoding.BigEndianUnicode.GetBytes(src);
            Assert.AreEqual(src, TextFileUtility.GetText(input));
        }
Ejemplo n.º 4
0
        public override Task <TextAndVersion> LoadTextAndVersionAsync(Workspace workspace, DocumentId documentId, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            SourceText text;

            if (IdeServices.DocumentManager?.Documents.Any(doc => doc.IsFile && doc.FileName != null && FilePath.PathComparer.Compare(Path.GetFullPath(doc.FileName), fileName) == 0 && doc.Editor != null) == true)
            {
                var document = IdeServices.DocumentManager?.Documents.FirstOrDefault(doc => doc.IsFile && doc.FileName != null && FilePath.PathComparer.Compare(Path.GetFullPath(doc.FileName), fileName) == 0 && doc.Editor != null);
                text = MonoDevelopSourceText.Create(document.Editor);
            }
            else
            {
                try {
                    if (File.Exists(fileName))
                    {
                        text = SourceText.From(TextFileUtility.GetText(fileName));
                    }
                    else
                    {
                        text = SourceText.From("");
                    }
                } catch (Exception e) {
                    LoggingService.LogError($"Failed to get file text for {fileName}", e);
                    text = SourceText.From("");
                }
            }
            return(Task.FromResult(TextAndVersion.Create(text, VersionStamp.Create())));
        }
Ejemplo n.º 5
0
        public void TestUTF16BEMixedText()
        {
            var src = "Hello\u00A9\u008D World\u2122";

            byte[] input = Encoding.BigEndianUnicode.GetBytes(src);
            Assert.AreEqual(src, TextFileUtility.GetText(input));
        }
Ejemplo n.º 6
0
        public void TestCp1252()
        {
            var src = "Hello\u00A9 World\u00C1";

            byte[] input = Encoding.GetEncoding(1252).GetBytes(src);
            Assert.AreEqual(src, TextFileUtility.GetText(input));
        }
Ejemplo n.º 7
0
        public override Task <TextAndVersion> LoadTextAndVersionAsync(Workspace workspace, DocumentId documentId, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            SourceText text;

            if (IdeApp.Workbench?.Documents.Any(doc => doc.IsFile && doc.FileName != null && FilePath.PathComparer.Compare(Path.GetFullPath(doc.FileName), fileName) == 0) == true)
            {
                text = new MonoDevelopSourceText(TextFileProvider.Instance.GetTextEditorData(fileName).CreateDocumentSnapshot());
            }
            else
            {
                try {
                    if (File.Exists(fileName))
                    {
                        text = SourceText.From(TextFileUtility.GetText(fileName));
                    }
                    else
                    {
                        text = SourceText.From("");
                    }
                } catch (Exception e) {
                    LoggingService.LogError($"Failed to get file text for {fileName}", e);
                    text = SourceText.From("");
                }
            }
            return(Task.FromResult(TextAndVersion.Create(text, VersionStamp.Create())));
        }
        public void TestBug16332()
        {
            byte[] input = new byte[] { 0xEF, 0xBB, 0xBF, (byte)'a' };
            bool   hadBom;

            Assert.AreEqual("a", TextFileUtility.GetText(input, Encoding.UTF8, out hadBom));
            Assert.IsTrue(hadBom);
        }
Ejemplo n.º 9
0
 public CodeRulePanelWidget()
 {
     TextEditor          = TextEditorFactory.CreateNewEditor();
     TextEditor.MimeType = "application/xml";
     TextEditor.Options  = DefaultSourceEditorOptions.PlainEditor;
     try {
         TextEditor.Text = TextFileUtility.GetText(TypeSystemService.RuleSetManager.GlobalRulesetFileName, out encoding);
     } catch (Exception e) {
         LoggingService.LogError("Error while loading global rule set file " + TypeSystemService.RuleSetManager, e);
         loadingError = true;
     }
 }
Ejemplo n.º 10
0
        public string ReadString(bool readBinaryFiles)
        {
            string result = cachedText != null ? cachedText.Target as string : null;

            if (result != null)
            {
                return(result);
            }

            if (buffer != null)
            {
                result = buffer.ToString();
            }
            else
            {
                Document doc = null;

                var task = SearchDocument();
                if (task.Wait(1000))
                {
                    doc = task.Result;
                }

                if (doc != null && doc.Editor != null)
                {
                    result   = doc.Editor.Text;
                    encoding = doc.Editor.Encoding;
                    hadBom   = doc.Editor.UseBOM;
                }
                else
                {
                    try {
                        if (!File.Exists(FileName))
                        {
                            return(null);
                        }
                        var content = File.ReadAllBytes(FileName);
                        if (!readBinaryFiles && TextFileUtility.IsBinary(content))
                        {
                            return(null);
                        }
                        result = TextFileUtility.GetText(content, out encoding, out hadBom);
                    } catch (Exception e) {
                        LoggingService.LogError("Error while opening " + FileName, e);
                        return(null);
                    }
                }
            }
            cachedText = new WeakReference(result);
            return(result);
        }
Ejemplo n.º 11
0
        void IViewContent.LoadNew(System.IO.Stream content, string mimeType)
        {
            textEditor.MimeType = mimeType;
            string text = null;

            if (content != null)
            {
                Encoding encoding;
                bool     hadBom;
                text                = TextFileUtility.GetText(content, out encoding, out hadBom);
                textEditor.Text     = text;
                textEditor.Encoding = encoding;
                textEditor.UseBOM   = hadBom;
            }
            RunFirstTimeFoldUpdate(text);
            textEditorImpl.InformLoadComplete();
        }
Ejemplo n.º 12
0
        async Task <TextAndVersion> GetTextAndVersion(Workspace workspace, DocumentId documentId, CancellationToken cancellationToken)
        {
            if (!File.Exists(fileName))
            {
                return(TextAndVersion.Create(await((MonoDevelopWorkspace)workspace).GetDocument(documentId).GetTextAsync(cancellationToken), VersionStamp.Create()));
            }
            SourceText text;

            if (workspace.IsDocumentOpen(documentId))
            {
                text = new MonoDevelopSourceText(TextFileProvider.Instance.GetTextEditorData(fileName).CreateDocumentSnapshot());
            }
            else
            {
                text = SourceText.From(TextFileUtility.GetText(fileName));
            }
            return(TextAndVersion.Create(text, VersionStamp.Create()));
        }
Ejemplo n.º 13
0
        public void UpdateLocalText()
        {
            var    textBuffer = info.Controller.GetContent <ITextBuffer> ();
            string localText  = null;

            if (textBuffer != null)
            {
                localText = textBuffer.CurrentSnapshot.GetText();
            }
            else
            {
                localText = TextFileUtility.GetText(info.Item.Path);
            }

            foreach (var data in dict.Values)
            {
                data.Document.TextChanged -= HandleDataDocumentTextReplaced;
                data.Document.Text         = localText;
                data.Document.TextChanged += HandleDataDocumentTextReplaced;
            }
            CreateDiff();
        }
Ejemplo n.º 14
0
        public string ReadString()
        {
            if (buffer != null)
            {
                return(buffer.ToString());
            }
            var doc = SearchDocument();

            if (doc != null)
            {
                return(doc.Editor.Text);
            }
            try {
                if (!File.Exists(FileName))
                {
                    return(null);
                }
                return(TextFileUtility.GetText(FileName, out encoding, out hadBom));
            } catch (Exception e) {
                LoggingService.LogError("Error while opening " + FileName, e);
                return(null);
            }
        }
Ejemplo n.º 15
0
        internal void SetLocal(TextEditorData data)
        {
            if (info == null)
            {
                throw new InvalidOperationException("Version control info must be set before attaching the merge view to an editor.");
            }
            dict[data.Document] = data;

            var editor = info.Document.GetContent <ITextBuffer> ();

            if (editor != null)
            {
                data.Document.Text       = editor.CurrentSnapshot.GetText();
                data.Document.IsReadOnly = editor.IsReadOnly(0);
            }
            else
            {
                data.Document.Text       = TextFileUtility.GetText(info.Item.Path);
                data.Document.IsReadOnly = true;
            }

            CreateDiff();
            data.Document.TextChanged += HandleDataDocumentTextReplaced;
        }
Ejemplo n.º 16
0
 public void TestFallback()
 {
     byte[] input = new byte[] { 0xFF, 0x10, 0xAA, (byte)'u', 0x8D };
     Assert.AreEqual("?\u0010?u?", TextFileUtility.GetText(input));
 }
Ejemplo n.º 17
0
        public BlameWidget(VersionControlDocumentInfo info)
        {
            GtkWorkarounds.FixContainerLeak(this);

            this.info = info;

            vAdjustment          = new Adjustment(0, 0, 0, 0, 0, 0);
            vAdjustment.Changed += HandleAdjustmentChanged;

            vScrollBar = new VScrollbar(vAdjustment);
            AddChild(vScrollBar);

            hAdjustment          = new Adjustment(0, 0, 0, 0, 0, 0);
            hAdjustment.Changed += HandleAdjustmentChanged;

            hScrollBar = new HScrollbar(hAdjustment);
            AddChild(hScrollBar);

            var          textView = info.Controller.GetContent <ITextView> ();
            TextDocument doc;

            if (textView != null)
            {
                doc = new TextDocument(textView.TextSnapshot.GetText())
                {
                    IsReadOnly = true,
                    MimeType   = IdeServices.DesktopService.GetMimeTypeForContentType(textView.TextBuffer.ContentType)
                };
            }
            else
            {
                doc = new TextDocument(TextFileUtility.GetText(info.Item.Path))
                {
                    IsReadOnly = true,
                    MimeType   = IdeServices.DesktopService.GetMimeTypeForUri(info.Item.Path)
                };
            }
            var options = new CustomEditorOptions(DefaultSourceEditorOptions.Instance);

            options.TabsToSpaces = false;

            editor = new MonoTextEditor(doc, new SourceEditor.StyledSourceEditorOptions(options));

            AddChild(editor);
            editor.SetScrollAdjustments(hAdjustment, vAdjustment);

            overview = new BlameRenderer(this);
            AddChild(overview);

            this.DoubleBuffered          = true;
            editor.Painted              += HandleEditorExposeEvent;
            editor.EditorOptionsChanged += delegate {
                overview.OptionsChanged();
            };
            editor.Caret.PositionChanged += ComparisonWidget.CaretPositionChanged;
            editor.FocusInEvent          += ComparisonWidget.EditorFocusIn;
            editor.Document.Folded       += delegate {
                QueueDraw();
            };
            editor.Document.FoldTreeUpdated += delegate {
                QueueDraw();
            };
            editor.DoPopupMenu = ShowPopup;
            Show();
        }
Ejemplo n.º 18
0
 public void TestCodePage858()
 {
     byte[] input = new byte[] { (byte)'/', (byte)'/', (byte)' ', 0x9D };
     Assert.AreEqual("// \u00D8", TextFileUtility.GetText(input));
 }
Ejemplo n.º 19
0
 public void TestBug4564()
 {
     byte[] input = new byte[] { (byte)'a', (byte)'a', 0xEF, 0xBB, 0xBF };
     Assert.AreEqual("aa\uFEFF", TextFileUtility.GetText(input));
 }
Ejemplo n.º 20
0
 public void TestBug1803()
 {
     // 0xA9 == (c) was the problem for UTF8
     byte[] input = new byte[] { (byte)'/', (byte)'/', (byte)' ', 0xA9 };
     Assert.AreEqual("// \u00A9", TextFileUtility.GetText(input));
 }