Library for Yodiwo's Plegma API

Revision:
3:96b08b5f998f
Parent:
0:384a04dc912e
Child:
6:4596aaa1a824
--- a/jsmn.c	Tue Sep 08 11:08:03 2015 +0000
+++ b/jsmn.c	Tue Sep 15 10:21:40 2015 +0000
@@ -2,6 +2,48 @@
 
 #include "jsmn.h"
 
+int strcpy_escaped(char *dest, char *src)
+{
+	char *scur = src;
+	char *dcur = dest;
+	while(*scur != '\0') {
+		if (*scur == '\"' || *scur == '\\') {
+			*(dcur++) = '\\';
+		}
+		*(dcur++) = *(scur++);
+	}
+	*dcur = '\0';
+	return dcur - dest;
+}
+
+int memcpy_unescaped(void *dest, void *src, int n_source)
+{
+	char *s = src;
+	char *d = dest;
+	int i;
+	int j = 0;
+	for(i = 0; i < n_source; i++, j++) {
+		if (s[i] == '\\' && i != n_source - 1)
+			i++;
+		d[j] = s[i];
+	}
+	return j - 1;
+}
+
+int count_escaped(char *buf, int len)
+{
+	int cnt = 0;
+	int i = 0;
+	while(i < len - 1) {
+		if (buf[i] == '\\') {
+			cnt++;
+			i++;
+		}
+		i++;
+	}
+	return cnt;
+}
+
 /**
  * Allocates a fresh unused token from the token pull.
  */