Mercurial > octave
comparison scripts/miscellaneous/inputParser.m @ 30379:363fb10055df stable
maint: Style check m-files ahead of 7.1 release.
* Map.m, integral3.m, logspace.m, quad2d.m, quadgk.m, quadl.m, tsearchn.m,
get_first_help_sentence.m, print_usage.m, getframe.m, imformats.m,
javaclasspath.m, condest.m, null.m, ordeig.m, inputParser.m, license.m,
memory.m, methods.m, __publish_html_output__.m, __publish_latex_output__.m,
publish.m, ode15s.m, fminbnd.m, fzero.m, configure_make.m, get_description.m,
get_forge_pkg.m, annotation.m, camlookat.m, legend.m, __gnuplot_legend__.m,
bar.m, colorbar.m, fill3.m, isosurface.m, plotyy.m, polar.m, __bar__.m,
__ezplot__.m, __patch__.m, __pie__.m, __plt__.m, __scatter__.m, smooth3.m,
stemleaf.m, __gnuplot_drawnow__.m, print.m, printd.m, __add_default_menu__.m,
__gnuplot_draw_axes__.m, __gnuplot_print__.m, __print_parse_opts__.m,
struct2hdl.m, profexport.m, profile.m, movfun.m, sprandsym.m, betaincinv.m,
factor.m, nchoosek.m, gallery.m, hadamard.m, iqr.m, ranks.m,
__run_test_suite__.m, test.m, datevec.m, weboptions.m:
Style check m-files ahead of 7.1 release.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 26 Nov 2021 20:53:22 -0800 |
parents | 212461a26e9c |
children | 796f54d4ddbf |
comparison
equal
deleted
inserted
replaced
30377:26f2daafa270 | 30379:363fb10055df |
---|---|
504 this.add_missing ("Switch"); | 504 this.add_missing ("Switch"); |
505 | 505 |
506 endfunction | 506 endfunction |
507 | 507 |
508 function disp (this) | 508 function disp (this) |
509 | |
509 if (nargin != 1) | 510 if (nargin != 1) |
510 print_usage (); | 511 print_usage (); |
511 endif | 512 endif |
512 printf ("inputParser object with properties:\n\n"); | 513 printf ("inputParser object with properties:\n\n"); |
513 b2s = @(x) ifelse (any (x), "true", "false"); | 514 b2s = @(x) ifelse (any (x), "true", "false"); |
517 b2s (this.CaseSensitive), b2s (this.FunctionName), | 518 b2s (this.CaseSensitive), b2s (this.FunctionName), |
518 b2s (this.KeepUnmatched), b2s (this.PartialMatching), | 519 b2s (this.KeepUnmatched), b2s (this.PartialMatching), |
519 b2s (this.StructExpand)); | 520 b2s (this.StructExpand)); |
520 printf ("Defined parameters:\n\n {%s}\n", | 521 printf ("Defined parameters:\n\n {%s}\n", |
521 strjoin (this.Parameters, ", ")); | 522 strjoin (this.Parameters, ", ")); |
523 | |
522 endfunction | 524 endfunction |
523 | 525 |
524 endmethods | 526 endmethods |
525 | 527 |
526 methods (Access = private) | 528 methods (Access = private) |
527 | 529 |
528 function validate_name (this, type, name) | 530 function validate_name (this, type, name) |
531 | |
529 if (! isvarname (name)) | 532 if (! isvarname (name)) |
530 error ("inputParser.add%s: NAME is an invalid identifier", method); | 533 error ("inputParser.add%s: NAME is an invalid identifier", method); |
531 elseif (any (strcmpi (this.Parameters, name))) | 534 elseif (any (strcmpi (this.Parameters, name))) |
532 ## Even if CaseSensitive is "on", we still shouldn't allow | 535 ## Even if CaseSensitive is "on", we still shouldn't allow |
533 ## two args with the same name. | 536 ## two args with the same name. |
534 error ("inputParser.add%s: argname '%s' has already been specified", | 537 error ("inputParser.add%s: argname '%s' has already been specified", |
535 type, name); | 538 type, name); |
536 endif | 539 endif |
537 this.Parameters{end+1} = name; | 540 this.Parameters{end+1} = name; |
541 | |
538 endfunction | 542 endfunction |
539 | 543 |
540 function validate_arg (this, name, val, in) | 544 function validate_arg (this, name, val, in) |
541 if (! val (in)) | 545 |
542 this.error (sprintf ("failed validation of %s with %s", | 546 if (! val (in)) |
543 toupper (name), func2str (val))); | 547 this.error (sprintf ("failed validation of %s with %s", |
544 endif | 548 toupper (name), func2str (val))); |
545 this.Results.(name) = in; | 549 endif |
550 this.Results.(name) = in; | |
551 | |
546 endfunction | 552 endfunction |
547 | 553 |
548 function r = is_argname (this, type, name) | 554 function r = is_argname (this, type, name) |
555 | |
549 r = ischar (name) && isrow (name); | 556 r = ischar (name) && isrow (name); |
550 if (r) | 557 if (r) |
551 if (this.CaseSensitive) | 558 if (this.CaseSensitive) |
552 r = isfield (this.(type), name); | 559 r = isfield (this.(type), name); |
553 if (r) | 560 if (r) |
560 if (r) | 567 if (r) |
561 this.last_name = fnames{l}; | 568 this.last_name = fnames{l}; |
562 endif | 569 endif |
563 endif | 570 endif |
564 endif | 571 endif |
572 | |
565 endfunction | 573 endfunction |
566 | 574 |
567 function add_missing (this, type) | 575 function add_missing (this, type) |
576 | |
568 unmatched = setdiff (fieldnames (this.(type)), fieldnames (this.Results)); | 577 unmatched = setdiff (fieldnames (this.(type)), fieldnames (this.Results)); |
569 for namec = unmatched(:)' | 578 for namec = unmatched(:)' |
570 name = namec{1}; | 579 name = namec{1}; |
571 this.UsingDefaults{end+1} = name; | 580 this.UsingDefaults{end+1} = name; |
572 this.Results.(name) = this.(type).(name).def; | 581 this.Results.(name) = this.(type).(name).def; |
573 endfor | 582 endfor |
583 | |
574 endfunction | 584 endfunction |
575 | 585 |
576 function error (this, msg) | 586 function error (this, msg) |
587 | |
577 where = ""; | 588 where = ""; |
578 if (this.FunctionName) | 589 if (this.FunctionName) |
579 where = [this.FunctionName ": "]; | 590 where = [this.FunctionName ": "]; |
580 endif | 591 endif |
581 error ("%s%s", where, msg); | 592 error ("%s%s", where, msg); |
593 | |
582 endfunction | 594 endfunction |
583 | 595 |
584 endmethods | 596 endmethods |
585 | 597 |
586 endclassdef | 598 endclassdef |