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
faml-0.3.4 vendor/houdini/houdini_js_u.c
faml-0.3.3 vendor/houdini/houdini_js_u.c
faml-0.3.2 vendor/houdini/houdini_js_u.c
escape_utils-1.1.0 ext/escape_utils/houdini_js_u.c
escape_utils-1.0.1 ext/escape_utils/houdini_js_u.c
escape_utils-1.0.0 ext/escape_utils/houdini_js_u.c
walters-0.3.0 xni-ext/houdini/houdini_js_u.c
walters-0.2.0 xni-ext/houdini/houdini_js_u.c
walters-0.1.1 xni-ext/houdini/houdini_js_u.c
walters-0.1.0 xni-ext/houdini/houdini_js_u.c
walters-0.0.1 ext/houdini/houdini_js_u.c
escape_utils-0.3.2 ext/escape_utils/houdini_js_u.c
escape_utils-0.3.1 ext/escape_utils/houdini_js_u.c
escape_utils-0.3.0 ext/escape_utils/houdini_js_u.c