Skip to content

Commit

Permalink
completely reformat m-files using miss_hit
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Nov 8, 2023
1 parent 3ff781f commit 33263de
Show file tree
Hide file tree
Showing 53 changed files with 4,312 additions and 4,329 deletions.
7 changes: 7 additions & 0 deletions .miss_hit
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
project_root

suppress_rule: "redundant_brackets"
suppress_rule: "line_length"
suppress_rule: "file_length"
suppress_rule: "copyright_notice"
suppress_rule: "naming_functions"
suppress_rule: "naming_parameters"
suppress_rule: "naming_scripts"
suppress_rule: "unicode"
indent_function_file_body: false
21 changes: 10 additions & 11 deletions base64decode.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
% output = base64decode(input)
%
% Decoding a Base64-encoded byte-stream to recover the original data
% This function depends on JVM in MATLAB or, can optionally use the ZMat
% This function depends on JVM in MATLAB or, can optionally use the ZMat
% toolbox (http://github.com/NeuroJSON/zmat)
%
% Copyright (c) 2012, Kota Yamaguchi
Expand All @@ -22,28 +22,27 @@
% orig=char(base64decode(bytes))
%
% license:
% BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
% BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%

if(nargin==0)
if (nargin == 0)
error('you must provide at least 1 input');
end
if(exist('zmat','file')==2 || exist('zmat','file')==3)
output=zmat(varargin{1},0,'base64');
return;
elseif(isoctavemesh)
if (exist('zmat', 'file') == 2 || exist('zmat', 'file') == 3)
output = zmat(varargin{1}, 0, 'base64');
return
elseif (isoctavemesh)
error('You must install the ZMat toolbox (http://github.com/NeuroJSON/zmat) to use this function in Octave');
end

error(javachk('jvm'));

if(ischar(varargin{1}))
varargin{1}=uint8(varargin{1});
if (ischar(varargin{1}))
varargin{1} = uint8(varargin{1});
end

input=typecast(varargin{1}(:)','uint8');
input = typecast(varargin{1}(:)', 'uint8');

output = typecast(org.apache.commons.codec.binary.Base64.decodeBase64(input), 'uint8')';

24 changes: 12 additions & 12 deletions base64encode.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
%
% Encoding a binary vector or array using Base64
%
% This function depends on JVM in MATLAB or, can optionally use the ZMat
% This function depends on JVM in MATLAB or, can optionally use the ZMat
% toolbox (http://github.com/NeuroJSON/zmat)
%
% Copyright (c) 2012, Kota Yamaguchi
Expand All @@ -23,29 +23,29 @@
% orig=char(base64decode(bytes))
%
% license:
% BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
% BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
%
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
%

if(nargin==0)
if (nargin == 0)
error('you must provide at least 1 input');
end

if(exist('zmat','file')==2 || exist('zmat','file')==3)
[varargout{1:nargout}]=zmat(varargin{1}, 1,'base64',varargin{2:end});
return;
if (exist('zmat', 'file') == 2 || exist('zmat', 'file') == 3)
[varargout{1:nargout}] = zmat(varargin{1}, 1, 'base64', varargin{2:end});
return
end

if(ischar(varargin{1}))
varargin{1}=uint8(varargin{1});
if (ischar(varargin{1}))
varargin{1} = uint8(varargin{1});
end

input=typecast(varargin{1}(:)','uint8');
input = typecast(varargin{1}(:)', 'uint8');

if(isoctavemesh)
if (isoctavemesh)
varargout{1} = base64_encode(uint8(input));
return;
return
end

error(javachk('jvm'));
Expand All @@ -54,4 +54,4 @@
end

varargout{1} = char(org.apache.commons.codec.binary.Base64.encodeBase64Chunked(input))';
varargout{1} = regexprep(varargout{1} ,'\r','');
varargout{1} = regexprep(varargout{1}, '[\r\n]', '');
70 changes: 35 additions & 35 deletions decodevarname.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function newname = decodevarname(name,varargin)
function newname = decodevarname(name, varargin)
%
% newname = decodevarname(name)
%
Expand All @@ -16,61 +16,61 @@
% letter into "x0xHH_" and non-ascii letters into "_0xHH_"
% format, where hex key HH stores the ascii (or Unicode) value
% of the character.
%
%
% output:
% newname: the restored original string
%
% example:
% decodevarname('x0x5F_a') % returns _a
% decodevarname('a_') % returns a_ as it is a valid variable name
% decodevarname('x0xE58F98__0xE9878F_') % returns '变量'
% decodevarname('x0xE58F98__0xE9878F_') % returns '变量'
%
% this file is part of EasyH5 Toolbox: https://github.com/NeuroJSON/easyh5
%
% License: GPLv3 or 3-clause BSD license, see https://github.com/NeuroJSON/easyh5 for details
%

newname=name;
isunpack=1;
if(nargin==2 && ~isstruct(varargin{1}))
isunpack=varargin{1};
elseif(nargin>1)
isunpack=jsonopt('UnpackHex',1,varargin{:});
newname = name;
isunpack = 1;
if (nargin == 2 && ~isstruct(varargin{1}))
isunpack = varargin{1};
elseif (nargin > 1)
isunpack = jsonopt('UnpackHex', 1, varargin{:});
end

if(isunpack)
if(isempty(strfind(name, '0x')) || isempty(regexp(name,'0x([0-9a-fA-F]+)_','once')))
if (isunpack)
if (isempty(strfind(name, '0x')) || isempty(regexp(name, '0x([0-9a-fA-F]+)_', 'once')))
return
end
if(exist('native2unicode','builtin'))
h2u=@hex2unicode;
newname=regexprep(name,'(^x|_){1}0x([0-9a-fA-F]+)_','${h2u($2)}');
if (exist('native2unicode', 'builtin'))
h2u = @hex2unicode;
newname = regexprep(name, '(^x|_){1}0x([0-9a-fA-F]+)_', '${h2u($2)}');
else
if(isunpack && strcmp(name,'x0x0_'))
newname='';
return;
if (isunpack && strcmp(name, 'x0x0_'))
newname = '';
return
end
pos=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','start');
pend=regexp(name,'(^x|_){1}0x([0-9a-fA-F]+)_','end');
if(isempty(pos))
return;
pos = regexp(name, '(^x|_){1}0x([0-9a-fA-F]+)_', 'start');
pend = regexp(name, '(^x|_){1}0x([0-9a-fA-F]+)_', 'end');
if (isempty(pos))
return
end
str0=name;
pos0=[0 pend(:)' length(name)];
newname='';
for i=1:length(pos)
newname=[newname str0(pos0(i)+1:pos(i)-1) char(hex2dec(str0(pos(i)+3:pend(i)-1)))];
str0 = name;
pos0 = [0 pend(:)' length(name)];
newname = '';
for i = 1:length(pos)
newname = [newname str0(pos0(i) + 1:pos(i) - 1) char(hex2dec(str0(pos(i) + 3:pend(i) - 1)))];
end
if(pos(end)~=length(name))
newname=[newname str0(pos0(end-1)+1:pos0(end))];
if (pos(end) ~= length(name))
newname = [newname str0(pos0(end - 1) + 1:pos0(end))];
end
end
end

%--------------------------------------------------------------------------
function str=hex2unicode(hexstr)
val=hex2dec(hexstr);
id=histc(val,[0 2^8 2^16 2^32 2^64]);
type={'uint8','uint16','uint32','uint64'};
bytes=typecast(cast(val,type{id~=0}),'uint8');
str=native2unicode(fliplr(bytes(:,1:find(bytes,1,'last'))));
% --------------------------------------------------------------------------
function str = hex2unicode(hexstr)
val = hex2dec(hexstr);
id = histc(val, [0 2^8 2^16 2^32 2^64]);
type = {'uint8', 'uint16', 'uint32', 'uint64'};
bytes = typecast(cast(val, type{id ~= 0}), 'uint8');
str = native2unicode(fliplr(bytes(:, 1:find(bytes, 1, 'last'))));
57 changes: 28 additions & 29 deletions encodevarname.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function str = encodevarname(str,varargin)
function str = encodevarname(str, varargin)
%
% newname = encodevarname(name)
%
% Encode an invalid variable name using a hex-format for bi-directional
% conversions.
% conversions.

% This function is sensitive to the default charset
% settings in MATLAB, please call feature('DefaultCharacterSet','utf8')
Expand All @@ -20,7 +20,7 @@
% format, where HH is the ascii (or Unicode) value of the
% character.
%
% if the encoded variable name CAN NOT be longer than 63, i.e.
% if the encoded variable name CAN NOT be longer than 63, i.e.
% the maximum variable name specified by namelengthmax, and
% one uses the output of this function as a struct or variable
% name, the name will be truncated at 63. Please consider using
Expand All @@ -30,39 +30,38 @@
% example:
% encodevarname('_a') % returns x0x5F_a
% encodevarname('a_') % returns a_ as it is a valid variable name
% encodevarname('变量') % returns 'x0xE58F98__0xE9878F_'
% encodevarname('变量') % returns 'x0xE58F98__0xE9878F_'
%
% this file is part of EasyH5 Toolbox: https://github.com/NeuroJSON/easyh5
%
% License: GPLv3 or 3-clause BSD license, see https://github.com/NeuroJSON/easyh5 for details
%

if(~isvarname(str(1)))
if(exist('unicode2native','builtin'))
str=sprintf('x0x%s_%s',sprintf('%X',unicode2native(str(1))),str(2:end));
else
str=sprintf('x0x%X_%s',char(str(1))+0,str(2:end));
end
if (~isvarname(str(1)))
if (exist('unicode2native', 'builtin'))
str = sprintf('x0x%s_%s', sprintf('%X', unicode2native(str(1))), str(2:end));
else
str = sprintf('x0x%X_%s', char(str(1)) + 0, str(2:end));
end
if(isvarname(str))
return;
end
if (isvarname(str))
return
end
if (exist('unicode2native', 'builtin'))
str = regexprep(str, '([^0-9A-Za-z_])', '_0x${sprintf(''%X'',unicode2native($1))}_');
else
cpos = find(~ismember(str, ['0':'9', 'A':'Z', 'a':'z', '_']));
% cpos=regexp(str,'[^0-9A-Za-z_]');
if (isempty(cpos))
return
end
if(exist('unicode2native','builtin'))
str=regexprep(str,'([^0-9A-Za-z_])','_0x${sprintf(''%X'',unicode2native($1))}_');
else
cpos=find(~ismember(str, ['0':'9','A':'Z','a':'z','_']));
%cpos=regexp(str,'[^0-9A-Za-z_]');
if(isempty(cpos))
return;
end
str0=str;
pos0=[0 cpos(:)' length(str)];
str='';
for i=1:length(cpos)
str=[str str0(pos0(i)+1:cpos(i)-1) sprintf('_0x%X_',str0(cpos(i))+0)];
end
if(cpos(end)~=length(str))
str=[str str0(pos0(end-1)+1:pos0(end))];
end
str0 = str;
pos0 = [0 cpos(:)' length(str)];
str = '';
for i = 1:length(cpos)
str = [str str0(pos0(i) + 1:cpos(i) - 1) sprintf('_0x%X_', str0(cpos(i)) + 0)];
end
if (cpos(end) ~= length(str))
str = [str str0(pos0(end - 1) + 1:pos0(end))];
end
end
Loading

0 comments on commit 33263de

Please sign in to comment.