question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to change text encoding post-parse

See original GitHub issue

So right now if you need to try and handle multiple midi files of various text encodings at runtime you are somewhat out of luck and would need to continuously re-parse the whole midi until the correct encoding is found.

Going from this:

public string Text { get; set; }
protected sealed override void ReadContent(MidiReader reader, ReadingSettings settings, int size)
{
    ThrowIfArgument.IsNegative(nameof(size), size,
            "Text event cannot be read since the size is negative number.");

    if (size == 0)
        return;

    textData = reader.ReadBytes(size);
    var encoding = settings.TextEncoding ?? SmfUtilities.DefaultEncoding;
    Text = encoding.GetString(bytes);
}

to something like this (this isnt 100% working code but just something to get an idea of what i’m saying here)

protected byte[] _textData = null;
protected string _textEncoded;

public string Text
{
    get
    {
        if (_textData != null)
        {
            var encoding = settings.TextEncoding ?? SmfUtilities.DefaultEncoding;
            _textEncoded = encoding.GetString(_textData);
            return _textEncoded;

        }
        else
        {
            return _textEncoded;
        }
    }
    set => _textEncoded = value;
}

protected sealed override void ReadContent(MidiReader reader, ReadingSettings settings, int size)
{
    ThrowIfArgument.IsNegative(nameof(size), size, "Text event cannot be read since the size is negative number.");

    if (size == 0)
        return;

    _textData = reader.ReadBytes(size);
}

It would need some other api changes perhaps with how settings and/or encodings are handled.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
melanchallcommented, Jul 5, 2019

I’ve added DecodeTextCallback property to ReadingSettings.

0reactions
melanchallcommented, Jun 30, 2019

@mdsitton So is it good to have text parsing callback?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I correct the character encoding of a file?
1- Copy the original text · 2- In Notepad++, open new file, change Encoding -> pick an encoding you think the original text...
Read more >
Choose text encoding when you open and save files
In the File Conversion dialog box, select Other encoding, and then select the encoding standard that you want from the list.
Read more >
How do I change the character encoding for a webpage ...
Manual encoding switching may be able to be done by use of Chrome extensions. Marked as best answer by Kameron M - Community...
Read more >
Problem with special character encoding (Possibly Latin1)
Solved: Hi there, So, I got a database that possibly has a Latin1 encoding for the text fields. I say possibly because it's...
Read more >
Change character encoding after a file has been opened
Being able to change character encoding after a file has been loaded or a new buffer created. (Have to work with a lot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found