Changeset 450 for trunk/src/xml2struct.m


Ignore:
Timestamp:
Jun 12, 2012, 12:27:42 AM (12 years ago)
Author:
sommeria
Message:

various bugs repaired

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/xml2struct.m

    r379 r450  
    1515
    1616
    17 function out=convert_string(s)
    18 info=whos('s');
     17function out=convert_string(ss)
     18info=whos('ss');
    1919switch info.class
    2020    case 'struct'
    21         names = fieldnames(s);
     21        names = fieldnames(ss);
    2222        for k=1:length(names)
    23             out.(names{k})=convert_string(s.(names{k}));
     23            out.(names{k})=convert_string(ss.(names{k}));
    2424        end
    2525    case 'char'   
    26         if isempty(regexp(s,'^(-*\d+\.*\d*\ *)+$'))% if the string contains a set of numbers (with possible sign and decimal) separated by blanks
    27             out=s;
     26        if isempty(regexp(ss,'^(-*\d+\.*\d*\ *)+$'))% if the string does not contains a set of numbers (with possible sign and decimal) separated by blanks
     27            sep_ind=regexp(ss,'\s&\s');% check for separator ' & ' which indicates column separation in tables
     28            if ~isempty(sep_ind)
     29                sep_ind=[-2 sep_ind length(ss)+1];
     30                for icolumn=1:length(sep_ind)-1
     31                    out{1,icolumn}=ss(sep_ind(icolumn)+3:sep_ind(icolumn+1)-1);
     32                end
     33            else
     34                out=ss; %reproduce the input string
     35            end
    2836        else
    29             out=str2num(s);
     37            out=str2num(ss);
    3038        end
    3139    case 'cell'
    32         for ilist=1:numel(s)
    33             out(ilist,:)=str2num(s{ilist});
     40        for ilist=1:numel(ss)
     41            out(ilist,:)=str2num(ss{ilist});
    3442        end
    3543    otherwise
    36         out=s;
     44        out=ss;
    3745end
    3846
Note: See TracChangeset for help on using the changeset viewer.