source: Sophya/trunk/SophyaLib/SUtils/strutilxx.cc@ 1238

Last change on this file since 1238 was 1238, checked in by ansari, 25 years ago
  • DAtaType -> DataTypeInfo
  • strutilxx pour gestion de string version c++ (/ strutil.cc,h en C).

cmv 18/10/00

File size: 1.3 KB
Line 
1#include "machdefs.h"
2#include <stdio.h>
3#include <stdlib.h>
4#include <iostream.h>
5
6#include "strutilxx.h"
7
8
9void FillVStringFrString(string s,vector<string>& vs,char sep)
10// Use string "s" to fill vector of strings "vs"
11// considering char "sep" as a separator.
12// Vector is filled from its end (no reset done).
13// Tp write a "sep" char, use \'sep'
14// Warning: separator "sep" could not be set to '\'
15// Ex: sep=' ': s="aaa bbb cc d " -> vs=(aaa,bbb,cc,d)
16// Ex: sep=';': s="aaa ;bbb; cc;d " -> vs=(aaa ,bbb, cc,d )
17// Ex: sep=';': s=";aaa\;bbb;;;ccc;ddd" -> vs=(aaa;bbb,ccc,ddd)
18// Ex: sep=';': s=";aaa\;bbb;;;ccc;ddd\" -> vs=(aaa;bbb,ccc,ddd\)
19{
20uint_4 ls = s.size();
21if(ls<=0 || sep=='\\') return;
22s += sep; // add a separator at the end
23const char* str = s.c_str();
24ls = strlen(str); // str[ls-1]==sep cf ci-dessus
25string dum = "";
26for(uint_4 i=0; i<ls; i++) {
27 if(i==0 && str[i]==sep) {
28 continue;
29 } else if(str[i]=='\\') {
30 if(str[i+1]!=sep || i==ls-2) dum += str[i];
31 } else if(str[i]!=sep) {
32 dum += str[i];
33 } else { // C'est un "sep" mais est-ce vraiment un separateur?
34 if(str[i-1]=='\\' && i!=ls-1) dum += str[i];
35 else { // C'est un separateur, ne delimite t-il pas d'autres separateurs?
36 if(dum.size()<=0) continue;
37 vs.push_back(dum);
38 dum = "";
39 }
40 }
41}
42}
Note: See TracBrowser for help on using the repository browser.