Sha256: 285cda599a5e7cf8a89bf024e64be0fbb4390e5c5d19b8f859a8fb8c649fc4d7

Contents?: true

Size: 797 Bytes

Versions: 54

Compression:

Stored size: 797 Bytes

Contents

#include <assert.h>
#include <stdio.h>
#include <string.h>

#include "houdini.h"

int
houdini_unescape_js(gh_buf *ob, const uint8_t *src, size_t size)
{
	size_t  i = 0, org, ch;

	while (i < size) {
		org = i;
		while (i < size && src[i] != '\\')
			i++;

		if (likely(i > org)) {
			if (unlikely(org == 0)) {
				if (i >= size)
					return 0;

				gh_buf_grow(ob, HOUDINI_UNESCAPED_SIZE(size));
			}

			gh_buf_put(ob, src + org, i - org);
		}

		/* escaping */
		if (i == size)
			break;

		if (++i == size) {
			gh_buf_putc(ob, '\\');
			break;
		}

		ch = src[i];

		switch (ch) {
		case 'n':
			ch = '\n';
			/* pass through */

		case '\\':
		case '\'':
		case '\"':
		case '/':
			gh_buf_putc(ob, ch);
			i++;
			break;

		default:
			gh_buf_putc(ob, '\\');
			break;
		}
	}

	return 1;
}

Version data entries

54 entries across 54 versions & 4 rubygems

Version Path
hamlit-2.1.1 ext/hamlit/houdini/houdini_js_u.c
hamlit-2.1.0 ext/hamlit/houdini/houdini_js_u.c
faml-0.7.2 vendor/houdini/houdini_js_u.c
hamlit-2.0.2 ext/hamlit/houdini/houdini_js_u.c
faml-0.7.1 vendor/houdini/houdini_js_u.c
hamlit-2.0.1 ext/hamlit/houdini/houdini_js_u.c
faml-0.7.0 vendor/houdini/houdini_js_u.c
faml-0.6.5 vendor/houdini/houdini_js_u.c
faml-0.6.4 vendor/houdini/houdini_js_u.c
faml-0.6.3 vendor/houdini/houdini_js_u.c
faml-0.6.2 vendor/houdini/houdini_js_u.c
faml-0.6.1 vendor/houdini/houdini_js_u.c
faml-0.6.0 vendor/houdini/houdini_js_u.c
faml-0.5.1 vendor/houdini/houdini_js_u.c
faml-0.5.0 vendor/houdini/houdini_js_u.c
faml-0.4.2 vendor/houdini/houdini_js_u.c
faml-0.4.1 vendor/houdini/houdini_js_u.c
faml-0.4.0 vendor/houdini/houdini_js_u.c
faml-0.3.6 vendor/houdini/houdini_js_u.c
faml-0.3.5 vendor/houdini/houdini_js_u.c