ReactOS 0.4.16-dev-927-g467dec4
mbschr.cpp
Go to the documentation of this file.
1/***
2* mbschr.c - Search MBCS string for character
3*
4* Copyright (c) Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* Search MBCS string for a character
8*
9*******************************************************************************/
10#ifndef _MBCS
11 #error This file should only be compiled with _MBCS defined
12#endif
13
15#include <locale.h>
16#include <stddef.h>
17#include <string.h>
18
19#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26018
20
21/***
22* _mbschr - Search MBCS string for character
23*
24*Purpose:
25* Search the given string for the specified character.
26* MBCS characters are handled correctly.
27*
28*Entry:
29* unsigned char *string = string to search
30* int c = character to search for
31*
32*Exit:
33* returns a pointer to the first occurence of the specified char
34* within the string.
35*
36* returns nullptr if the character is not found n the string.
37*
38*Exceptions:
39* Input parameters are validated. Refer to the validation section of the function.
40*
41*******************************************************************************/
42
43
44extern "C" _CONST_RETURN unsigned char * __cdecl _mbschr_l(
45 const unsigned char *string,
46 unsigned int c,
48 )
49{
50 unsigned short cc = '\0';
51 _LocaleUpdate _loc_update(plocinfo);
52
53 /* validation section */
54 _VALIDATE_RETURN(string != nullptr, EINVAL, nullptr);
55
56 if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0)
57 return (_CONST_RETURN unsigned char *)strchr((const char *)string, (int)c);
58
59 for (; (cc = *string) != '\0'; string++)
60 {
61 if ( _ismbblead_l(cc, _loc_update.GetLocaleT()) )
62 {
63 if (*++string == '\0')
64 return nullptr; /* error */
65 if ( c == (unsigned int)((cc << 8) | *string) ) /* DBCS match */
66 return (unsigned char *)(string - 1);
67 }
68 else if (c == (unsigned int)cc)
69 break; /* SBCS match */
70 }
71
72 if (c == (unsigned int)cc) /* check for SBCS match--handles NUL char */
73 return (unsigned char *)(string);
74
75 return nullptr;
76}
77
78extern "C" _CONST_RETURN unsigned char * (__cdecl _mbschr)(
79 const unsigned char *string,
80 unsigned int c
81 )
82{
83 return _mbschr_l(string, c, nullptr);
84}
#define EINVAL
Definition: acclib.h:90
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define __cdecl
Definition: accygwin.h:79
#define _ismbblead_l(_c, p)
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
const GLubyte * c
Definition: glext.h:8905
_locale_t plocinfo
Definition: ismbbyte.cpp:75
uint32_t cc
Definition: isohybrid.c:75
_CONST_RETURN unsigned char *__cdecl _mbschr(const unsigned char *string, unsigned int c)
Definition: mbschr.cpp:78
_CONST_RETURN unsigned char *__cdecl _mbschr_l(const unsigned char *string, unsigned int c, _locale_t plocinfo)
Definition: mbschr.cpp:44
char string[160]
Definition: util.h:11
#define _CONST_RETURN
Definition: memory.h:16