src/cx/string.h

changeset 1652
db8299984bfe
parent 1651
38b051dea6b1
equal deleted inserted replaced
1651:38b051dea6b1 1652:db8299984bfe
701 #define cx_strstr_m(haystack, needle) cx_strstr_m_(haystack, cx_strcast(needle)) 701 #define cx_strstr_m(haystack, needle) cx_strstr_m_(haystack, cx_strcast(needle))
702 702
703 /** 703 /**
704 * Splits a given string using a delimiter string. 704 * Splits a given string using a delimiter string.
705 * 705 *
706 * @note The resulting array contains strings that point to the source 706 * Internal function - do not use.
707 * @p string. Use cx_strdup() to get copies.
708 * 707 *
709 * @param string the string to split 708 * @param string the string to split
710 * @param delim the delimiter 709 * @param delim the delimiter
711 * @param limit the maximum number of split items 710 * @param limit the maximum number of split items
712 * @param output a preallocated array of at least @p limit length 711 * @param output the output array
713 * @return the actual number of split items 712 * @return the actual number of split items
713 * @see cx_strsplit()
714 */ 714 */
715 cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(4, 3) 715 cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(4, 3)
716 CX_EXPORT size_t cx_strsplit(cxstring string, cxstring delim, 716 CX_EXPORT size_t cx_strsplit_(cxstring string, cxstring delim,
717 size_t limit, cxstring *output); 717 size_t limit, cxstring *output);
718 718
719 /** 719 /**
720 * Splits a given string using a delimiter string. 720 * Splits a given string using a delimiter string.
721 * 721 *
722 * The array pointed to by @p output will be allocated by @p allocator. 722 * Internal function - do not use.
723 *
724 * @note The resulting array contains strings that point to the source
725 * @p string. Use cx_strdup() to get copies.
726 *
727 * @attention If allocation fails, the @c NULL pointer will be written to
728 * @p output and the number returned will be zero.
729 * 723 *
730 * @param allocator the allocator to use for allocating the resulting array 724 * @param allocator the allocator to use for allocating the resulting array
731 * @param string the string to split 725 * @param string the string to split
732 * @param delim the delimiter 726 * @param delim the delimiter
733 * @param limit the maximum number of split items 727 * @param limit the maximum number of split items
734 * @param output a pointer where the address of the allocated array shall be 728 * @param output the output array
735 * written to
736 * @return the actual number of split items 729 * @return the actual number of split items
730 * @see cx_strsplit_a()
737 */ 731 */
738 cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(5) 732 cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(5)
739 CX_EXPORT size_t cx_strsplit_a(const CxAllocator *allocator, 733 CX_EXPORT size_t cx_strsplit_a_(const CxAllocator *allocator,
740 cxstring string, cxstring delim, 734 cxstring string, cxstring delim,
741 size_t limit, cxstring **output); 735 size_t limit, cxstring **output);
742 736
743 737
744 /** 738 /**
745 * Splits a given string using a delimiter string. 739 * Splits a given string using a delimiter string.
746 * 740 *
747 * @note The resulting array contains strings that point to the source 741 * Internal function - do not use.
748 * @p string. Use cx_strdup() to get copies.
749 * 742 *
750 * @param string the string to split 743 * @param string the string to split
751 * @param delim the delimiter 744 * @param delim the delimiter
752 * @param limit the maximum number of split items 745 * @param limit the maximum number of split items
753 * @param output a preallocated array of at least @p limit length 746 * @param output the output array
754 * @return the actual number of split items 747 * @return the actual number of split items
748 * @see cx_strsplit_m()
755 */ 749 */
756 cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(4, 3) 750 cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(4, 3)
757 CX_EXPORT size_t cx_strsplit_m(cxmutstr string, cxstring delim, 751 CX_EXPORT size_t cx_strsplit_m_(cxmutstr string, cxstring delim,
758 size_t limit, cxmutstr *output); 752 size_t limit, cxmutstr *output);
759 753
760 /** 754 /**
761 * Splits a given string using a delimiter string. 755 * Splits a given string using a delimiter string.
762 * 756 *
763 * The array pointed to by @p output will be allocated by @p allocator. 757 * Internal function - do not use.
764 *
765 * @note The resulting array contains strings that point to the source
766 * @p string. Use cx_strdup() to get copies.
767 *
768 * @attention If allocation fails, the @c NULL pointer will be written to
769 * @p output and the number returned will be zero.
770 * 758 *
771 * @param allocator the allocator to use for allocating the resulting array 759 * @param allocator the allocator to use for allocating the resulting array
772 * @param string the string to split 760 * @param string the string to split
773 * @param delim the delimiter 761 * @param delim the delimiter
774 * @param limit the maximum number of split items 762 * @param limit the maximum number of split items
775 * @param output a pointer where the address of the allocated array shall be 763 * @param output the output array
776 * written to
777 * @return the actual number of split items 764 * @return the actual number of split items
765 * @see cx_strsplit_ma()
778 */ 766 */
779 cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(5) 767 cx_attr_nodiscard cx_attr_nonnull cx_attr_access_w(5)
780 CX_EXPORT size_t cx_strsplit_ma(const CxAllocator *allocator, 768 CX_EXPORT size_t cx_strsplit_ma_(const CxAllocator *allocator,
781 cxmutstr string, cxstring delim, size_t limit, 769 cxmutstr string, cxstring delim, size_t limit,
782 cxmutstr **output); 770 cxmutstr **output);
771
772 /**
773 * Splits a given string using a delimiter string.
774 *
775 * @note The resulting array contains strings that point to the source
776 * @p string. Use cx_strdup() to get copies.
777 *
778 * @param string (@c cxstring) the string to split
779 * @param delim the delimiter
780 * @param limit (@c size_t) the maximum number of split items
781 * @param output (@c cxstring*) a preallocated array of at least @p limit length
782 * @return the actual number of split items
783 */
784 #define cx_strsplit(string, delim, limit, output) \
785 cx_strsplit_(string, cx_strcast(delim), limit, output)
786
787 /**
788 * Splits a given string using a delimiter string.
789 *
790 * The array pointed to by @p output will be allocated by @p allocator.
791 *
792 * @note The resulting array contains strings that point to the source
793 * @p string. Use cx_strdup() to get copies.
794 *
795 * @attention If allocation fails, the @c NULL pointer will be written to
796 * @p output and the number returned will be zero.
797 *
798 * @param allocator (@c CxAllocator*) the allocator to use for allocating the resulting array
799 * @param string (@c cxstring) the string to split
800 * @param delim the delimiter
801 * @param limit (@c size_t) the maximum number of split items
802 * @param output (@c cxstring**) a pointer where the address of the allocated
803 * array shall be written to
804 * @return the actual number of split items
805 */
806 #define cx_strsplit_a(allocator, string, delim, limit, output) \
807 cx_strsplit_a_(allocator, string, cx_strcast(delim), limit, output)
808
809
810 /**
811 * Splits a given string using a delimiter string.
812 *
813 * @note The resulting array contains strings that point to the source
814 * @p string. Use cx_strdup() to get copies.
815 *
816 * @param string (@c cxmutstr) the string to split
817 * @param delim the delimiter
818 * @param limit (@c size_t) the maximum number of split items
819 * @param output (@c cxmutstr*) a preallocated array of at least @p limit length
820 * @return the actual number of split items
821 */
822 #define cx_strsplit_m(string, delim, limit, output) \
823 cx_strsplit_m_(string, cx_strcast(delim), limit, output)
824
825 /**
826 * Splits a given string using a delimiter string.
827 *
828 * The array pointed to by @p output will be allocated by @p allocator.
829 *
830 * @note The resulting array contains strings that point to the source
831 * @p string. Use cx_strdup() to get copies.
832 *
833 * @attention If allocation fails, the @c NULL pointer will be written to
834 * @p output and the number returned will be zero.
835 *
836 * @param allocator (@c CxAllocator*) the allocator to use for allocating the resulting array
837 * @param string (@c cxmutstr) the string to split
838 * @param delim the delimiter
839 * @param limit (@c size_t) the maximum number of split items
840 * @param output (@c cxmutstr**) a pointer where the address of the allocated
841 * array shall be written to
842 * @return the actual number of split items
843 */
844 #define cx_strsplit_ma(allocator, string, delim, limit, output) \
845 cx_strsplit_ma_(allocator, string, cx_strcast(delim), limit, output)
783 846
784 /** 847 /**
785 * Compares two strings. 848 * Compares two strings.
786 * 849 *
787 * @param s1 the first string 850 * @param s1 the first string

mercurial