Esempio n. 1
0
/* C Strings {{{ */
CYUTF8String CYPoolUTF8String(CYPool &pool, CYUTF16String utf16) {
    // XXX: this is wrong
    size_t size(utf16.size * 5);
    char *temp(new(pool) char[size]);

    const uint16_t *lhs(utf16.data);
    uint8_t *rhs(reinterpret_cast<uint8_t *>(temp));
    _assert(ConvertUTF16toUTF8(&lhs, lhs + utf16.size, &rhs, rhs + size, lenientConversion) == conversionOK);

    *rhs = 0;
    return CYUTF8String(temp, reinterpret_cast<char *>(rhs) - temp);
}
Esempio n. 2
0
static CYUTF8String Run(CYPool &pool, int client, CYUTF8String code) {
    const char *json;
    uint32_t size;

    if (client == -1) {
        mode_ = Running;
#ifdef CY_EXECUTE
        json = CYExecute(pool, code);
#else
        json = NULL;
#endif
        mode_ = Working;
        if (json == NULL)
            size = 0;
        else
            size = strlen(json);
    } else {
        mode_ = Sending;
        size = code.size;
        CYSendAll(client, &size, sizeof(size));
        CYSendAll(client, code.data, code.size);
        mode_ = Waiting;
        CYRecvAll(client, &size, sizeof(size));
        if (size == _not(uint32_t))
            json = NULL;
        else {
            char *temp(new(pool) char[size + 1]);
            CYRecvAll(client, temp, size);
            temp[size] = '\0';
            json = temp;
        }
        mode_ = Working;
    }

    return CYUTF8String(json, size);
}
Esempio n. 3
0
static void Run(int client, bool syntax, const char *data, size_t size, std::ostream *out = NULL, bool expand = false) {
    CYPool pool;
    Output(syntax, Run(pool, client, CYUTF8String(data, size)), out, expand);
}
Esempio n. 4
0
static CYUTF8String Run(CYPool &pool, int client, const std::string &code) {
    return Run(pool, client, CYUTF8String(code.c_str(), code.size()));
}