src/cx/string.h

changeset 1676
f889ffd07c86
parent 1675
36c0fb2b60b2
child 1677
1d73c7302fbc
equal deleted inserted replaced
1675:36c0fb2b60b2 1676:f889ffd07c86
672 * @see cx_strat() 672 * @see cx_strat()
673 */ 673 */
674 #define cx_strat(str, index) cx_strat_(cx_strcast(str), index) 674 #define cx_strat(str, index) cx_strat_(cx_strcast(str), index)
675 675
676 /** 676 /**
677 * Searches for a character in a string.
678 * Internal function - do not use.
679 * @param string
680 * @param chr
681 * @return
682 * @see cx_strchr()
683 */
684 CX_EXTERN CX_NODISCARD
685 cxstring cx_strchr_(cxstring string, int chr);
686
687 /**
688 * Searches for a character in a string.
689 * Internal function - do not use.
690 * @param string
691 * @param chr
692 * @return
693 * @see cx_strrchr()
694 */
695 CX_EXTERN CX_NODISCARD
696 cxstring cx_strrchr_(cxstring string, int chr);
697
698 #ifdef __cplusplus
699 CX_CPPDECL cxstring cx_strchr(cxstring string, int chr) {
700 return cx_strchr_(string, chr);
701 }
702 CX_CPPDECL cxmutstr cx_strchr(cxmutstr string, int chr) {
703 return cx_mutstrcast(cx_strchr_(cx_strcast(string), chr));
704 }
705 CX_CPPDECL cxstring cx_strrchr(cxstring string, int chr) {
706 return cx_strrchr_(string, chr);
707 }
708 CX_CPPDECL cxmutstr cx_strrchr(cxmutstr string, int chr) {
709 return cx_mutstrcast(cx_strrchr_(cx_strcast(string), chr));
710 }
711 #else
712 /**
713 * Internal conversion function - do not use.
714 * @param string
715 * @param chr
716 * @return
717 */
718 CX_INLINE cxmutstr cx_strchr_m_(cxmutstr string, int chr) {
719 return cx_mutstrcast(cx_strchr_(cx_strcast(string), chr));
720 }
721 /**
722 * Internal conversion function - do not use.
723 * @param string
724 * @param chr
725 * @return
726 */
727 CX_INLINE cxmutstr cx_strrchr_m_(cxmutstr string, int chr) {
728 return cx_mutstrcast(cx_strrchr_(cx_strcast(string), chr));
729 }
730
731 /**
677 * Returns a substring starting at the location of the first occurrence of the 732 * Returns a substring starting at the location of the first occurrence of the
678 * specified character. 733 * specified character.
679 * 734 *
680 * If the string does not contain the character, an empty string is returned. 735 * If the string does not contain the character, an empty string is returned.
681 * 736 *
682 * @param string the string where to locate the character 737 * @param string the string where to locate the character
683 * @param chr the character to locate 738 * @param chr the character to locate
684 * @return a substring starting at the first location of @p chr 739 * @return a substring starting at the first location of @p chr
685 * 740 */
686 * @see cx_strchr_m() 741 #define cx_strchr(string, chr) _Generic(cx_strcast_m(string), \
687 */ 742 cxstring: cx_strchr_, \
688 CX_EXTERN CX_NODISCARD 743 cxmutstr: cx_strchr_m_)(cx_strcast_m(string), chr)
689 cxstring cx_strchr(cxstring string, int chr);
690
691 /**
692 * Returns a substring starting at the location of the first occurrence of the
693 * specified character.
694 *
695 * If the string does not contain the character, an empty string is returned.
696 *
697 * @param string the string where to locate the character
698 * @param chr the character to locate
699 * @return a substring starting at the first location of @p chr
700 *
701 * @see cx_strchr()
702 */
703 CX_EXTERN CX_NODISCARD
704 cxmutstr cx_strchr_m(cxmutstr string, int chr);
705 744
706 /** 745 /**
707 * Returns a substring starting at the location of the last occurrence of the 746 * Returns a substring starting at the location of the last occurrence of the
708 * specified character. 747 * specified character.
709 * 748 *
710 * If the string does not contain the character, an empty string is returned. 749 * If the string does not contain the character, an empty string is returned.
711 * 750 *
712 * @param string the string where to locate the character 751 * @param string the string where to locate the character
713 * @param chr the character to locate 752 * @param chr the character to locate
714 * @return a substring starting at the last location of @p chr 753 * @return a substring starting at the last location of @p chr
715 * 754 */
716 * @see cx_strrchr_m() 755 #define cx_strrchr(string, chr) _Generic(cx_strcast_m(string), \
717 */ 756 cxstring: cx_strrchr_, \
718 CX_EXTERN CX_NODISCARD 757 cxmutstr: cx_strrchr_m_)(cx_strcast_m(string), chr)
719 cxstring cx_strrchr(cxstring string, int chr); 758 #endif
720
721 /**
722 * Returns a substring starting at the location of the last occurrence of the
723 * specified character.
724 *
725 * If the string does not contain the character, an empty string is returned.
726 *
727 * @param string the string where to locate the character
728 * @param chr the character to locate
729 * @return a substring starting at the last location of @p chr
730 *
731 * @see cx_strrchr()
732 */
733 CX_EXTERN CX_NODISCARD
734 cxmutstr cx_strrchr_m(cxmutstr string, int chr);
735 759
736 /** 760 /**
737 * Searches for a specific substring. 761 * Searches for a specific substring.
738 * 762 *
739 * Internal function - do not use. 763 * Internal function - do not use.

mercurial