Very old versions for history.
[opsoft_archive.git] / silentbob / silentbob-1.1 / src / sblib / sstrend.cpp
blob3ce96c7429d944066bd059d5d3e9f008b6203f25
1 /*
2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
5 */
7 char * sstrend (char * d_ptr)
9 bool t_instring = false;
10 int d_slash_count;
11 char ch_last;
12 char *d_old;
13 unsigned limit = 1024;
15 if (! d_ptr)
16 return (char *) 0;
18 if (!(*d_ptr))
19 return (char *) 0;
21 ch_last = *d_ptr;
22 d_old = d_ptr;
23 limit--;
24 while (*d_ptr && (limit > 0)) {
25 if (*d_ptr == '\'' || *d_ptr == '\"') {
26 if (t_instring && *d_ptr != ch_last) {
27 d_ptr++;
28 continue; // Mmm...
31 if (t_instring) {
32 if (d_ptr[-1] == '\\') {
33 d_slash_count = 1;
34 while (d_ptr [-(d_slash_count)] == '\\')
35 d_slash_count++;
37 if (d_slash_count & 1)
38 t_instring = false;
39 } else {
40 d_ptr++;
41 t_instring = false;
42 continue;
44 } else {
45 ch_last = *d_ptr;
46 t_instring = true;
50 if (t_instring) {
51 d_ptr++;
52 continue;
53 } else
54 break;
57 d_ptr --;
59 if (*d_ptr == 0)
60 return 0;
62 return d_ptr;