~ubuntu-branches/ubuntu/trusty/psychtoolbox-3/trusty-proposed

« back to all changes in this revision

Viewing changes to Psychtoolbox/PsychOneliners/WrapString.m

  • Committer: Package Import Robot
  • Author(s): Yaroslav Halchenko
  • Date: 2013-11-19 23:34:50 UTC
  • mfrom: (3.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20131119233450-f7nf92vb8qavjmk8
Tags: 3.0.11.20131017.dfsg1-3
Upload to unsable since fresh glew has arrived to sid!

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
% 10/2/02 dgp Make it clear that maxLineLength is in characters, not pixels.
22
22
% 09/20/09 mk Improve argument handling as per suggestion of Peter April.
23
23
 
24
 
if nargin>2 || nargout>1 %#ok<OR2>
 
24
if nargin>2 || nargout>1 
25
25
        error('Usage: wrappedString=WrapString(string,[maxLineLength])\n');
26
26
end
27
27
 
29
29
    maxLineLength=[];
30
30
end
31
31
 
32
 
if isempty(maxLineLength) | isnan(maxLineLength) %#ok<OR2>
 
32
if isempty(maxLineLength) || isnan(maxLineLength)
33
33
        maxLineLength=74;
34
34
end
35
35
 
36
36
eol=sprintf('\n');
37
37
wrapped='';
38
38
while length(string)>maxLineLength
39
 
        l=min([findstr(eol,char(string)) length(string)+1]);
 
39
        l=min([strfind(char(string),eol) length(string)+1]);
40
40
        if l<maxLineLength
41
41
                % line is already short enough
42
42
                [wrapped,string]=onewrap(wrapped,string,l);
43
43
        else
44
 
                s=findstr(' ',char(string));
 
44
                s=strfind(char(string),' ');
45
45
                n=find(s<maxLineLength);
46
46
                if ~isempty(n)
47
47
                        % ignore spaces before the furthest one before maxLineLength