Sha256: ea193d746c002739632f0f295f476079f3052a0f9117045ec6237df30c86f6bf

Contents?: true

Size: 1.44 KB

Versions: 6

Compression:

Stored size: 1.44 KB

Contents

/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
/* vi: set expandtab shiftwidth=4 tabstop=4: */

#include "arraytoc.h"

static void hexencodemap(void)
{
    static const char sHexChars[] = "0123456789ABCDEF";
    int i;
    char hexEncode1[256];
    char hexEncode2[256];
    for (i = 0; i < 256; ++i) {
        hexEncode1[i] = sHexChars[i >> 4];
        hexEncode2[i] = sHexChars[i & 0x0f];
    }

    char_array_to_c(hexEncode1, sizeof(hexEncode1), "gsHexEncodeMap1");
    char_array_to_c(hexEncode2, sizeof(hexEncode2), "gsHexEncodeMap2");
}

static void jsencodemap(void)
{
    int i;
    char jsEncodeMap[256];

    /* set everything to "as is" */
    for (i = 0; i < 256; ++i) {
        jsEncodeMap[i] = 0;
    }

    /* chars that need hex escaping */
    for (i = 0; i < 32; ++i) {
        jsEncodeMap[i] = 'A';
    }
    for (i = 127; i < 256; ++i) {
        jsEncodeMap[i] = 'A';
    }

    /* items that have special escaping */
    jsEncodeMap[0x08] = 'b';
    jsEncodeMap[0x09] = 't';
    jsEncodeMap[0x0a] = 'n';
    jsEncodeMap[0x0b] = 'v';
    jsEncodeMap[0x0c] = 'f';
    jsEncodeMap[0x0d] = 'r';
    jsEncodeMap[0x5c] = '\\'; /* blackslash gets escaped */
    jsEncodeMap[0x22] = '"'; /* dquote gets escaped */
    jsEncodeMap[0x27] = '\''; /* squote gets escaped */

    char_array_to_c(jsEncodeMap, sizeof(jsEncodeMap), "gsJavascriptEncodeMap");
}

int main(void)
{
    jsencodemap();
    hexencodemap();
    return 0;
}

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ffi-hydrogen-0.1.5 vendor/stringencoders/src/modp_bjavascript_gen.c
ffi-hydrogen-0.1.4 vendor/stringencoders/src/modp_bjavascript_gen.c
ffi-hydrogen-0.1.3 vendor/stringencoders/src/modp_bjavascript_gen.c
ffi-hydrogen-0.1.2 vendor/stringencoders/src/modp_bjavascript_gen.c
ffi-hydrogen-0.1.1 vendor/stringencoders/src/modp_bjavascript_gen.c
ffi-hydrogen-0.1.0 vendor/stringencoders/src/modp_bjavascript_gen.c