time | Calls | line |
---|
| | 326 | function [s, maxVarLen, colWidth] = alignTabularContents(s, colWidth)
|
| | 327 | % When the variables in a table are strings or chars, there is a
|
| | 328 | % possibility for them to be misaligned. For instance, strings
|
| | 329 | % containing hyperlinks will show up on the command window as
|
| | 330 | % possibly a different character width than what strlength()
|
| | 331 | % returns. Same for <strong> text. International characters also
|
| | 332 | % pose this problem, since the widths of Unicode characters cannot
|
| | 333 | % be guaranteed to be the same, usually causing strings containing
|
| | 334 | % international characters to be wider than ASCII text with the
|
| | 335 | % same number of characters.
|
| | 336 |
|
| | 337 | % The purpose of alignTabularContents is to check for these
|
| | 338 | % potential cases of misalignment and adjust the strings properly
|
| | 339 | % so they are as close to even as possible. wrappedLength() is used
|
| | 340 | % to accurately obtain the display width of each line of text. For
|
| | 341 | % the case of international characters, it is impossible to line
|
| | 342 | % them up exactly due to them being non-integral character lengths.
|
| | 343 | % Thus, the remainder is tracked to ensure they are aligned within
|
| | 344 | % 1 character of other ASCII lines.
|
| | 345 |
|
| | 346 | % alignTabularContents is used to align table variables that are
|
| | 347 | % nx1 strings or multi-column table variables to ensure that each
|
| | 348 | % sub-column of a table variable is aligned properly, before that
|
| | 349 | % variable is aligned with other variables in the table.
|
| | 350 |
|
< 0.001 | 8 | 351 | if nargin < 2
|
| | 352 | [rows, cols] = size(s);
|
| | 353 | colWidth = zeros(rows,1);
|
< 0.001 | 8 | 354 | else
|
| | 355 | %rows = size(s,1);
|
< 0.001 | 8 | 356 | cols = 1;
|
< 0.001 | 8 | 357 | end
|
| | 358 |
|
0.003 | 8 | 359 | tagged = containsRegexp(s,'<a\s+href\s*=|<strong>');
|
< 0.001 | 8 | 360 | varLengthM = strlength(s);
|
< 0.001 | 8 | 361 | for idx = 1:numel(s)
|
0.001 | 800 | 362 | tagged(idx) = tagged(idx) || any(s{idx} > char(128));
|
< 0.001 | 800 | 363 | end
|
0.002 | 8 | 364 | varLengthM(tagged) = vectorizedWrappedLength(s(tagged));
|
< 0.001 | 8 | 365 | for c=1:cols
|
< 0.001 | 8 | 366 | varLength = varLengthM(:,c);
|
< 0.001 | 8 | 367 | maxVarLen = max(ceil(varLength));
|
< 0.001 | 8 | 368 | postPadLen = maxVarLen - varLength;
|
< 0.001 | 8 | 369 | colWidth = colWidth + (postPadLen - floor(postPadLen));
|
< 0.001 | 8 | 370 | tooLong = colWidth > 1;
|
< 0.001 | 8 | 371 | colWidth(tooLong) = colWidth(tooLong) - 1;
|
< 0.001 | 8 | 372 | postPadLen(tooLong) = postPadLen(tooLong) +1;
|
< 0.001 | 8 | 373 | ppI = floor(postPadLen);
|
< 0.001 | 8 | 374 | for r = 1:max(ppI)
|
| | 375 | % add the spaces in place to improve performance
|
0.002 | 80 | 376 | s(ppI >= r,c) = s(ppI >= r,c) + " ";
|
< 0.001 | 80 | 377 | end
|
< 0.001 | 8 | 378 | end
|
< 0.001 | 8 | 379 | end
|
Other subfunctions in this file are not included in this listing.