Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dseries
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sébastien Villemot
dseries
Commits
04547e32
Verified
Commit
04547e32
authored
Sep 18, 2019
by
Sébastien Villemot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Compatibility fix: strsplit and strjoin were introduced in MATLAB R2013a
Provide alternative implementations, taken from Dynare.
parent
628b0356
Pipeline
#1870
passed with stage
in 1 minute and 33 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
223 additions
and
0 deletions
+223
-0
src/initialize_dseries_class.m
src/initialize_dseries_class.m
+8
-0
src/utilities/missing/strjoin/strjoin.m
src/utilities/missing/strjoin/strjoin.m
+63
-0
src/utilities/missing/strsplit/private/ischarint.m
src/utilities/missing/strsplit/private/ischarint.m
+27
-0
src/utilities/missing/strsplit/private/ischarnum.m
src/utilities/missing/strsplit/private/ischarnum.m
+35
-0
src/utilities/missing/strsplit/strsplit.m
src/utilities/missing/strsplit/strsplit.m
+90
-0
No files found.
src/initialize_dseries_class.m
View file @
04547e32
...
...
@@ -124,6 +124,14 @@ if ~exist('iscolumn','file')
p
{
end
+
1
}
=
'utilities/missing/iscolumn'
;
end
if
~
exist
(
'strsplit'
,
'file'
)
p
{
end
+
1
}
=
'utilities/missing/strsplit'
;
end
if
~
exist
(
'strjoin'
,
'file'
)
p
{
end
+
1
}
=
'utilities/missing/strjoin'
;
end
% Set path
P
=
cellfun
(
@
(
c
)[
dseries_src_root
c
],
p
,
'uni'
,
false
);
addpath
(
P
{:});
...
...
src/utilities/missing/strjoin/strjoin.m
0 → 100644
View file @
04547e32
function
rval
=
strjoin
(
cstr
,
delimiter
)
% Adapted from Octave's implementation of strjoin
%
% Limitation: escaped characters (e.g. '\n') in delimiters will not be
% interpreted as the characters they represent.
% Copyright (C) 2013-2019 Ben Abbott
% Copyright (C) 2007 Muthiah Annamalai
% Copyright (C) 2019 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if
nargin
==
1
delimiter
=
' '
;
elseif
nargin
<
1
||
nargin
>
2
error
(
'strjoin: must have either one or two arguments'
)
end
if
~
(
iscellstr
(
cstr
)
&&
(
ischar
(
delimiter
)
||
iscellstr
(
delimiter
)))
error
(
'strjoin: first argument must be a cell array, second array either a char array or a cell array'
)
end
if
numel
(
cstr
)
==
1
rval
=
cstr
{
1
};
return
;
end
if
ischar
(
delimiter
)
% There is no equivalent to do_string_escapes in MATLAB
%delimiter = do_string_escapes(delimiter);
delimiter
=
{
delimiter
};
end
num
=
numel
(
cstr
);
if
numel
(
delimiter
)
==
1
&&
num
>
1
delimiter
=
repmat
(
delimiter
,
1
,
num
);
delimiter
(
end
)
=
{
''
};
elseif
num
>
0
&&
numel
(
delimiter
)
~=
num
-
1
error
(
'strjoin: the number of delimiters does not match the number of strings'
);
else
delimiter
(
end
+
1
)
=
{
''
};
end
if
num
==
0
rval
=
''
;
else
tmp
=
[
cstr
(:)
.
'; delimiter(:).'
];
rval
=
[
tmp
{:}];
end
src/utilities/missing/strsplit/private/ischarint.m
0 → 100644
View file @
04547e32
function
l
=
ischarint
(
x
)
% Returns true if and only if char x represents an integer.
% Copyright © 2018 DynareTeam
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
s
=
warning
;
warning
off
;
l
=
isint
(
str2double
(
x
));
warning
(
s
);
\ No newline at end of file
src/utilities/missing/strsplit/private/ischarnum.m
0 → 100644
View file @
04547e32
function
l
=
ischarnum
(
x
)
% Returns true if and only if char x represents a real number.
% Copyright © 2018 DynareTeam
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
l
=
false
;
s
=
warning
;
warning
off
;
number
=
str2double
(
x
);
warning
(
s
);
if
~
isempty
(
number
)
if
isreal
(
number
)
l
=
true
;
end
end
\ No newline at end of file
src/utilities/missing/strsplit/strsplit.m
0 → 100644
View file @
04547e32
function
tok
=
strsplit
(
str
,
delimiters
)
% Splits a string into multiple terms.
%
% INPUTS
% - str [char] String to be splitted.
% - delimiters [char, cell(char)] Delimiters.
%
% OUTPUTS
% - tok [cell(char)] Terms.
% Copyright © 2018 DynareTeam
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
remove_empty
=
true
;
remove_numbers
=
false
;
% Check first input arguments
assert
(
ischar
(
str
)
&&
ndims
(
str
)
==
2
&&
size
(
str
,
1
)
<=
1
,
'The first arugment has to be a row char array!'
);
% Set default value for second input arguments
if
nargin
<
2
delimiters
=
{
' '
};
end
% If second input argument is a char transform it into a sigleton cell of char
if
nargin
>
1
if
ischar
(
delimiters
)
assert
(
ndims
(
delimiters
)
==
2
&&
size
(
delimiters
,
1
)
==
1
,
'The second input argument has to be be a char string!'
);
delimiters
=
{
delimiters
};
end
end
% Check that `delimiters` is a one dimensional cell
assert
(
ndim
(
delimiters
)
<=
1
,
'The second input argument has to be a one dimensional cell array!'
)
% Check that `delimiters` is a cell of row char arrays
assert
(
all
(
cellfun
(
@
ischar
,
delimiters
))
&&
all
(
cellfun
(
@
rows
,
delimiters
)
==
1
),
'The second input argument has to be a cell of row char arrays!'
)
% If space is one of the delimiters obtain the index in `delimiters`
idspace
=
strmatch
(
' '
,
delimiters
);
% Get the number of delimiters
n
=
length
(
delimiters
);
% Remove unnecessary spaces
delimiters
(
setdiff
(
1
:
n
,
idspace
))
=
strtrim
(
delimiters
(
setdiff
(
1
:
n
,
idspace
)));
% Join all the delimiters (strjoin is not available with matlab version less than R2013a)
if
n
>
1
delimiter
=
''
;
for
i
=
1
:
n
if
isspace
(
delimiters
{
i
})
delimiter
=
horzcat
(
delimiter
,
'\s'
);
else
delimiter
=
horzcat
(
delimiter
,
delimiters
{
i
});
end
delimiter
=
horzcat
(
delimiter
,
'|'
);
end
delimiter
=
horzcat
(
delimiter
,
'\W'
);
else
delimiter
=
delimiters
{
1
};
end
% Get tokens
tok
=
regexp
(
str
,
delimiter
,
'split'
);
if
remove_empty
% Remove empty tokens
tok
=
tok
(
find
(
~
cellfun
(
@
isempty
,
tok
)));
end
if
remove_numbers
% Remove numbers
tok
=
tok
(
find
(
~
cellfun
(
@
ischarnum
,
tok
)));
end
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment