13d58139fSopenharmony_ci/* 23d58139fSopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2014-2021. All rights reserved. 33d58139fSopenharmony_ci * Licensed under Mulan PSL v2. 43d58139fSopenharmony_ci * You can use this software according to the terms and conditions of the Mulan PSL v2. 53d58139fSopenharmony_ci * You may obtain a copy of Mulan PSL v2 at: 63d58139fSopenharmony_ci * http://license.coscl.org.cn/MulanPSL2 73d58139fSopenharmony_ci * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 83d58139fSopenharmony_ci * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 93d58139fSopenharmony_ci * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 103d58139fSopenharmony_ci * See the Mulan PSL v2 for more details. 113d58139fSopenharmony_ci * Description: By defining data type for UNICODE string and including "input.inl", 123d58139fSopenharmony_ci * this file generates real underlying function used by scanf family API. 133d58139fSopenharmony_ci * Create: 2014-02-25 143d58139fSopenharmony_ci */ 153d58139fSopenharmony_ci 163d58139fSopenharmony_ci/* If some platforms don't have wchar.h, don't include it */ 173d58139fSopenharmony_ci#if !(defined(SECUREC_VXWORKS_PLATFORM)) 183d58139fSopenharmony_ci/* If there is no macro below, it will cause vs2010 compiling alarm */ 193d58139fSopenharmony_ci#if defined(_MSC_VER) && (_MSC_VER >= 1400) 203d58139fSopenharmony_ci#ifndef __STDC_WANT_SECURE_LIB__ 213d58139fSopenharmony_ci/* The order of adjustment is to eliminate alarm of Duplicate Block */ 223d58139fSopenharmony_ci#define __STDC_WANT_SECURE_LIB__ 0 233d58139fSopenharmony_ci#endif 243d58139fSopenharmony_ci#ifndef _CRTIMP_ALTERNATIVE 253d58139fSopenharmony_ci#define _CRTIMP_ALTERNATIVE /* Comment microsoft *_s function */ 263d58139fSopenharmony_ci#endif 273d58139fSopenharmony_ci#endif 283d58139fSopenharmony_ci#include <wchar.h> 293d58139fSopenharmony_ci#endif 303d58139fSopenharmony_ci 313d58139fSopenharmony_ci/* fix redefined */ 323d58139fSopenharmony_ci#undef SECUREC_ENABLE_WCHAR_FUNC 333d58139fSopenharmony_ci/* Disable wchar func to clear vs warning */ 343d58139fSopenharmony_ci#define SECUREC_ENABLE_WCHAR_FUNC 0 353d58139fSopenharmony_ci#define SECUREC_FORMAT_OUTPUT_INPUT 1 363d58139fSopenharmony_ci 373d58139fSopenharmony_ci#ifndef SECUREC_FOR_WCHAR 383d58139fSopenharmony_ci#define SECUREC_FOR_WCHAR 393d58139fSopenharmony_ci#endif 403d58139fSopenharmony_ci 413d58139fSopenharmony_ci#include "secinput.h" 423d58139fSopenharmony_ci 433d58139fSopenharmony_ci#include "input.inl" 443d58139fSopenharmony_ci 453d58139fSopenharmony_ciSECUREC_INLINE unsigned int SecWcharHighBits(SecInt ch) 463d58139fSopenharmony_ci{ 473d58139fSopenharmony_ci /* Convert int to unsigned int clear 571 */ 483d58139fSopenharmony_ci return ((unsigned int)(int)ch & (~0xffU)); 493d58139fSopenharmony_ci} 503d58139fSopenharmony_ci 513d58139fSopenharmony_ciSECUREC_INLINE unsigned char SecWcharLowByte(SecInt ch) 523d58139fSopenharmony_ci{ 533d58139fSopenharmony_ci /* Convert int to unsigned int clear 571 */ 543d58139fSopenharmony_ci return (unsigned char)((unsigned int)(int)ch & 0xffU); 553d58139fSopenharmony_ci} 563d58139fSopenharmony_ci 573d58139fSopenharmony_ciSECUREC_INLINE int SecIsDigit(SecInt ch) 583d58139fSopenharmony_ci{ 593d58139fSopenharmony_ci if (SecWcharHighBits(ch) != 0) { 603d58139fSopenharmony_ci return 0; /* Same as isdigit */ 613d58139fSopenharmony_ci } 623d58139fSopenharmony_ci return isdigit((int)SecWcharLowByte(ch)); 633d58139fSopenharmony_ci} 643d58139fSopenharmony_ci 653d58139fSopenharmony_ciSECUREC_INLINE int SecIsXdigit(SecInt ch) 663d58139fSopenharmony_ci{ 673d58139fSopenharmony_ci if (SecWcharHighBits(ch) != 0) { 683d58139fSopenharmony_ci return 0; /* Same as isxdigit */ 693d58139fSopenharmony_ci } 703d58139fSopenharmony_ci return isxdigit((int)SecWcharLowByte(ch)); 713d58139fSopenharmony_ci} 723d58139fSopenharmony_ci 733d58139fSopenharmony_ciSECUREC_INLINE int SecIsSpace(SecInt ch) 743d58139fSopenharmony_ci{ 753d58139fSopenharmony_ci return iswspace((wint_t)(int)(ch)); 763d58139fSopenharmony_ci} 773d58139fSopenharmony_ci 78