WSGetNumberAsUTF8String (C 函数)

int WSGetNumberAsUTF8String(WSLINK l, const unsigned char **s, int *v, int *c)

读取由 l 指定的 WSTP 连接上的下一个数字,作为 UTF-8 字符的一个字符串,表示存储于字符 c 和长度为 v 的字符串 s 的数字值.

更多信息

  • WSGetNumberAsUTF8String() 可分配内存以储存字符串值. 可调用有 s 内容的 WSReleaseUTF8String() 来释放由 WSGetNumberAsUTF8String() 分配的内存. 若 WSGetNumberAsUTF8String() 失败,则不要调用有 s 内容的 WSReleaseUTF8String().
  • 若发生错误,则 WSGetNumberAsUTF8String() 返回0;若函数成功,则返回非零值.
  • WSTP 的标头文件 wstp.h. 已对 WSGetNumberAsUTF8String() 作出声明.

范例

基本范例  (1)

#include "wstp.h"

/* A function for reading an integer from a link */

void f(WSLINK l)
{
    switch(WSGetType(l))
    {
        case WSTKINT:
        {
            int rawType;
            rawType = WSGetRawType(l);
            if(rawType == WSTK_WSSHORT)
            {
                short theNumber;
                WSGetInteger16(l, &theNumber);
                /* ... */
            }
            else if(rawType == WSTK_WSINT)
            {
                int theNumber;
                WSGetInteger32(l, &theNumber);
                /* ... */
            }
            else
            {
                const unsigned char *theNumber;
                int length, characters;
                WSGetNumberAsUTF8String(l, &theNumber, &length, &characters);
                /* ... */
                WSReleaseUTF8String(l, theNumber, length);
            }
        }
        break;
        case WSTKREAL:
            /* ... */
    }
}