📄 strings.c
字号:
}char * strpbrk(const char * string, const char * control) { char *cset; /* 1st char in control string stops search */ while (*string) { for (cset = (char *) control; *cset; cset++) if (*cset == *string) return (char *) string; string++; } return NULL;}/****wchar_t *wcsrchr(string, ch) - find last occurrence of ch in wide string**Purpose:* Finds the last occurrence of ch in string. The terminating* null character is used as part of the search (wide-characters).**Entry:* wchar_t *string - string to search in* wchar_t ch - character to search for**Exit:* returns a pointer to the last occurrence of ch in the given* string* returns NULL if ch does not occurr in the string**Exceptions:********************************************************************************/wchar_t * wcsrchr(const wchar_t * string, wchar_t ch) { wchar_t *start = (wchar_t *)string; while (*string++) /* find end of string */ ; /* search towards front */ while (--string != start && *string != ch) ; if (*string == ch) /* wchar_t found ? */ return( (wchar_t *)string ); return(NULL);}char * strrchr(const char * string, int ch) { char *start = (char *)string; while (*string++) /* find end of string */ ; /* search towards front */ while (--string != start && *string != ch) ; if (*string == ch) /* wchar_t found ? */ return( (char *)string ); return(NULL);}/****wchar_t *_wcsrev(string) - reverse a wide-character string in place**Purpose:* Reverses the order of characters in the string. The terminating* null character remains in place (wide-characters).**Entry:* wchar_t *string - string to reverse**Exit:* returns string - now with reversed characters**Exceptions:********************************************************************************/wchar_t * _wcsrev (wchar_t * string) { wchar_t *start = string; wchar_t *left = string; wchar_t ch; while (*string++) /* find end of string */ ; string -= 2; while (left < string) { ch = *left; *left++ = *string; *string-- = ch; } return(start);}char * _strrev (char * string) { char *start = string; char *left = string; char ch; while (*string++) /* find end of string */ ; string -= 2; while (left < string) { ch = *left; *left++ = *string; *string-- = ch; } return(start);}/****wchar_t *_wcsset(string, val) - sets all of string to val (wide-characters)**Purpose:* Sets all of wchar_t characters in string (except the terminating '/0'* character) equal to val (wide-characters).***Entry:* wchar_t *string - string to modify* wchar_t val - value to fill string with**Exit:* returns string -- now filled with val's**Uses:**Exceptions:********************************************************************************/wchar_t * _wcsset (wchar_t * string, wchar_t val) { wchar_t *start = string; while (*string) *string++ = val; return(start);}#ifndef SHx#pragma function(_strset)#endifchar *_strset(char * string, int val) { char *start = string; while (*string) *string++ = val; return(start);}/****int wcsspn(string, control) - find init substring of control chars**Purpose:* Finds the index of the first character in string that does belong* to the set of characters specified by control. This is* equivalent to the length of the initial substring of string that* consists entirely of characters from control. The L'\0' character* that terminates control is not considered in the matching process* (wide-character strings).**Entry:* wchar_t *string - string to search* wchar_t *control - string containing characters not to search for**Exit:* returns index of first wchar_t in string not in control**Exceptions:********************************************************************************/size_t wcsspn(const wchar_t * string, const wchar_t * control) { wchar_t *str = (wchar_t *) string; wchar_t *ctl; /* 1st char not in control string stops search */ while (*str) { for (ctl = (wchar_t *)control; *ctl != *str; ctl++) if (*ctl == 0) /* reached end of control string without finding a match */ return str - string; str++; } /* The whole string consisted of characters from control */ return str - string;}size_t strspn(const char * string, const char * control) { char *str = (char *) string; char *ctl; /* 1st char not in control string stops search */ while (*str) { for (ctl = (char *)control; *ctl != *str; ctl++) if (*ctl == 0) /* reached end of control string without finding a match */ return str - string; str++; } /* The whole string consisted of characters from control */ return str - string;}/*******************************************************************************wchar_t *wcsstr(string1, string2) - search for string2 in string1 * (wide strings)**Purpose:* finds the first occurrence of string2 in string1 (wide strings)**Entry:* wchar_t *string1 - string to search in* wchar_t *string2 - string to search for**Exit:* returns a pointer to the first occurrence of string2 in* string1, or NULL if string2 does not occur in string1**Uses:**Exceptions:*********************************************************************************/wchar_t * wcsstr (const wchar_t * wcs1, const wchar_t * wcs2) { wchar_t *cp = (wchar_t *) wcs1; wchar_t *s1, *s2; while (*cp) { s1 = cp; s2 = (wchar_t *) wcs2; while ( *s1 && *s2 && !(*s1-*s2) ) s1++, s2++; if (!*s2) return(cp); cp++; } return(NULL);}/****wchar_t *wcstok(string, control) - tokenize string with delimiter in control* (wide-characters)**Purpose:* wcstok considers the string to consist of a sequence of zero or more* text tokens separated by spans of one or more control chars. the first* call, with string specified, returns a pointer to the first wchar_t of* the first token, and will write a null wchar_t into string immediately* following the returned token. subsequent calls with zero for the first* argument (string) will work thru the string until no tokens remain. the* control string may be different from call to call. when no tokens remain* in string a NULL pointer is returned. remember the control chars with a* bit map, one bit per wchar_t. the null wchar_t is always a control char* (wide-characters).**Entry:* wchar_t *string - wchar_t string to tokenize, or NULL to get next token* wchar_t *control - wchar_t string of characters to use as delimiters**Exit:* returns pointer to first token in string, or if string* was NULL, to next token* returns NULL when no more tokens remain.**Uses:**Exceptions:********************************************************************************/wchar_t * wcstok(wchar_t * string, const wchar_t * control) { wchar_t *token; const wchar_t *ctl; crtGlob_t *pcrt; if (!(pcrt = GetCRTStorage())) return 0; /* If string==NULL, continue with previous string */ if (!string) string = pcrt->wnexttoken; /* Find beginning of token (skip over leading delimiters). Note that * there is no token iff this loop sets string to point to the terminal * null (*string == '\0') */ while (*string) { for (ctl=control; *ctl && *ctl != *string; ctl++) ; if (!*ctl) break; string++; } token = string; /* Find the end of the token. If it is not the end of the string, * put a null there. */ for ( ; *string ; string++ ) { for (ctl=control; *ctl && *ctl != *string; ctl++) ; if (*ctl) { *string++ = '\0'; break; } } pcrt->wnexttoken = string; /* Determine if a token has been found. */ if (token == string) return NULL; else return token;}/****long _wtol(char *nptr) - Convert string to long**Purpose:* Converts ASCII string pointed to by nptr to binary.* Overflow is not detected.**Entry:* nptr = ptr to string to convert**Exit:* return long int value of the string**Exceptions:* None - overflow is not detected.********************************************************************************/long _wtol(const WCHAR *nptr) { WCHAR c; /* current char */ long total=0; /* current total */ int sign, digit; /* if '-', then negative, otherwise positive */ /* skip whitespace */ while (iswspace(*nptr)) ++nptr; // check for hex "0x" if (TEXT('0') == *nptr) nptr++; if (TEXT('x') == *nptr || TEXT('X') == *nptr) { nptr++; // skip the x while (c=*nptr++) { if (c >= TEXT('0') && c <= TEXT('9')) digit = c - TEXT('0'); else if (c >= TEXT('a') && c <= TEXT('f')) digit = (c - TEXT('a')) + 10; else if (c >= TEXT('A') && c <= TEXT('F')) digit = (c - TEXT('A')) + 10; else // invalid character break; total = 16 * total + digit; } return total; } // We are in decimal. c = *nptr++; sign = c; /* save sign indication */ if (c == TEXT('-') || c == TEXT('+')) c = *nptr++; /* skip sign */ while (c >= TEXT('0') && c <= TEXT('9')) { total = 10 * total + (c - TEXT('0')); /* accumulate digit */ c = *nptr++; /* get next char */ } if (sign == TEXT('-')) return -total; else return total; /* return result, negated if necessary */}/****long _wtoll(char *nptr) - Convert string to 64 bit integer**Purpose:* Converts ASCII string pointed to by nptr to binary.* Overflow is not detected.**Entry:* nptr = ptr to string to convert**Exit:* return __int64 value of the string**Exceptions:* None - overflow is not detected.********************************************************************************/__int64 _wtoll(const WCHAR *nptr) { WCHAR c; /* current char */ __int64 total; /* current total */ int sign; /* if '-', then negative, otherwise positive */ /* skip whitespace */ while (iswspace(*nptr)) ++nptr; c = *nptr++; sign = c; /* save sign indication */ if (c == TEXT('-') || c == TEXT('+')) c = *nptr++; /* skip sign */ total = 0; while (c >= TEXT('0') && c <= TEXT('9')) { total = 10 * total + (c - TEXT('0')); /* accumulate digit */ c = *nptr++; /* get next char */ } if (sign == TEXT('-')) return -total; else return total; /* return result, negated if necessary */}__int64 _atoi64(const char *nptr) { char c; /* current char */ __int64 total; /* current total */ int sign; /* if '-', then negative, otherwise positive */ /* skip whitespace */ while (isspace(*nptr)) ++nptr; c = *nptr++; sign = c; /* save sign indication */ if (c == '-' || c == '+') c = *nptr++; /* skip sign */ total = 0; while (c >= '0' && c <= '9') { total = 10 * total + (c - '0'); /* accumulate digit */ c = *nptr++; /* get next char */ } if (sign == '-') return -total; else return total; /* return result, negated if necessary */}char * _strlwr(char *pstr) { char *pTrav; for (pTrav = pstr; *pTrav; pTrav++) *pTrav = _tolower(*pTrav); return pstr;}char * _strupr(char *pstr) { char *pTrav; for (pTrav = pstr; *pTrav; pTrav++) *pTrav = _toupper(*pTrav); return pstr;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -