⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 splitcode.m

📁 M2HTML by itself generates an HTML documentation of Matlab M-files in the current directory.
💻 M
字号:
function splitc = splitcode(code)%Split a line of Matlab code in string, comment and other%  SPLITC = SPLITCODE(CODE) splits line of Matlab code CODE into a cell%  array SPLITC where each element is either a character array ('...'),%  a comment (%...), a continuation (...) or something else.%  Note that CODE = [SPLITC{:}]%%  See also M2HTML, HIGHLIGHT%  Copyright (C) 2003 Guillaume Flandin <Guillaume@artefact.tk>%  $Revision: 1.0 $Date: 2003/29/04 17:33:43 $%- Label quotes in {'transpose', 'beginstring', 'midstring', 'endstring'}iquote = findstr(code,'''');quotetransp = [double('_''.)}]') ...			   double('A'):double('Z') ...			   double('0'):double('9') ...			   double('a'):double('z')];flagstring = 0;flagdoublequote = 0;jquote = [];for i=1:length(iquote)	if ~flagstring		if iquote(i) > 1 & any(quotetransp == double(code(iquote(i)-1)))			% => 'transpose';		else			% => 'beginstring';			jquote(size(jquote,1)+1,:) = [iquote(i) length(code)];			flagstring = 1;		end	else % if flagstring		if flagdoublequote | ...		   (iquote(i) < length(code) & strcmp(code(iquote(i)+1),''''))			% => 'midstring';			flagdoublequote = ~flagdoublequote;		else			% => 'endstring';			jquote(size(jquote,1),2) = iquote(i);			flagstring = 0;		end	endend%- Find if a portion of code is a commentipercent = findstr(code,'%');jpercent = [];for i=1:length(ipercent)	if isempty(jquote) | ...	   ~any((ipercent(i) > jquote(:,1)) & (ipercent(i) < jquote(:,2)))		jpercent = [ipercent(i) length(code)];		break;	endend%- Find continuation punctuation '...'icont = findstr(code,'...');for i=1:length(icont)	if (isempty(jquote) | ...		~any((icont(i) > jquote(:,1)) & (icont(i) < jquote(:,2)))) & ...		(isempty(jpercent) | ...		icont(i) < jpercent(1))		jpercent = [icont(i) length(code)];		break;	endend%- Remove strings inside commentsif ~isempty(jpercent) & ~isempty(jquote)	jquote(find(jquote(:,1) > jpercent(1)),:) = [];end%- Split code in a cell array of stringsicode = [jquote ; jpercent];splitc = {};if isempty(icode)	splitc{1} = code;elseif icode(1,1) > 1	splitc{1} = code(1:icode(1,1)-1);endfor i=1:size(icode,1)	splitc{end+1} = code(icode(i,1):icode(i,2));	if i < size(icode,1) & icode(i+1,1) > icode(i,2) + 1		splitc{end+1} = code((icode(i,2)+1):(icode(i+1,1)-1));	elseif i == size(icode,1) & icode(i,2) < length(code)		splitc{end+1} = code(icode(i,2)+1:end);	endend

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -