WSGetNumberAsUTF8String (C Function)

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

reads the next number of the WSTP connection specified by l as a string of UTF-8 characters representing the number value stored in the string s of length v with c characters.

Details

  • WSGetNumberAsUTF8String() allocates memory to store the string value. To release the memory allocated by WSGetNumberAsUTF8String(), call WSReleaseUTF8String() on the contents of s. If WSGetNumberAsUTF8String() fails, do not call WSReleaseUTF8String() on the contents of s.
  • WSGetNumberAsUTF8String() returns 0 on error and a nonzero value if the function succeeds.
  • WSGetNumberAsUTF8String() is declared in the WSTP header file wstp.h.

Examples

Basic Examples  (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:
            /* ... */
    }
}