Anonymous | Login | 2021-01-24 05:34 UTC |
Main | My View | View Issues | Change Log | Docs |
Viewing Issue Simple Details [ Jump to Notes ] | [ Issue History ] [ Print ] | |||||||||||
ID | Category | Severity | Type | Date Submitted | Last Update | |||||||
0001061 | [1003.1(2008)/Issue 7] Base Definitions and Headers | Editorial | Enhancement Request | 2016-07-07 21:09 | 2020-10-16 09:39 | |||||||
Reporter | EdSchouten | View Status | public | |||||||||
Assigned To | ajosey | |||||||||||
Priority | normal | Resolution | Open | |||||||||
Status | Under Review | |||||||||||
Name | Ed Schouten | |||||||||||
Organization | Nuxi, the Netherlands | |||||||||||
User Reference | ||||||||||||
Section | string.h / wchar.h | |||||||||||
Page Number | - | |||||||||||
Line Number | - | |||||||||||
Interp Status | --- | |||||||||||
Final Accepted Text | ||||||||||||
Summary | 0001061: Please add memmem() (and maybe wmemmem()) | |||||||||||
Description |
A decent implementation of the strstr()/wcsstr() function is rather complex. In the old days, implementations typically had to make a trade-off between in-place quadratic time algorithms (simple scanning) or linear-time/space algorithms (e.g. Knuth-Morris-Pratt). If I'm correct, an in-place linear worst-case time algorithm is only known since the 90s (Two-way string-matching). Its pseudo-code alone is already 50 lines. The problem with strstr()/wcsstr() is that it assumes that the input strings are null terminated, which isn't always the case. This is why many operating systems (Linux, all the BSDs, Mac OS X) provide a memmem() function as well, which can reuse the same algorithm. There shouldn't be a need to handroll such a function yourself. |
|||||||||||
Desired Action | Please standardize the existing memmem() function. While there, maybe we should also add wmemmem() for consistency. | |||||||||||
Tags | No tags attached. | |||||||||||
Attached Files |
![]() |
|||||||||||
|
![]() |
|
(0003817) EdSchouten (updater) 2017-08-15 07:50 |
[ Sorry if you received a partial response; I accidentally clicked the submit button ] Hi Andrew, As you requested, attached to this ticket you may find formatted text for inclusion into the standard. It is loosely based on the existing documentation of strstr(), except that I've decided to rename 's1' and 's2' to 'haystack' and 'needle' to prevent confusion. Be sure to get in touch in case there are things you want me to clarify/improve. Ed |
(0003871) rhansen (manager) 2017-10-26 16:19 edited on: 2017-10-26 16:27 |
This was discussed during the 2017-10-26 telecon. We have no problem adding memmem() to the standard, but since this is a new interface, we need a sponsor. There is no consensus to add wmemmem(). The following wording was agreed upon: In XSH chapter 3, insert a new entry for memmem(): NAMEmemmem — find a byte subsequence in a byte sequence On page 363 after line 12395 (XBD <string.h> DESCRIPTION), insert: [CX]void *memmem(const void *, size_t, const void *, size_t);[/CX] On page 2071 line 66440 (XSH strstr() SEE ALSO), add memmem(). |
(0005052) geoffclare (manager) 2020-10-16 09:39 |
The memmem() additions have been made in the Issue8NewAPIs branch in gitlab, based on Note: 0003871. It was also added to the POSIX_C_LIB_EXT subprofile group in XRAT E.1. |
Mantis 1.1.6[^] Copyright © 2000 - 2008 Mantis Group |