jstrtok.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 105 行

C
105
字号
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/


#include "variety.h"
#include <jctype.h>
#include <jstring.h>


/**
*
*  Name:        jstrtok         暥帤楍傪嬪愗暥帤偱暘妱偡傞
*
*  Synopsis:    sp = jstrtok( targ, brk );
*
*               JSTRING sp;     暘妱偟偨暥帤楍
*               JSTRING targ;   暥帤楍
*               JSTRING brk;    嬪愗暥帤
*
*  Description: 暥帤楍倲倎倰倗傪暥帤楍倐倰倠撪偵偁傞暥帤傪嬪愗暥帤
*               偲偟偰暘妱偡傞丅嵟弶偺屇傃弌偟偱侾屄栚偺暘妱偟偨暥
*               帤楍傊偺億僀儞僞偑曉偝傟傞丅俀夞栚偐傜偼倲倎倰倗傪
*               俶倀俴俴偵偟偰屇傃弌偡偙偲偵傛傝丄弴偵暘妱偟偨暥帤
*               楍傊偺億僀儞僞偑曉偝傟傞丅
*
*  Returns:     僰儖暥帤偵払偟偨応崌偼僰儖丒億僀儞僞偑曉偝傟傞丅
*
*  Caution:     尦偺暥帤楍偼丄僰儖暥帤偑忋彂偒偝傟傞帠偵傛傝彂偒姺
*               偊傜傟傞丅
*
*
*  Name:        jstrtok         Break 2-byte KANJI string into tokens of KANJI
*
*  Synopsis:    sp = jstrtok( targ, brk );
*
*               JSTRING sp;     Broken string
*               JSTRING targ;   2-byte KANJI string
*               JSTRING brk;    Sequence of 2-byte KANJI delimiters
*
*  Description: Break the 2-byte KANJI string pointed to by targ into a
*               sequence of tokens of 2-byte KANJI, each of which is delimited
*               by a character from the string pointed to by brk. The first
*               call to jstrtok will return a pointer to the first token in the
*               string pointed to by targ. Subsequence calls to jstrtok must
*               pass a NULL pointer as the first argument, in order to get the
*               next token in the string.
*
*  Returns:     jstrtok function returns a pointer to the first character of
*               token or NULL if there is no token found.
*
*  Caution:     The given string is overwritten by NULL character.
*
**/

_WCRTLINK JSTRING jstrtok( JCHAR *targ, const JCHAR *brk )
{
    static JCHAR *sp;
    JCHAR *p, *q, *r;

    p = ( targ == NULL ) ? sp : targ;
    if( p == NULL ) return( NULL );
    q = jstrskip( p, brk );
    if( q == NULL ) return( NULL );
    if( *q == '\0' || ( iskanji( *q ) && q[1] == '\0' ) )
        return( NULL );
    r = jstrmatch( q, brk );
    if( r == NULL ) return( NULL );
    if( *r == '\0' ) {
        sp = NULL;
    } else {
        if( iskanji( *r ) ) *r++ = '\0';
        *r = '\0';
        sp = ++r;
    }
    return( q );
}

⌨️ 快捷键说明

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