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

Last change on this file since 2514 was 2514, checked in by ansari, 22 years ago

correction erreur suite a changmenet string en string const & ds strutilxx.h .cc - Reza 16 Mars 2004

File size: 1.4 KB
Line 
1#include "machdefs.h"
2#include <stdio.h>
3#include <stdlib.h>
4#include <iostream>
5
6#include "strutilxx.h"
7
8
9void FillVStringFrString(string const & 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;
22const char* str = s.c_str();
23ls = strlen(str); // str[ls-1]==sep cf ci-dessus
24string dum = "";
25for(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}
41// Ajout du dernier mot eventuellement - Pas de separateur a la fin -
42if(dum.size() > 0) vs.push_back(dum);
43}
Note: See TracBrowser for help on using the repository browser.