summaryrefslogtreecommitdiffstats
path: root/private/crt32/mbstring/mbschr.c
blob: a42109344ed4ebb28ae1a3aafd2e861a040f5bf2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*** 
* mbschr.c - Search MBCS string for character
*
*	Copyright (c) 1985-1993, Microsoft Corporation.  All rights reserved.
*
*Purpose:
*	Search MBCS string for a character
*
*Revision History:
*	11-19-92  KRS	Ported from 16-bit sources.
*	05-12-93  KRS	Fix handling of c=='\0'.
*	08-20-93  CFW   Change param type to int, use new style param declarators.
*
*******************************************************************************/

#ifdef _MBCS
#include <cruntime.h>
#include <mbdata.h>
#include <mbctype.h>
#include <mbstring.h>
#include <stddef.h>

/***
* _mbschr - Search MBCS string for character
*
*Purpose:
*	Search the given string for the specified character.
*	MBCS characters are handled correctly.
*
*Entry:
*	unsigned char *string = string to search
*	int c = character to search for
*
*Exit:
*	returns a pointer to the first occurence of the specified char
*	within the string.
*
*	returns NULL if the character is not found n the string.
*
*Exceptions:
*
*******************************************************************************/


unsigned char * _CRTAPI1 _mbschr(
    const unsigned char *string,
    unsigned int c
    )
{
    unsigned short cc;

    for (; (cc = *string); string++) {

            if (_ISLEADBYTE(cc)) {			
                if (*++string == '\0')
                    return NULL;	/* error */
                if ( c == (unsigned int)((cc << 8) | *string) ) /* DBCS match */
                    return (unsigned char *)(string - 1);
                } 
            else if (c == (unsigned int)cc)
                break;	/* SBCS match */
        }
    if (c == (unsigned int)cc)	/* check for SBCS match--handles NUL char */
        return (unsigned char *)(string);
    return NULL;
}
#endif	/* _MBCS */