| 694 */ |
694 */ |
| 695 CX_EXTERN CX_NODISCARD |
695 CX_EXTERN CX_NODISCARD |
| 696 cxstring cx_strrchr_(cxstring string, int chr); |
696 cxstring cx_strrchr_(cxstring string, int chr); |
| 697 |
697 |
| 698 #ifdef __cplusplus |
698 #ifdef __cplusplus |
| 699 CX_CPPDECL cxstring cx_strchr(cxstring string, int chr) { |
699 CX_CPPDECL cxstring cx_strchr_cpp(cxstring string, int chr) { |
| 700 return cx_strchr_(string, chr); |
700 return cx_strchr_(string, chr); |
| 701 } |
701 } |
| 702 CX_CPPDECL cxmutstr cx_strchr(cxmutstr string, int chr) { |
702 CX_CPPDECL cxmutstr cx_strchr_cpp(cxmutstr string, int chr) { |
| 703 return cx_mutstrcast(cx_strchr_(cx_strcast(string), chr)); |
703 return cx_mutstrcast(cx_strchr_(cx_strcast(string), chr)); |
| 704 } |
704 } |
| 705 CX_CPPDECL cxstring cx_strrchr(cxstring string, int chr) { |
705 #define cx_strchr(s, chr) cx_strchr_cpp(cx_strcast_m(s), chr) |
| |
706 CX_CPPDECL cxstring cx_strrchr_cpp(cxstring string, int chr) { |
| 706 return cx_strrchr_(string, chr); |
707 return cx_strrchr_(string, chr); |
| 707 } |
708 } |
| 708 CX_CPPDECL cxmutstr cx_strrchr(cxmutstr string, int chr) { |
709 CX_CPPDECL cxmutstr cx_strrchr_cpp(cxmutstr string, int chr) { |
| 709 return cx_mutstrcast(cx_strrchr_(cx_strcast(string), chr)); |
710 return cx_mutstrcast(cx_strrchr_(cx_strcast(string), chr)); |
| 710 } |
711 } |
| |
712 #define cx_strrchr(s, chr) cx_strrchr_cpp(cx_strcast_m(s), chr) |
| 711 #else |
713 #else |
| 712 /** |
714 /** |
| 713 * Internal conversion function - do not use. |
715 * Internal conversion function - do not use. |
| 714 * @param string |
716 * @param string |
| 715 * @param chr |
717 * @param chr |
| 733 * specified character. |
735 * specified character. |
| 734 * |
736 * |
| 735 * If the string does not contain the character, an empty string is returned. |
737 * If the string does not contain the character, an empty string is returned. |
| 736 * |
738 * |
| 737 * @param string the string where to locate the character |
739 * @param string the string where to locate the character |
| 738 * @param chr the character to locate |
740 * @param chr (@c int) the character to locate |
| 739 * @return a substring starting at the first location of @p chr |
741 * @return (@c cxstring or @c cxmutstr) a substring starting at the first |
| |
742 * location of @p chr |
| 740 */ |
743 */ |
| 741 #define cx_strchr(string, chr) _Generic(cx_strcast_m(string), \ |
744 #define cx_strchr(string, chr) _Generic(cx_strcast_m(string), \ |
| 742 cxstring: cx_strchr_, \ |
745 cxstring: cx_strchr_, \ |
| 743 cxmutstr: cx_strchr_m_)(cx_strcast_m(string), chr) |
746 cxmutstr: cx_strchr_m_)(cx_strcast_m(string), chr) |
| 744 |
747 |
| 747 * specified character. |
750 * specified character. |
| 748 * |
751 * |
| 749 * If the string does not contain the character, an empty string is returned. |
752 * If the string does not contain the character, an empty string is returned. |
| 750 * |
753 * |
| 751 * @param string the string where to locate the character |
754 * @param string the string where to locate the character |
| 752 * @param chr the character to locate |
755 * @param chr (@c int) the character to locate |
| 753 * @return a substring starting at the last location of @p chr |
756 * @return (@c cxstring or @c cxmutstr) a substring starting at the last |
| |
757 * location of @p chr |
| 754 */ |
758 */ |
| 755 #define cx_strrchr(string, chr) _Generic(cx_strcast_m(string), \ |
759 #define cx_strrchr(string, chr) _Generic(cx_strcast_m(string), \ |
| 756 cxstring: cx_strrchr_, \ |
760 cxstring: cx_strrchr_, \ |
| 757 cxmutstr: cx_strrchr_m_)(cx_strcast_m(string), chr) |
761 cxmutstr: cx_strrchr_m_)(cx_strcast_m(string), chr) |
| 758 #endif |
762 #endif |
| 769 * @see cx_strstr() |
773 * @see cx_strstr() |
| 770 */ |
774 */ |
| 771 CX_EXTERN CX_NODISCARD |
775 CX_EXTERN CX_NODISCARD |
| 772 cxstring cx_strstr_(cxstring haystack, cxstring needle); |
776 cxstring cx_strstr_(cxstring haystack, cxstring needle); |
| 773 |
777 |
| |
778 #ifdef __cplusplus |
| |
779 CX_CPPDECL cxstring cx_strstr_cpp(cxstring haystack, cxstring needle) { |
| |
780 return cx_strstr_(haystack, needle); |
| |
781 } |
| |
782 CX_CPPDECL cxmutstr cx_strstr_cpp(cxmutstr haystack, cxstring needle) { |
| |
783 return cx_mutstrcast(cx_strstr_(cx_strcast(haystack), needle)); |
| |
784 } |
| |
785 #define cx_strstr(h,n) cx_strstr_cpp(cx_strcast_m(h), cx_strcast(n)) |
| |
786 #else |
| |
787 /** |
| |
788 * Internal conversion - do not use. |
| |
789 * @param haystack |
| |
790 * @param needle |
| |
791 * @return |
| |
792 */ |
| |
793 CX_INLINE cxmutstr cx_strstr_m_(cxmutstr haystack, cxstring needle) { |
| |
794 return cx_mutstrcast(cx_strstr_(cx_strcast(haystack), needle)); |
| |
795 } |
| |
796 |
| 774 /** |
797 /** |
| 775 * Returns a substring starting at the location of the first occurrence of the |
798 * Returns a substring starting at the location of the first occurrence of the |
| 776 * specified string. |
799 * specified string. |
| 777 * |
800 * |
| 778 * If @p haystack does not contain @p needle, an empty string is returned. |
801 * If @p haystack does not contain @p needle, an empty string is returned. |
| 779 * |
802 * |
| 780 * If @p needle is an empty string, the complete @p haystack is |
803 * If @p needle is an empty string, the complete @p haystack is |
| 781 * returned. |
804 * returned. |
| 782 * |
805 * |
| 783 * @param haystack (@c cxstring) the string to be scanned |
|
| 784 * @param needle string containing the sequence of characters to match |
|
| 785 * @return (@c cxstring) a substring starting at the first occurrence of |
|
| 786 * @p needle, or an empty string, if the sequence is not contained |
|
| 787 * @see cx_strstr_m() |
|
| 788 */ |
|
| 789 #define cx_strstr(haystack, needle) cx_strstr_(haystack, cx_strcast(needle)) |
|
| 790 |
|
| 791 /** |
|
| 792 * Searches for a specific substring. |
|
| 793 * |
|
| 794 * Internal function - do not use. |
|
| 795 * |
|
| 796 * @param haystack the string to be scanned |
806 * @param haystack the string to be scanned |
| 797 * @param needle string containing the sequence of characters to match |
807 * @param needle string containing the sequence of characters to match |
| 798 * @return a substring starting at the first occurrence of @p needle, |
808 * @return (@c cxstring or @c cxmutstr) a substring starting at the first |
| 799 * or an empty string, if the sequence is not contained |
809 * occurrence of @p needle, or an empty string, if the sequence is not contained |
| 800 * @see cx_strstr_m() |
810 */ |
| 801 */ |
811 #define cx_strstr(haystack, needle) _Generic(cx_strcast_m(haystack), \ |
| 802 CX_EXTERN CX_NODISCARD |
812 cxstring: cx_strstr_,\ |
| 803 cxmutstr cx_strstr_m_(cxmutstr haystack, cxstring needle); |
813 cxmutstr: cx_strstr_m_)(cx_strcast_m(haystack), cx_strcast(needle)) |
| 804 |
814 #endif |
| 805 /** |
|
| 806 * Returns a substring starting at the location of the first occurrence of the |
|
| 807 * specified string. |
|
| 808 * |
|
| 809 * If @p haystack does not contain @p needle, an empty string is returned. |
|
| 810 * |
|
| 811 * If @p needle is an empty string, the complete @p haystack is |
|
| 812 * returned. |
|
| 813 * |
|
| 814 * @param haystack (@c cxmutstr) the string to be scanned |
|
| 815 * @param needle string containing the sequence of characters to match |
|
| 816 * @return (@c cxmutstr) a substring starting at the first occurrence of |
|
| 817 * @p needle, or an empty string, if the sequence is not contained |
|
| 818 * @see cx_strstr() |
|
| 819 */ |
|
| 820 #define cx_strstr_m(haystack, needle) cx_strstr_m_(haystack, cx_strcast(needle)) |
|
| 821 |
815 |
| 822 /** |
816 /** |
| 823 * Splits a given string using a delimiter string. |
817 * Splits a given string using a delimiter string. |
| 824 * |
818 * |
| 825 * Internal function - do not use. |
819 * Internal function - do not use. |