| [1238] | 1 | #include "machdefs.h" | 
|---|
|  | 2 | #include <stdio.h> | 
|---|
|  | 3 | #include <stdlib.h> | 
|---|
| [2322] | 4 | #include <iostream> | 
|---|
| [1238] | 5 |  | 
|---|
|  | 6 | #include "strutilxx.h" | 
|---|
|  | 7 |  | 
|---|
|  | 8 |  | 
|---|
| [2511] | 9 | void FillVStringFrString(string const & s,vector<string>& vs,char sep) | 
|---|
| [1238] | 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 | { | 
|---|
|  | 20 | uint_4 ls = s.size(); | 
|---|
|  | 21 | if(ls<=0 || sep=='\\') return; | 
|---|
|  | 22 | const char* str = s.c_str(); | 
|---|
|  | 23 | ls = strlen(str); // str[ls-1]==sep cf ci-dessus | 
|---|
|  | 24 | string dum = ""; | 
|---|
|  | 25 | for(uint_4 i=0; i<ls; i++) { | 
|---|
|  | 26 | if(i==0 && str[i]==sep) { | 
|---|
|  | 27 | continue; | 
|---|
|  | 28 | } else if(str[i]=='\\') { | 
|---|
|  | 29 | if(str[i+1]!=sep || i==ls-2) dum += str[i]; | 
|---|
|  | 30 | } else if(str[i]!=sep) { | 
|---|
|  | 31 | dum += str[i]; | 
|---|
|  | 32 | } else {  // C'est un "sep" mais est-ce vraiment un separateur? | 
|---|
|  | 33 | if(str[i-1]=='\\' && i!=ls-1) dum += str[i]; | 
|---|
|  | 34 | else {  // C'est un separateur, ne delimite t-il pas d'autres separateurs? | 
|---|
|  | 35 | if(dum.size()<=0) continue; | 
|---|
|  | 36 | vs.push_back(dum); | 
|---|
|  | 37 | dum = ""; | 
|---|
|  | 38 | } | 
|---|
|  | 39 | } | 
|---|
|  | 40 | } | 
|---|
| [2514] | 41 | // Ajout du dernier mot eventuellement - Pas de separateur a la fin - | 
|---|
|  | 42 | if(dum.size() > 0)  vs.push_back(dum); | 
|---|
| [1238] | 43 | } | 
|---|