File: common.c

package info (click to toggle)
gnutls28 3.8.11-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 82,372 kB
  • sloc: ansic: 391,853; asm: 117,804; sh: 18,780; makefile: 6,801; yacc: 1,858; python: 1,399; cpp: 1,243; perl: 995; sed: 39
file content (43 lines) | stat: -rw-r--r-- 729 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
char *escape_string(const char *str, char *buffer, int buffer_size)
{
	int i = 0, j = 0;

	while (str[i] != 0 && j < buffer_size - 1) {
		if (str[i] == '_') {
			buffer[j++] = '\\';
			buffer[j++] = '_';
			buffer[j++] = '\\';
			buffer[j++] = '-';
		} else if (str[i] == '#') {
			buffer[j++] = '\\';
			buffer[j++] = '#';
		} else {
			buffer[j++] = str[i];
		}
		i++;
	};

	buffer[j] = 0;

	return buffer;
}

char *escape_texi_string(const char *str, char *buffer, int buffer_size)
{
	int i = 0, j = 0;

	while (str[i] != 0 && j < buffer_size - 1) {
		if (str[i] == '_') {
			buffer[j++] = '_';
			buffer[j++] = '@';
			buffer[j++] = '-';
		} else {
			buffer[j++] = str[i];
		}
		i++;
	};

	buffer[j] = 0;

	return buffer;
}