⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 strings.c

📁 不错的东西 请查看 WINCE OS
💻 C
📖 第 1 页 / 共 2 页
字号:
*Exit:
*	returns a pointer to the first character from control found
*	in string.
*	returns NULL if string and control have no characters in common.
*
*Exceptions:
*
*******************************************************************************/

wchar_t * wcspbrk(const wchar_t * string, const wchar_t * control) {
    wchar_t *wcset;
    /* 1st char in control string stops search */
    while (*string) {
        for (wcset = (wchar_t *) control; *wcset; wcset++)
            if (*wcset == *string)
                return (wchar_t *) string;
        string++;
    }
    return NULL;
}

/* These functions are implemented for x86 under crtw32\strings\x86 */
#if !defined(_M_IX86)
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;
}
#endif // _M_IX86

/***
*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;

	/* find end of string */
	while (*string++);

	/* search towards front */
	while (--string != start && *string != ch);
	if (*string == ch)			/* wchar_t found ? */
		return( (wchar_t *)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);
}

/* These functions are implemented for x86 under crtw32\strings\x86 */
#if !defined(_M_IX86)
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);
}
#endif // _M_IX86

#pragma function(_wcsset)

/***
*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);
}

#if !defined(M32R) && !defined(_M_IX86)

#pragma function(_strset)

char *_strset(char * string, int val) {
	char *start = string;
	while (*string)
		*string++ = val;
	return(start);
}

#endif

/***
*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;
}

/* These functions are implemented for x86 under crtw32\strings\x86 */
#if !defined(_M_IX86)
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;
}
#endif // _M_IX86

/******************************************************************************
*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;
	if (!*wcs2)
	    return((wchar_t *)wcs1);
	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 land ...    
	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) {
	/* Performance note:  avoid char arithmetic on RISC machines. (4-byte regs) */
	int 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) {
	/* Performance note:  use unsigned char on RISC machines to avoid sign extension in 4-byte regs. */
	unsigned char *pTrav;
	for (pTrav = pstr; *pTrav; pTrav++)
		*pTrav = _tolower(*pTrav);
	return pstr;
}

char * _strupr(char *pstr) {
	/* Performance note:  use unsigned char on RISC machines to avoid sign extension in 4-byte regs. */
	unsigned char *pTrav;
	for (pTrav = pstr; *pTrav; pTrav++)
		*pTrav = _toupper(*pTrav);
	return pstr;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -