liangzimei / yamlmatlab

Automatically exported from code.google.com/p/yamlmatlab

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

data.(field) crashes when field has whitespace

GoogleCodeExporter opened this issue · comments

What steps will reproduce the problem?
1. import any yaml file where the field names are not valid matlab field names 
(e.g. has a space)

What is the expected output? What do you see instead?
??? Invalid field name: 'file stub'.

Error in ==> Hash2Struct at 142
                    Data.(field) = d;

Error in ==> Hash2Struct at 111
                                h2sres = Hash2Struct(hm);

Error in ==> ReadYaml>ReplaceImportByStruct at 63
        s = Hash2Struct(ymlobj);

Error in ==> ReadYaml at 38
Data = ReplaceImportByStruct(yaml_file);



What version of the product are you using? On what operating system?
0.3.2; win 7; matlab 64

Please provide any additional information below.
one fix would be to use matlab's built in genvarname;  I wrote a quick 
workaround to turn spaces into _

I put this subfuction at the end of hash2struct

function field = fixFieldName(field)
%function field = fixFieldName(field)
%replaces invalid field characters (whitespaces) with underscores

ind = regexp(field, '\s');
if (~isempty(ind))
    field(ind) = '_';
end

and replaced all instances of Data.(field) with Data.(fixFieldName(field))

additionally, line 115 needs to be revised to
if isfield(Data,fixFieldName(field))


Original issue reported on code.google.com by gers...@gmail.com on 23 Jun 2011 at 2:01

We have decided not to include the fix into new release - it is a question for 
Mathworks to implement fields with whitespaces. 

Original comment by JirkaCig...@gmail.com on 9 Sep 2011 at 7:27

Original comment by JirkaCig...@gmail.com on 9 Sep 2011 at 7:31

  • Changed state: WontFix