Very old versions for history.
[opsoft_archive.git] / silentbob / silent_bob-1.2 / src / sblib / split_to_words.cpp
blobd78a12839db83748552e66662025667dce1acab7
1 /*
2 * (c) Oleg Puchinin 2006.
3 * graycardinalster@gmail.com
5 */
7 #include "../head.h"
8 #include "../dbg.h"
9 #include "inline.h"
11 DArray * split_to_words (char * d_op)
13 DArray * d_Ret = new DArray (16);
14 char * d_old = strdup (d_op);
15 bool b_done = false;
16 char * S = d_old;
17 char * d_end;
18 char ch;
20 if (d_Ret == NULL || d_old == NULL)
21 return NULL;
23 while (true) {
24 b_done = false;
25 d_end = S;
27 if (*d_end == ' ')
28 d_end++;
30 while (*d_end) {
31 if (!(if_abc(d_end) ||
32 if_digit (d_end) ||
33 *d_end == '_' ||
34 *d_end == ' ') )
35 break;
36 d_end ++;
39 if (! *d_end) {
40 ch = 0;
41 b_done = true;
42 goto split_to_words_L1;
45 ch = *d_end;
46 if (d_end[-1] == ' ')
47 d_end[-1] = 0;
48 else
49 *d_end = 0;
51 while (*S && *S == ' ')
52 S++;
54 split_to_words_L1:
55 d_Ret->add (LPCHAR(new_cword (S, ch)));
57 if (b_done)
58 break;
60 if (ch == '\"' || ch == '\'') {
61 *d_end = ch;
62 d_end = sstrend (d_end);
63 assert (d_end == NULL, "Lena 1");
64 if (*d_end == '\0' || *(++d_end) == '\0')
65 break;
68 S = d_end + 1;
71 DROP (d_old);
72 return d_Ret;