Switch to unified view

a/src/utils/smallut.cpp b/src/utils/smallut.cpp
...
...
172
    }
172
    }
173
    }
173
    }
174
    return mcs1 == mcs2;
174
    return mcs1 == mcs2;
175
}
175
}
176
176
177
template <class T> bool stringToStrings(const string &s, T &tokens)
177
template <class T> bool stringToStrings(const string &s, T &tokens, 
178
                                        const string& addseps)
178
{
179
{
179
    string current;
180
    string current;
180
    tokens.clear();
181
    tokens.clear();
181
    enum states {SPACE, TOKEN, INQUOTE, ESCAPE};
182
    enum states {SPACE, TOKEN, INQUOTE, ESCAPE};
182
    states state = SPACE;
183
    states state = SPACE;
...
...
235
                continue;
236
                continue;
236
        }
237
        }
237
        break;
238
        break;
238
239
239
        default:
240
        default:
241
            if (!addseps.empty() && addseps.find(s[i]) != string::npos) {
240
      switch(state) {
242
                switch(state) {
241
            case ESCAPE:
243
                case ESCAPE:
242
                state = INQUOTE;
244
                    state = INQUOTE;
243
                break;
245
                    break;
246
                case INQUOTE: 
247
                    break;
244
            case SPACE: 
248
                case SPACE: 
249
                    tokens.insert(tokens.end(), string(1, s[i]));
250
                    continue;
251
                case TOKEN: 
252
                    tokens.insert(tokens.end(), current);
253
                    current.erase();
254
                    tokens.insert(tokens.end(), string(1, s[i]));
255
                    state = SPACE;
256
                    continue;
257
                }
258
            } else switch(state) {
259
                case ESCAPE:
260
                    state = INQUOTE;
261
                    break;
262
                case SPACE: 
245
                state = TOKEN;
263
                    state = TOKEN;
246
                break;
264
                    break;
247
            case TOKEN: 
265
                case TOKEN: 
248
            case INQUOTE: 
266
                case INQUOTE: 
249
                break;
267
                    break;
250
      }
268
                }
251
        current += s[i];
269
        current += s[i];
252
    }
270
    }
253
    }
271
    }
254
    switch(state) {
272
    switch(state) {
255
    case SPACE: 
273
    case SPACE: 
...
...
261
    case ESCAPE:
279
    case ESCAPE:
262
    return false;
280
    return false;
263
    }
281
    }
264
    return true;
282
    return true;
265
}
283
}
266
bool stringToStrings(const string &s, list<string> &tokens)
284
bool stringToStrings(const string &s, list<string> &tokens, 
285
                     const string& as)
267
{
286
{
268
    return stringToStrings<list<string> >(s, tokens);
287
    return stringToStrings<list<string> >(s, tokens, as);
269
}
288
}
270
bool stringToStrings(const string &s, vector<string> &tokens)
289
bool stringToStrings(const string &s, vector<string> &tokens, 
290
                     const string& as)
271
{
291
{
272
    return stringToStrings<vector<string> >(s, tokens);
292
    return stringToStrings<vector<string> >(s, tokens, as);
273
}
293
}
274
bool stringToStrings(const string &s, set<string> &tokens)
294
bool stringToStrings(const string &s, set<string> &tokens, 
295
                     const string& as)
275
{
296
{
276
    return stringToStrings<set<string> >(s, tokens);
297
    return stringToStrings<set<string> >(s, tokens, as);
277
}
298
}
278
299
279
template <class T> void stringsToString(const T &tokens, string &s) 
300
template <class T> void stringsToString(const T &tokens, string &s) 
280
{
301
{
281
    for (typename T::const_iterator it = tokens.begin();
302
    for (typename T::const_iterator it = tokens.begin();
...
...
727
    {"toto.txt", ".txt1"},
748
    {"toto.txt", ".txt1"},
728
    {"toto.txt1", ".txt"},
749
    {"toto.txt1", ".txt"},
729
};
750
};
730
int nsuffpairs = sizeof(suffpairs) / sizeof(struct spair);
751
int nsuffpairs = sizeof(suffpairs) / sizeof(struct spair);
731
752
753
const char *thisprog;
732
754
733
int main(int argc, char **argv)
755
int main(int argc, char **argv)
734
{
756
{
757
    thisprog = *argv++;argc--;
758
759
#if 1
760
    if (argc <=0 ) {
761
        cerr << "Usage: smallut <stringtosplit>" << endl;
762
        exit(1);
763
    }
764
    string s = *argv++;argc--;
765
    vector<string> vs;
766
    if (!stringToStrings(s, vs, ":-()")) {
767
        cerr << "Bad entry" << endl;
768
        exit(1);
769
    }
770
    for (vector<string>::const_iterator it = vs.begin(); it != vs.end(); it++)
771
        cerr << "[" << *it << "] ";
772
    cerr << endl;
773
    exit(0);
735
#if 0
774
#elif 0
736
    for (int i = 0; i < npairs; i++) {
775
    for (int i = 0; i < npairs; i++) {
737
    {
776
    {
738
        int c = stringicmp(pairs[i].s1, pairs[i].s2);
777
        int c = stringicmp(pairs[i].s1, pairs[i].s2);
739
        printf("'%s' %s '%s' ", pairs[i].s1, 
778
        printf("'%s' %s '%s' ", pairs[i].s1, 
740
           c == 0 ? "==" : c < 0 ? "<" : ">", pairs[i].s2);
779
           c == 0 ? "==" : c < 0 ? "<" : ">", pairs[i].s2);
...
...
766
#elif 0
805
#elif 0
767
    std::string testit("ligne\ndeuxieme ligne\r3eme ligne\r\n");
806
    std::string testit("ligne\ndeuxieme ligne\r3eme ligne\r\n");
768
    cout << "[" << neutchars(testit, "\r\n") << "]" << endl;
807
    cout << "[" << neutchars(testit, "\r\n") << "]" << endl;
769
    string i, o;
808
    string i, o;
770
    cout << "neutchars(null) is [" << neutchars(i, "\r\n") << "]" << endl;
809
    cout << "neutchars(null) is [" << neutchars(i, "\r\n") << "]" << endl;
771
#elif 1
810
#elif 0
772
    map<string, string> substs;
811
    map<string, string> substs;
773
    substs["a"] = "A_SUBST";
812
    substs["a"] = "A_SUBST";
774
    substs["title"] = "TITLE_SUBST";
813
    substs["title"] = "TITLE_SUBST";
775
    string in = "a: %a title: %(title) pcpc: %% %";
814
    string in = "a: %a title: %(title) pcpc: %% %";
776
    string out;
815
    string out;