wchar.c

来自「ST5518机顶盒系统文件系统源代码!绝对超值!」· C语言 代码 · 共 145 行

C
145
字号
/******************************************************************************    File Name   : wchar.c    Description : A local implementation of wchar.h******************************************************************************//* Includes ---------------------------------------------------------------- */#include <stdlib.h>#include <stdio.h>#include <ctype.h>#include "wchar.h"/* Private Types ----------------------------------------------------------- *//* Private Constants ------------------------------------------------------- *//* Private Variables ------------------------------------------------------- *//* Private Macros ---------------------------------------------------------- *//* Private Function Prototypes --------------------------------------------- *//* Functions --------------------------------------------------------------- *//******************************************************************************Function Name : wcscpy  Description : Copy a wchar_t string into another   Parameters :******************************************************************************/wchar_t *wcscpy (wchar_t * dst, const wchar_t * src){    wchar_t *rtn = dst;    while (*src)        *dst++ = *src++;    *dst = L'\0';               /* final "\0" */    return rtn;}/******************************************************************************Function Name : wcslen  Description : Calculate length of a string of wchar_t   Parameters :******************************************************************************/int wcslen (const wchar_t * string){    const wchar_t *ptr = string;    int number = 0;    while (*ptr++)        number++;    return number;}/******************************************************************************Function Name : wcsncmp  Description : Compare two strings of wchar_t   Parameters :******************************************************************************/int wcsncmp (const wchar_t * string1, const wchar_t * string2, int MaxLength){    const wchar_t *str1, *str2;    int security = 0;    str1 = string1;    str2 = string2;    while ((*str1 == *str2) && (security++ < MaxLength) && *str1)    {        str1++;        str2++;    }    if (security >= MaxLength)        return 0;    if (*str1 < *str2)        return -1;    if (*str1 > *str2)        return 1;    return 0;}/******************************************************************************Function Name : wcscvt  Description : Convert a char* into a wchar_t*   Parameters :******************************************************************************/wchar_t *wcscvt (const char *input, wchar_t * output){    wchar_t *rtn = output;            while (*input)        *(output++) = (wchar_t) *(input++);            *output = L'\0';    return rtn;}/******************************************************************************Function Name : wcschr  Description : Searches for the first wide character in a wide string   Parameters :******************************************************************************/int wcschr (const wchar_t * ParsedString, wchar_t ElementToSearch){    const wchar_t *ptr = ParsedString;    int count = 0;    while (*ptr != ElementToSearch)    {        count++;        if (!*ptr++)            return -1;    }    return count;}/******************************************************************************Function Name : wcschr2  Description : Searches for the first wide character in a wide string.                We look for an occurs of either Element1 or Element2.                This function is heavily used.   Parameters :******************************************************************************/int wcschr2 (const wchar_t * ParsedString, wchar_t Element1, wchar_t Element2){    const wchar_t *ptr = ParsedString;    int count = 0;    while ((*ptr != Element1) && (*ptr != Element2))    {        count++;        if (!*ptr++)            return -1;    }    return count;}

⌨️ 快捷键说明

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