📄 string.h
字号:
/* Find the last occurrence of C in S. This is the BSD name. */# define _HAVE_STRING_ARCH_rindex 1# define rindex(s, c) \ (__extension__ (__builtin_constant_p (c) \ ? __strrchr_c ((s), ((c) & 0xff) << 8) \ : __strrchr_g ((s), (c))))#endif/* Return the length of the initial segment of S which consists entirely of characters not in REJECT. */#define _HAVE_STRING_ARCH_strcspn 1#define strcspn(s, reject) \ (__extension__ (__builtin_constant_p (reject) && sizeof ((reject)[0]) == 1 \ ? ((reject)[0] == '\0' \ ? strlen (s) \ : ((reject)[1] == '\0' \ ? __strcspn_c1 ((s), (((reject)[0] << 8) & 0xff00)) \ : __strcspn_cg ((s), (reject), strlen (reject)))) \ : __strcspn_g ((s), (reject))))__STRING_INLINE size_t __strcspn_c1 (__const char *__s, int __reject);#ifndef _FORCE_INLINES__STRING_INLINE size_t__strcspn_c1 (__const char *__s, int __reject){ register unsigned long int __d0; register char *__res; __asm__ __volatile__ ("1:\n\t" "movb (%0),%%al\n\t" "leal 1(%0),%0\n\t" "cmpb %%ah,%%al\n\t" "je 2f\n\t" "testb %%al,%%al\n\t" "jne 1b\n" "2:" : "=r" (__res), "=&a" (__d0) : "0" (__s), "1" (__reject), "m" ( *(struct { char __x[0xfffffff]; } *)__s) : "cc"); return (__res - 1) - __s;}#endif__STRING_INLINE size_t __strcspn_cg (__const char *__s, __const char __reject[], size_t __reject_len);__STRING_INLINE size_t__strcspn_cg (__const char *__s, __const char __reject[], size_t __reject_len){ register unsigned long int __d0, __d1, __d2; register __const char *__res; __asm__ __volatile__ ("cld\n" "1:\n\t" "lodsb\n\t" "testb %%al,%%al\n\t" "je 2f\n\t" "movl %5,%%edi\n\t" "movl %6,%%ecx\n\t" "repne; scasb\n\t" "jne 1b\n" "2:" : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2) : "0" (__s), "d" (__reject), "g" (__reject_len) : "memory", "cc"); return (__res - 1) - __s;}__STRING_INLINE size_t __strcspn_g (__const char *__s, __const char *__reject);#ifdef __PIC____STRING_INLINE size_t__strcspn_g (__const char *__s, __const char *__reject){ register unsigned long int __d0, __d1, __d2; register __const char *__res; __asm__ __volatile__ ("pushl %%ebx\n\t" "movl %4,%%edi\n\t" "cld\n\t" "repne; scasb\n\t" "notl %%ecx\n\t" "leal -1(%%ecx),%%ebx\n" "1:\n\t" "lodsb\n\t" "testb %%al,%%al\n\t" "je 2f\n\t" "movl %4,%%edi\n\t" "movl %%ebx,%%ecx\n\t" "repne; scasb\n\t" "jne 1b\n" "2:\n\t" "popl %%ebx" : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2) : "r" (__reject), "0" (__s), "1" (0), "2" (0xffffffff) : "memory", "cc"); return (__res - 1) - __s;}#else__STRING_INLINE size_t__strcspn_g (__const char *__s, __const char *__reject){ register unsigned long int __d0, __d1, __d2, __d3; register __const char *__res; __asm__ __volatile__ ("cld\n\t" "repne; scasb\n\t" "notl %%ecx\n\t" "leal -1(%%ecx),%%edx\n" "1:\n\t" "lodsb\n\t" "testb %%al,%%al\n\t" "je 2f\n\t" "movl %%ebx,%%edi\n\t" "movl %%edx,%%ecx\n\t" "repne; scasb\n\t" "jne 1b\n" "2:" : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2), "=&d" (__d3) : "0" (__s), "1" (0), "2" (0xffffffff), "3" (__reject), "b" (__reject) /* Clobber memory, otherwise GCC cannot handle this. */ : "memory", "cc"); return (__res - 1) - __s;}#endif/* Return the length of the initial segment of S which consists entirely of characters in ACCEPT. */#define _HAVE_STRING_ARCH_strspn 1#define strspn(s, accept) \ (__extension__ (__builtin_constant_p (accept) && sizeof ((accept)[0]) == 1 \ ? ((accept)[0] == '\0' \ ? ((void) (s), 0) \ : ((accept)[1] == '\0' \ ? __strspn_c1 ((s), (((accept)[0] << 8 ) & 0xff00)) \ : __strspn_cg ((s), (accept), strlen (accept)))) \ : __strspn_g ((s), (accept))))#ifndef _FORCE_INLINES__STRING_INLINE size_t __strspn_c1 (__const char *__s, int __accept);__STRING_INLINE size_t__strspn_c1 (__const char *__s, int __accept){ register unsigned long int __d0; register char *__res; /* Please note that __accept never can be '\0'. */ __asm__ __volatile__ ("1:\n\t" "movb (%0),%b1\n\t" "leal 1(%0),%0\n\t" "cmpb %h1,%b1\n\t" "je 1b" : "=r" (__res), "=&q" (__d0) : "0" (__s), "1" (__accept), "m" ( *(struct { char __x[0xfffffff]; } *)__s) : "cc"); return (__res - 1) - __s;}#endif__STRING_INLINE size_t __strspn_cg (__const char *__s, __const char __accept[], size_t __accept_len);__STRING_INLINE size_t__strspn_cg (__const char *__s, __const char __accept[], size_t __accept_len){ register unsigned long int __d0, __d1, __d2; register __const char *__res; __asm__ __volatile__ ("cld\n" "1:\n\t" "lodsb\n\t" "testb %%al,%%al\n\t" "je 2f\n\t" "movl %5,%%edi\n\t" "movl %6,%%ecx\n\t" "repne; scasb\n\t" "je 1b\n" "2:" : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2) : "0" (__s), "g" (__accept), "g" (__accept_len), /* Since we do not know how large the memory we access it, use a really large amount. */ "m" ( *(struct { char __x[0xfffffff]; } *)__s), "m" ( *(struct { __extension__ char __x[__accept_len]; } *)__accept) : "cc"); return (__res - 1) - __s;}__STRING_INLINE size_t __strspn_g (__const char *__s, __const char *__accept);#ifdef __PIC____STRING_INLINE size_t__strspn_g (__const char *__s, __const char *__accept){ register unsigned long int __d0, __d1, __d2; register __const char *__res; __asm__ __volatile__ ("pushl %%ebx\n\t" "cld\n\t" "repne; scasb\n\t" "notl %%ecx\n\t" "leal -1(%%ecx),%%ebx\n" "1:\n\t" "lodsb\n\t" "testb %%al,%%al\n\t" "je 2f\n\t" "movl %%edx,%%edi\n\t" "movl %%ebx,%%ecx\n\t" "repne; scasb\n\t" "je 1b\n" "2:\n\t" "popl %%ebx" : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2) : "d" (__accept), "0" (__s), "1" (0), "2" (0xffffffff), "3" (__accept) : "memory", "cc"); return (__res - 1) - __s;}#else__STRING_INLINE size_t__strspn_g (__const char *__s, __const char *__accept){ register unsigned long int __d0, __d1, __d2, __d3; register __const char *__res; __asm__ __volatile__ ("cld\n\t" "repne; scasb\n\t" "notl %%ecx\n\t" "leal -1(%%ecx),%%edx\n" "1:\n\t" "lodsb\n\t" "testb %%al,%%al\n\t" "je 2f\n\t" "movl %%ebx,%%edi\n\t" "movl %%edx,%%ecx\n\t" "repne; scasb\n\t" "je 1b\n" "2:" : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2), "=&d" (__d3) : "0" (__s), "1" (0), "2" (0xffffffff), "3" (__accept), "b" (__accept) : "memory", "cc"); return (__res - 1) - __s;}#endif/* Find the first occurrence in S of any character in ACCEPT. */#define _HAVE_STRING_ARCH_strpbrk 1#define strpbrk(s, accept) \ (__extension__ (__builtin_constant_p (accept) && sizeof ((accept)[0]) == 1 \ ? ((accept)[0] == '\0' \ ? ((void) (s), NULL) \ : ((accept)[1] == '\0' \ ? strchr ((s), (accept)[0]) \ : __strpbrk_cg ((s), (accept), strlen (accept)))) \ : __strpbrk_g ((s), (accept))))__STRING_INLINE char *__strpbrk_cg (__const char *__s, __const char __accept[], size_t __accept_len);__STRING_INLINE char *__strpbrk_cg (__const char *__s, __const char __accept[], size_t __accept_len){ register unsigned long int __d0, __d1, __d2; register char *__res; __asm__ __volatile__ ("cld\n" "1:\n\t" "lodsb\n\t" "testb %%al,%%al\n\t" "je 2f\n\t" "movl %5,%%edi\n\t" "movl %6,%%ecx\n\t" "repne; scasb\n\t" "jne 1b\n\t" "decl %0\n\t" "jmp 3f\n" "2:\n\t" "xorl %0,%0\n" "3:" : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2) : "0" (__s), "d" (__accept), "g" (__accept_len) : "memory", "cc"); return __res;}__STRING_INLINE char *__strpbrk_g (__const char *__s, __const char *__accept);#ifdef __PIC____STRING_INLINE char *__strpbrk_g (__const char *__s, __const char *__accept){ register unsigned long int __d0, __d1, __d2; register char *__res; __asm__ __volatile__ ("pushl %%ebx\n\t" "movl %%edx,%%edi\n\t" "cld\n\t" "repne; scasb\n\t" "notl %%ecx\n\t" "leal -1(%%ecx),%%ebx\n" "1:\n\t" "lodsb\n\t" "testb %%al,%%al\n\t" "je 2f\n\t" "movl %%edx,%%edi\n\t" "movl %%ebx,%%ecx\n\t" "repne; scasb\n\t" "jne 1b\n\t" "decl %0\n\t" "jmp 3f\n" "2:\n\t" "xorl %0,%0\n" "3:\n\t" "popl %%ebx" : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2) : "d" (__accept), "0" (__s), "1" (0), "2" (0xffffffff) : "memory", "cc"); return __res;}#else__STRING_INLINE char *__strpbrk_g (__const char *__s, __const char *__accept){ register unsigned long int __d0, __d1, __d2, __d3; register char *__res; __asm__ __volatile__ ("movl %%ebx,%%edi\n\t" "cld\n\t" "repne; scasb\n\t" "notl %%ecx\n\t" "leal -1(%%ecx),%%edx\n" "1:\n\t" "lodsb\n\t" "testb %%al,%%al\n\t" "je 2f\n\t" "movl %%ebx,%%edi\n\t" "movl %%edx,%%ecx\n\t" "repne; scasb\n\t" "jne 1b\n\t" "decl %0\n\t" "jmp 3f\n" "2:\n\t" "xorl %0,%0\n" "3:" : "=S" (__res), "=&a" (__d0), "=&c" (__d1), "=&d" (__d2), "=&D" (__d3) : "0" (__s), "1" (0), "2" (0xffffffff), "b" (__accept) : "memory", "cc"); return __res;}#endif/* Find the first occurrence of NEEDLE in HAYSTACK. */#define _HAVE_STRING_ARCH_strstr 1#define strstr(haystack, needle) \ (__extension__ (__builtin_constant_p (needle) && sizeof ((needle)[0]) == 1 \ ? ((needle)[0] == '\0' \ ? (haystack) \ : ((needle)[1] == '\0' \ ? strchr ((haystack), (needle)[0]) \ : __strstr_cg ((haystack), (needle), \ strlen (needle)))) \ : __strstr_g ((haystack), (needle))))/* Please note that this function need not handle NEEDLEs with a length shorter than two. */__STRING_INLINE char *__strstr_cg (__const char *__haystack, __const char __needle[], size_t __needle_len);__STRING_INLINE char *__strstr_cg (__const char *__haystack, __const char __needle[], size_t __needle_len){ register unsigned long int __d0, __d1, __d2; register char *__res; __asm__ __volatile__ ("cld\n" \ "1:\n\t" "movl %6,%%edi\n\t" "movl %5,%%eax\n\t" "movl %4,%%ecx\n\t" "repe; cmpsb\n\t" "je 2f\n\t" "cmpb $0,-1(%%esi)\n\t" "leal 1(%%eax),%5\n\t" "jne 1b\n\t" "xorl %%eax,%%eax\n" "2:" : "=&a" (__res), "=&S" (__d0), "=&D" (__d1), "=&c" (__d2) : "g" (__needle_len), "1" (__haystack), "d" (__needle) : "memory", "cc"); return __res;}__STRING_INLINE char *__strstr_g (__const char *__haystack, __const char *__needle);#ifdef __PIC____STRING_INLINE char *__strstr_g (__const char *__haystack, __const char *__needle){ register unsigned long int __d0, __d1, __d2; register char *__res; __asm__ __volatile__ ("cld\n\t" "repne; scasb\n\t" "notl %%ecx\n\t" "pushl %%ebx\n\t" "decl %%ecx\n\t" /* NOTE! This also sets Z if searchstring='' */ "movl %%ecx,%%ebx\n" "1:\n\t" "movl %%edx,%%edi\n\t" "movl %%esi,%%eax\n\t" "movl %%ebx,%%ecx\n\t" "repe; cmpsb\n\t" "je 2f\n\t" /* also works for empty string, see above */ "cmpb $0,-1(%%esi)\n\t" "leal 1(%%eax),%%esi\n\t" "jne 1b\n\t" "xorl %%eax,%%eax\n" "2:\n\t" "popl %%ebx" : "=&a" (__res), "=&c" (__d0), "=&S" (__d1), "=&D" (__d2) : "0" (0), "1" (0xffffffff), "2" (__haystack), "3" (__needle), "d" (__needle) : "memory", "cc"); return __res;}#else__STRING_INLINE char *__strstr_g (__const char *__haystack, __const char *__needle){ register unsigned long int __d0, __d1, __d2, __d3; register char *__res; __asm__ __volatile__ ("cld\n\t" "repne; scasb\n\t" "notl %%ecx\n\t" "decl %%ecx\n\t" /* NOTE! This also sets Z if searchstring='' */ "movl %%ecx,%%edx\n" "1:\n\t" "movl %%ebx,%%edi\n\t" "movl %%esi,%%eax\n\t" "movl %%edx,%%ecx\n\t" "repe; cmpsb\n\t" "je 2f\n\t" /* also works for empty string, see above */ "cmpb $0,-1(%%esi)\n\t" "leal 1(%%eax),%%esi\n\t" "jne 1b\n\t" "xorl %%eax,%%eax\n" "2:" : "=&a" (__res), "=&c" (__d0), "=&S" (__d1), "=&D" (__d2), "=&d" (__d3) : "0" (0), "1" (0xffffffff), "2" (__haystack), "3" (__needle), "b" (__needle) : "memory", "cc"); return __res;}#endif/* Bit find functions. We define only the i686 version since for the other processors gcc generates good code. */#if defined __USE_BSD || defined __USE_XOPEN_EXTENDED# ifdef __i686__# define _HAVE_STRING_ARCH_ffs 1# define ffs(word) (__builtin_constant_p (word) \ ? __builtin_ffs (word) \ : ({ int __cnt, __tmp; \ __asm__ __volatile__ \ ("bsfl %2,%0\n\t" \ "cmovel %1,%0" \ : "=&r" (__cnt), "=r" (__tmp) \ : "rm" (word), "1" (-1)); \ __cnt + 1; }))# ifndef ffsl# define ffsl(word) ffs(word)# endif# endif /* i686 */#endif /* BSD || X/Open */#ifndef _FORCE_INLINES# undef __STRING_INLINE#endif#endif /* use string inlines && GNU CC */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -