Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


NextString.m

Go to the documentation of this file.
00001 function [err, Cnext, cend] = NextString (C, Delim, cpos, Opt)
00002 %
00003 %   [err,Cnext, cend] = NextString (C, Delim, cpos, Opt)
00004 %
00005 %Purpose:
00006 %   gets the next string in charachter array C that is delimited by Delim
00007 %   
00008 %   
00009 %Input Parameters:
00010 %   C : a character array
00011 %   Delim : delimitation character, see FindChar for special characters
00012 %      Note that Delim is included in Cnext
00013 %   cpos : position to start from in C ( cpos >=1 )
00014 %  Opt optional options structure with the following fields
00015 %    .Deblank (0/1) default 0, removes trailing white spaces (tab, newline, formfeed).
00016 %
00017 %Output Parameters:
00018 %   err : 0 No Problem
00019 %       : 1 Mucho Problems
00020 %       Cnext : C(pos:'location of next Delim')   
00021 %  cend is such that Cnext = C(cpos:cend);
00022 %   Warning : cend is not affected for Deblanking, the equality on
00023 %      the previous line is before deblanking is done on Cnext
00024 %      
00025 %More Info :
00026 %   FindChar
00027 %   SkipMatlabHelp
00028 %   PurgeComments
00029 %
00030 % example
00031 % ks = sprintf ('I am hyper, Yes Oh Yes I am.\nHow about You\tLaddy. Are You hyper ?\n')
00032 % [err, Cnext, cend] = NextString (ks,'.',1)
00033 % or 
00034 % [err, Cnext, cend] = NextString (ks,'.',29)
00035 % [err, Cnext, cend] = NextString (ks,'?',29)
00036 % or 
00037 % [err, Cnext, cend] = NextString (ks,'v',1)
00038 % or
00039 % [err, Cnext, cend] = NextString (ks,',',1)
00040 % [err, Cnext, cend] = NextString (ks,',',12)
00041 % or
00042 % [err, Cnext, cend] = NextString (ks,'NewLine',1)
00043 % [err, Cnext, cend] = NextString (ks,'Space',1)
00044 %
00045 % You get the idea right ?
00046 %
00047 %     Author : Ziad Saad
00048 %     Date : Sat Mar 27 14:38:45 CST 1999 
00049 
00050 
00051 %Define the function name for easy referencing
00052 FuncName = 'NextString';
00053 
00054 %Debug Flag
00055 DBG = 1;
00056 
00057 if (nargin == 3),
00058         Opt.Deblank = 0;
00059 end
00060 
00061 if (~isfield(Opt,'Deblank') | isempty(Opt.Deblank)), Opt.Deblank = 0; end
00062 
00063 %initailize return variables
00064 err = 1;
00065 Cnext = '';
00066 
00067 nC = length(C);
00068 
00069 if (cpos > nC),
00070         err = ErrEval(FuncName,'Err_cpos > length(C)');
00071         return;
00072 end
00073 
00074 [err, Loc] = FindChar (C(cpos:nC), Delim);
00075 
00076 if (isempty(Loc)),
00077         cend = nC-cpos;
00078 else
00079         switch Delim
00080                 case 'NewLine',
00081                         offset = -1;
00082                 case '\n',
00083                         offset = -1;
00084                 case 'Tab',
00085                         offset = -1;    
00086                 case '\t',
00087                         offset = -1;
00088                 case 'Space',
00089                         offset = -1;
00090                 case ' ',
00091                         offset = -1;
00092                 otherwise,
00093                         offset = -1;
00094         end
00095         cend = Loc(1)+cpos+ offset;
00096 end
00097 
00098 Cnext = C(cpos:cend);
00099 nCnext = length(Cnext);
00100 
00101 if (Opt.Deblank & nCnext),
00102         ispc = isspace(Cnext);
00103         if (sum(ispc) == length(ispc)),
00104                 %all space
00105                 Cnext = '';
00106         else
00107                 %get ridd of first blanks
00108                 cnt = 1;
00109                 while (ispc(cnt)),
00110                         cnt = cnt + 1;
00111                 end
00112                 cnt2 = nCnext;
00113                 while (ispc(cnt2)),
00114                         cnt2 = cnt2 - 1;
00115                 end
00116                 Cnext = Cnext(cnt:cnt2);
00117         end
00118 end
00119 
00120 err = 0;
00121 return;
00122 
00123 
00124 
 

Powered by Plone

This site conforms to the following standards: