WSGetUTF8String (C Function)

int WSGetUTF8String(WSLINK link,const unsigned char **s,int *b,int *c)

gets a UTF-8 character string from the WSTP connection specified by link, storing the string in s, the number of bytes in the string in b, and the number of characters in the string in c.

Details

  • WSGetUTF8String() allocates memory for the character string. You must call WSReleaseUTF8String() to disown this memory. If WSGetUTF8String() fails and the function's return value indicates an error, do not call WSReleaseUTF8String() on the contents of s.
  • WSGetUTF8String() returns immutable data.
  • WSGetUTF8String() stores all characters directly in the UTF-8 Unicode encoding form.
  • WSGetUTF8String() returns 0 in the event of an error, and a nonzero value if the function succeeds.
  • Use WSError() to retrieve the error code if WSGetUTF8String() fails.
  • WSGetUTF8String() is declared in the WSTP header file wstp.h.

Examples

Basic Examples  (1)

#include "wstp.h"

/* read a UTF-8 encoded string from a link */

void f(WSLINK lp)
{
    const unsigned char *string;
    int bytes;
    int characters;

    if(! WSGetUTF8String(lp, &string, &bytes, &characters))
        {
            /* unable to read the UTF-8 string from lp */
            return;
        }

    /* use the string */

    WSReleaseUTF8String(lp, string, bytes);
}