src/cx/string.h

changeset 1668
3ffdfe1776b4
parent 1667
608cc0b25352
child 1671
cf19b7820ff0
equal deleted inserted replaced
1667:608cc0b25352 1668:3ffdfe1776b4
529 */ 529 */
530 cx_attr_nodiscard 530 cx_attr_nodiscard
531 CX_EXPORT cxmutstr cx_strsubsl_m(cxmutstr string, size_t start, size_t length); 531 CX_EXPORT cxmutstr cx_strsubsl_m(cxmutstr string, size_t start, size_t length);
532 532
533 /** 533 /**
534 * Returns the character at the specified index offset.
535 *
536 * Internal function - do not use.
537 *
538 * @param str the string
539 * @param index the index offset
540 * @return the character at the index
541 * @see cx_strat()
542 */
543 CX_INLINE char cx_strat_(cxstring str, off_t index) {
544 size_t i;
545 if (index >= 0) {
546 i = index;
547 } else {
548 i = (size_t) (str.length + index);
549 }
550 if (i >= str.length) {
551 return '\0';
552 }
553 return str.ptr[i];
554 }
555
556 /**
557 * Returns the character at the specified index offset.
558 *
559 * When the @p index is negative, the character is counted from the end of the
560 * string where -1 denotes the last character in the string.
561 *
562 * When the @p index is out of bounds, the function returns zero.
563 *
564 * @param str the string
565 * @param index the index offset
566 * @return the character at the index
567 * @see cx_strat()
568 */
569 #define cx_strat(str, index) cx_strat_(cx_strcast(str), index)
570
571 /**
534 * Returns a substring starting at the location of the first occurrence of the 572 * Returns a substring starting at the location of the first occurrence of the
535 * specified character. 573 * specified character.
536 * 574 *
537 * If the string does not contain the character, an empty string is returned. 575 * If the string does not contain the character, an empty string is returned.
538 * 576 *

mercurial