Skip to content

BUG: Matlab - reading toml file encoutering error message. #31

@inwoo-park

Description

@inwoo-park

Hi Developer,

Thank you for your great works on reading toml file using matlab.

Problem

When I use your project for reading "*.toml" file, I encounter the error as follows

>> fname = 'example.toml';
>> decode(fname);
Error: File: TOML_MATLAB_ROOT/toml/private/consume_comment.m Line: 10 Column:
40
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax
error. To construct matrices, use brackets instead of parentheses.

Error in decode (line 17)
    toml_str = consume_comment(toml_str);

A Line 10 in consume_comment.m contains char(0xD). My current matlab version is 2018a. It seems that matlab version is not a source of problem.

What is meaing of char(0xD)? It seems that you convert the ASCII digit to text format (https://www.programming-algorithms.net/article/40286/ASCII-table).
For example, 0xD means CR(Carriage Return) in text.

if c == newline || (c == char(0xD) && idx < numel(out) && out(idx+1) == newline)

Solution

I find a solution for above problem.

It seems that function hex2dec in matlab (version < R2020a) does not support prefix 0x. For example, hex2dec('0xFF') is equal to hex2dec('FF').

hex2dec('FF') # supported since R2006a
hex2dec('0xFF') # supported since R2020a

Finally, the code should be changed to

if c == newline || (c == char(hex2dec('D')) && idx < numel(out) && out(idx+1) == newline)

Best regards,
Inwoo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions