string.h头文件中strpbrk,strcspn 等函数原英文全拼

char * strpbrk (const char *string, const char *stopset)
strpbrk (“string pointer break”)

size_t strcspn (const char *string, const char *stopset)
strcspn (“string complement span”) 

size_t strspn (const char *string, const char *skipset)
strspn (“string span”)



参考:http://www.gnu.org/software/libtool/manual/libc/Search-Functions.html

This section describes library functions which perform various kindsof searching operations on strings and arrays. These functions aredeclared in the header filestring.h.

— Function: void * memchr ( const void *block, int c, size_t size)

This function finds the first occurrence of the byte c (convertedto anunsigned char) in the initialsize bytes of theobject beginning atblock. The return value is a pointer to thelocated byte, or a null pointer if no match was found.

— Function: wchar_t * wmemchr ( const wchar_t *block, wchar_t wc, size_t size)

This function finds the first occurrence of the wide character wcin the initialsize wide characters of the object beginning atblock. The return value is a pointer to the located widecharacter, or a null pointer if no match was found.

— Function: void * rawmemchr ( const void *block, int c)

Often the memchr function is used with the knowledge that thebytec is available in the memory block specified by theparameters. But this means that thesize parameter is not reallyneeded and that the tests performed with it at runtime (to check whetherthe end of the block is reached) are not needed.

The rawmemchr function exists for just this situation which issurprisingly frequent. The interface is similar tomemchr exceptthat thesize parameter is missing. The function will look beyondthe end of the block pointed to byblock in case the programmermade an error in assuming that the bytec is present in the block. In this case the result is unspecified. Otherwise the return value is apointer to the located byte.

This function is of special interest when looking for the end of astring. Since all strings are terminated by a null byte a call like

             rawmemchr (str, '\0')

will never go beyond the end of the string.

This function is a GNU extension.

— Function: void * memrchr ( const void *block, int c, size_t size)

The function memrchr is like memchr, except that it searchesbackwards from the end of the block defined byblock andsize(instead of forwards from the front).

This function is a GNU extension.

— Function: char * strchr ( const char *string, int c)

The strchr function finds the first occurrence of the characterc (converted to achar) in the null-terminated stringbeginning atstring. The return value is a pointer to the locatedcharacter, or a null pointer if no match was found.

For example,

          strchr ("hello, world", 'l')
              ⇒ "llo, world"
          strchr ("hello, world", '?')
              ⇒ NULL

The terminating null character is considered to be part of the string,so you can use this function get a pointer to the end of a string byspecifying a null character as the value of thec argument. Itwould be better (but less portable) to usestrchrnul in thiscase, though.

— Function: wchar_t * wcschr ( const wchar_t *wstring, int wc)

The wcschr function finds the first occurrence of the widecharacterwc in the null-terminated wide character stringbeginning atwstring. The return value is a pointer to thelocated wide character, or a null pointer if no match was found.

The terminating null character is considered to be part of the widecharacter string, so you can use this function get a pointer to the endof a wide character string by specifying a null wude character as thevalue of thewc argument. It would be better (but less portable)to use wcschrnul in this case, though.

— Function: char * strchrnul ( const char *string, int c)

strchrnul is the same as strchr except that if it doesnot find the character, it returns a pointer to string's terminatingnull character rather than a null pointer.

This function is a GNU extension.

— Function: wchar_t * wcschrnul ( const wchar_t *wstring, wchar_t wc)

wcschrnul is the same as wcschr except that if it does notfind the wide character, it returns a pointer to wide character string'sterminating null wide character rather than a null pointer.

This function is a GNU extension.

One useful, but unusual, use of the strchrfunction is when one wants to have a pointer pointing to the NUL byteterminating a string. This is often written in this way:

       s += strlen (s);

This is almost optimal but the addition operation duplicated a bit ofthe work already done in thestrlen function. A better solutionis this:

       s = strchr (s, '\0');

There is no restriction on the second parameter of strchr so itcould very well also be the NUL character. Those readers thinking veryhard about this might now point out that thestrchr function ismore expensive than thestrlen function since we have two abortcriteria. This is right. But in the GNU C library the implementation ofstrchr is optimized in a special way so thatstrchractually is faster.

— Function: char * strrchr ( const char *string, int c)

The function strrchr is like strchr, except that it searchesbackwards from the end of the stringstring (instead of forwardsfrom the front).

For example,

          strrchr ("hello, world", 'l')
              ⇒ "ld"
— Function: wchar_t * wcsrchr ( const wchar_t *wstring, wchar_t c)

The function wcsrchr is like wcschr, except that it searchesbackwards from the end of the stringwstring (instead of forwardsfrom the front).

— Function: char * strstr ( const char *haystack, const char *needle)

This is like strchr, except that it searches haystack for asubstringneedle rather than just a single character. Itreturns a pointer into the stringhaystack that is the firstcharacter of the substring, or a null pointer if no match was found. Ifneedle is an empty string, the function returnshaystack.

For example,

          strstr ("hello, world", "l")
              ⇒ "llo, world"
          strstr ("hello, world", "wo")
              ⇒ "world"
— Function: wchar_t * wcsstr ( const wchar_t *haystack, const wchar_t *needle)

This is like wcschr, except that it searches haystack for asubstringneedle rather than just a single wide character. Itreturns a pointer into the stringhaystack that is the first widecharacter of the substring, or a null pointer if no match was found. Ifneedle is an empty string, the function returnshaystack.

— Function: wchar_t * wcswcs ( const wchar_t *haystack, const wchar_t *needle)

wcswcs is an deprecated alias for wcsstr. This is thename originally used in the X/Open Portability Guide before theAmendment 1 to ISO C90 was published.

— Function: char * strcasestr ( const char *haystack, const char *needle)

This is like strstr, except that it ignores case in searching forthe substring. Likestrcasecmp, it is locale dependent howuppercase and lowercase characters are related.

For example,

          strcasestr ("hello, world", "L")
              ⇒ "llo, world"
          strcasestr ("hello, World", "wo")
              ⇒ "World"
— Function: void * memmem ( const void *haystack, size_t haystack-len,
const void *needle, size_t needle-len
)

This is like strstr, but needle and haystack are bytearrays rather than null-terminated strings.needle-len is thelength ofneedle and haystack-len is the length ofhaystack.

This function is a GNU extension.

— Function: size_t strspn ( const char *string, const char *skipset)

The strspn (“string span”) function returns the length of theinitial substring ofstring that consists entirely of characters thatare members of the set specified by the stringskipset. The orderof the characters inskipset is not important.

For example,

          strspn ("hello, world", "abcdefghijklmnopqrstuvwxyz")
              ⇒ 5

Note that “character” is here used in the sense of byte. In a stringusing a multibyte character encoding (abstract) character consisting ofmore than one byte are not treated as an entity. Each byte is treatedseparately. The function is not locale-dependent.

— Function: size_t wcsspn ( const wchar_t *wstring, const wchar_t *skipset)

The wcsspn (“wide character string span”) function returns thelength of the initial substring ofwstring that consists entirelyof wide characters that are members of the set specified by the stringskipset. The order of the wide characters inskipset is notimportant.

— Function: size_t strcspn ( const char *string, const char *stopset)

The strcspn (“string complement span”) function returns the lengthof the initial substring ofstring that consists entirely of charactersthat arenot members of the set specified by the stringstopset. (In other words, it returns the offset of the first character instringthat is a member of the setstopset.)

For example,

          strcspn ("hello, world", " \t\n,.;!?")
              ⇒ 5

Note that “character” is here used in the sense of byte. In a stringusing a multibyte character encoding (abstract) character consisting ofmore than one byte are not treated as an entity. Each byte is treatedseparately. The function is not locale-dependent.

— Function: size_t wcscspn ( const wchar_t *wstring, const wchar_t *stopset)

The wcscspn (“wide character string complement span”) functionreturns the length of the initial substring ofwstring thatconsists entirely of wide characters that arenot members of theset specified by the stringstopset. (In other words, it returnsthe offset of the first character instring that is a member ofthe setstopset.)

— Function: char * strpbrk ( const char *string, const char *stopset)

The strpbrk (“string pointer break”) function is related tostrcspn, except that it returns a pointer to the first characterinstring that is a member of the setstopset instead of thelength of the initial substring. It returns a null pointer if no suchcharacter fromstopset is found.

For example,

          strpbrk ("hello, world", " \t\n,.;!?")
              ⇒ ", world"

Note that “character” is here used in the sense of byte. In a stringusing a multibyte character encoding (abstract) character consisting ofmore than one byte are not treated as an entity. Each byte is treatedseparately. The function is not locale-dependent.

— Function: wchar_t * wcspbrk ( const wchar_t *wstring, const wchar_t *stopset)

The wcspbrk (“wide character string pointer break”) function isrelated towcscspn, except that it returns a pointer to the firstwide character inwstring that is a member of the setstopset instead of the length of the initial substring. Itreturns a null pointer if no such character fromstopset is found.

5.7.1 Compatibility String Search Functions
— Function: char * index ( const char *string, int c)

index is another name for strchr; they are exactly the same. New code should always usestrchr since this name is defined inISO C whileindex is a BSD invention which never was availableon System V derived systems.

— Function: char * rindex ( const char *string, int c)

rindex is another name for strrchr; they are exactly the same. New code should always usestrrchr since this name is defined inISO C whilerindex is a BSD invention which never was availableon System V derived systems.


  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值