File: easyxs_string.h

package info (click to toggle)
libpromise-xs-perl 0.20-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 908 kB
  • sloc: perl: 1,097; ansic: 355; makefile: 3
file content (24 lines) | stat: -rw-r--r-- 657 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef EASYXS_STRING_H
#define EASYXS_STRING_H 1

#include "init.h"

static inline char* _easyxs_sv_to_str (pTHX_ SV* sv, U8 is_utf8) {
    if (SvROK(sv)) _EASYXS_CROAK_STRINGIFY_REFERENCE(sv);

    char *str = is_utf8 ? SvPVutf8_nolen(sv) : SvPVbyte_nolen(sv);

    size_t len = strlen(str);
    if (len != SvCUR(sv)) {
        croak("Cannot convert scalar to C string (NUL byte detected, offset %" UVf ")", (UV) len);
    }

    return str;
}

/* ---------------------------------------------------------------------- */

#define exs_SvPVbyte_nolen(sv) _easyxs_sv_to_str(aTHX_ sv, 0)
#define exs_SvPVutf8_nolen(sv) _easyxs_sv_to_str(aTHX_ sv, 1)

#endif