Mercurial > octave
comparison src/strfns.cc @ 11586:12df7854fa7c
strip trailing whitespace from source files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 20 Jan 2011 17:24:59 -0500 |
parents | 7d6d8c1e471f |
children | 7a5aacf65f81 |
comparison
equal
deleted
inserted
replaced
11585:1473d0cf86d2 | 11586:12df7854fa7c |
---|---|
527 | 527 |
528 return retval; | 528 return retval; |
529 } | 529 } |
530 | 530 |
531 // If both args are arrays, dimensions may be significant. | 531 // If both args are arrays, dimensions may be significant. |
532 static bool | 532 static bool |
533 strcmp_array_op (const charNDArray& s1, const charNDArray& s2, octave_idx_type) | 533 strcmp_array_op (const charNDArray& s1, const charNDArray& s2, octave_idx_type) |
534 { | 534 { |
535 return (s1.dims () == s2.dims () | 535 return (s1.dims () == s2.dims () |
536 && std::equal (s1.data (), s1.data () + s1.numel (), s2.data ())); | 536 && std::equal (s1.data (), s1.data () + s1.numel (), s2.data ())); |
537 } | 537 } |
538 | 538 |
539 // Otherwise, just use strings. | 539 // Otherwise, just use strings. |
540 static bool | 540 static bool |
541 strcmp_str_op (const std::string& s1, const std::string& s2, | 541 strcmp_str_op (const std::string& s1, const std::string& s2, |
542 octave_idx_type) | 542 octave_idx_type) |
543 { | 543 { |
544 return s1 == s2; | 544 return s1 == s2; |
616 %!assert (all (strcmp ({'foo'}, y) == [false; false])); | 616 %!assert (all (strcmp ({'foo'}, y) == [false; false])); |
617 %!assert (all (strcmp (y, {'foo'}) == [false; false])); | 617 %!assert (all (strcmp (y, {'foo'}) == [false; false])); |
618 %!assert (all (strcmp (y, {'foo'}) == [false; false])); | 618 %!assert (all (strcmp (y, {'foo'}) == [false; false])); |
619 */ | 619 */ |
620 | 620 |
621 // Apparently, Matlab ignores the dims with strncmp. It also | 621 // Apparently, Matlab ignores the dims with strncmp. It also |
622 static bool | 622 static bool |
623 strncmp_array_op (const charNDArray& s1, const charNDArray& s2, octave_idx_type n) | 623 strncmp_array_op (const charNDArray& s1, const charNDArray& s2, octave_idx_type n) |
624 { | 624 { |
625 octave_idx_type l1 = s1.numel (), l2 = s2.numel (); | 625 octave_idx_type l1 = s1.numel (), l2 = s2.numel (); |
626 return (n > 0 && n <= l1 && n <= l2 | 626 return (n > 0 && n <= l1 && n <= l2 |
627 && std::equal (s1.data (), s1.data () + n, s2.data ())); | 627 && std::equal (s1.data (), s1.data () + n, s2.data ())); |
628 } | 628 } |
629 | 629 |
630 // Otherwise, just use strings. Note that we neither extract substrings (which | 630 // Otherwise, just use strings. Note that we neither extract substrings (which |
631 // would mean a copy, at least in GCC), nor use string::compare (which is a | 631 // would mean a copy, at least in GCC), nor use string::compare (which is a |
632 // 3-way compare). | 632 // 3-way compare). |
633 static bool | 633 static bool |
634 strncmp_str_op (const std::string& s1, const std::string& s2, octave_idx_type n) | 634 strncmp_str_op (const std::string& s1, const std::string& s2, octave_idx_type n) |
635 { | 635 { |
636 octave_idx_type l1 = s1.length (), l2 = s2.length (); | 636 octave_idx_type l1 = s1.length (), l2 = s2.length (); |
637 return (n > 0 && n <= l1 && n <= l2 | 637 return (n > 0 && n <= l1 && n <= l2 |
638 && std::equal (s1.data (), s1.data () + n, s2.data ())); | 638 && std::equal (s1.data (), s1.data () + n, s2.data ())); |
639 } | 639 } |
640 | 640 |
641 DEFUN (strncmp, args, , | 641 DEFUN (strncmp, args, , |
642 "-*- texinfo -*-\n\ | 642 "-*- texinfo -*-\n\ |
711 bool operator () (char x, char y) const | 711 bool operator () (char x, char y) const |
712 { return std::toupper (x) == std::toupper (y); } | 712 { return std::toupper (x) == std::toupper (y); } |
713 }; | 713 }; |
714 | 714 |
715 // strcmpi is equivalent to strcmp in that it checks all dims. | 715 // strcmpi is equivalent to strcmp in that it checks all dims. |
716 static bool | 716 static bool |
717 strcmpi_array_op (const charNDArray& s1, const charNDArray& s2, octave_idx_type) | 717 strcmpi_array_op (const charNDArray& s1, const charNDArray& s2, octave_idx_type) |
718 { | 718 { |
719 return (s1.dims () == s2.dims () | 719 return (s1.dims () == s2.dims () |
720 && std::equal (s1.data (), s1.data () + s1.numel (), s2.data (), | 720 && std::equal (s1.data (), s1.data () + s1.numel (), s2.data (), |
721 icmp_char_eq ())); | 721 icmp_char_eq ())); |
767 /* | 767 /* |
768 %!assert (strcmpi("abc123", "ABC123"), logical(1)); | 768 %!assert (strcmpi("abc123", "ABC123"), logical(1)); |
769 */ | 769 */ |
770 | 770 |
771 // Like strncmp. | 771 // Like strncmp. |
772 static bool | 772 static bool |
773 strncmpi_array_op (const charNDArray& s1, const charNDArray& s2, octave_idx_type n) | 773 strncmpi_array_op (const charNDArray& s1, const charNDArray& s2, octave_idx_type n) |
774 { | 774 { |
775 octave_idx_type l1 = s1.numel (), l2 = s2.numel (); | 775 octave_idx_type l1 = s1.numel (), l2 = s2.numel (); |
776 return (n > 0 && n <= l1 && n <= l2 | 776 return (n > 0 && n <= l1 && n <= l2 |
777 && std::equal (s1.data (), s1.data () + n, s2.data (), | 777 && std::equal (s1.data (), s1.data () + n, s2.data (), |
778 icmp_char_eq ())); | 778 icmp_char_eq ())); |
779 } | 779 } |
780 | 780 |
781 // Ditto. | 781 // Ditto. |
782 static bool | 782 static bool |
783 strncmpi_str_op (const std::string& s1, const std::string& s2, octave_idx_type n) | 783 strncmpi_str_op (const std::string& s1, const std::string& s2, octave_idx_type n) |
784 { | 784 { |
785 octave_idx_type l1 = s1.length (), l2 = s2.length (); | 785 octave_idx_type l1 = s1.length (), l2 = s2.length (); |
786 return (n > 0 && n <= l1 && n <= l2 | 786 return (n > 0 && n <= l1 && n <= l2 |
787 && std::equal (s1.data (), s1.data () + n, s2.data (), | 787 && std::equal (s1.data (), s1.data () + n, s2.data (), |
788 icmp_char_eq ())); | 788 icmp_char_eq ())); |
789 } | 789 } |
790 | 790 |
791 DEFUNX ("strncmpi", Fstrncmpi, args, , | 791 DEFUNX ("strncmpi", Fstrncmpi, args, , |