Name n3620, alx-0028r2 - add st*rspn(), st*rcspn(), wc*rspn(), wc*rcspn() Principles - Codify existing practice to address evident deficiencies. - Enable secure programming Category Standardize common string APIs Author Alejandro Colomar History r0 (2025-06-14): - Initial draft. r1 (2025-06-26): - tfix. - s/Description/Rationale/ r2 (2025-06-27; n3620): - wfix. Rationale Searching for a span starting at the end of a string is a common operation. It allows easily removing trailing withe space in a line, for example: stpcpy(stprspn(buf, " \t\n"), ""); A variant that searches for the complementary span, stprcspn() is interesting for example for finding the basename of a path: stprcspn(s, "/"); Prior art Solaris provides strrspn(3GEN), although it returns a pointer. This is inconsistent with the existing strspn(3) family of functions, which returns an offset. Design decisions For returning a pointer, a better name for the Solaris API would have been stprspn(). Let's add it here as stprspn(), and turn Solaris into non-conforming in this regard. Proposed wording Based on N3550. 7.28.5.1 Add 'stprcspn' and 'stprspn' in the first sentence. 7.28.5 String handling :: Search functions ## New sections after 7.28.5.4 ("The strcspn function") +7.28.5.4+1 The strrcspn function + +Synopsis +1 #include + size_t strrcspn(const char *s, const char *reject); + +Description +2 The strrcspn function + computes the offset of the maximum final segment + of the string pointed to by s + which consists entirely of + characters not from + the string poined to by reject. + +Returns +3 The strrcspn function returns + the offset of the segment + from the begining of the string pointed to by s. + +7.28.5.4+2 The stprcspn generic function + +Synopsis +1 #include + QChar *stprcspn(QChar *s, const char *reject); + +Description +2 The stprcspn generic function + is equivalent to strrcspn, + except for the return value. + +Returns +3 The stprcspn generic function returns + s + strrcspn(s, reject) ## New sections after 7.28.5.7 ("The strspn function") +7.28.5.7+1 The strrspn function + +Synopsis +1 #include + size_t strrspn(const char *s, const char *accept); + +Description +2 The strrspn function + computes the offset of the maximum final segment + of the string pointed to by s + which consists entirely of + characters from + the string poined to by accept. + +Returns +3 The strrspn function returns + the offset of the segment + from the begining of the string pointed to by s. + +7.28.5.4+2 The stprspn generic function + +Synopsis +1 #include + QChar *stprspn(QChar *s, const char *accept); + +Description +2 The stprspn generic function + is equivalent to strrspn, + except for the return value. + +Returns +3 The stprspn generic function returns + s + strrspn(s, acccept) 7.28.5.1 Add 'wcprcspn' and 'wcprspn' in the first sentence. 7.33.4.6 General wide string utilities :: Wide string search functions ## New sections after 7.33.4.6.3 ("The wcscspn function") +7.33.4.6.3+1 The wcsrcspn function + +Synopsis +1 #include + size_t wcsrcspn(const wchar_t *s, const wchar_t *reject); + +Description +2 The wcsrcspn function + is equivalent to strrcspn + except that it handles wide strings. + +7.33.4.6.3+2 The wcprcspn generic function + +Synopsis +1 #include + QWchar *wcprcspn(QWchar *p, const wchar_t *reject); + +Description +2 The wcprcspn generic function + is equivalent to stprcspn + except that it handles wide strings. ## New sections after 7.33.4.6.6 ("The wcsspn function") +7.33.4.6.6+1 The wcsrspn function + +Synopsis +1 #include + size_t wcsrspn(const wchar_t *s, const wchar_t *accept); + +Description +2 The wcsrspn function + is equivalent to strrspn + except that it handles wide strings. + +7.33.4.6.6+2 The wcprspn generic function + +Synopsis +1 #include + QWchar *wcprspn(QWchar *p, const wchar_t *acccept); + +Description +2 The wcprspn generic function + is equivalent to stprspn + except that it handles wide strings. 7.35.18 String handling Add 'stprcspn' and 'stprspn' in the second paragraph. 7.35.21 Extended multibyte and wide character utilities Add 'wcprcspn' and 'wcprspn' in the third paragraph.