Thread overview |
---|
December 05, 2005 could string_tokeniser inlcude erase()? | ||||
---|---|---|---|---|
| ||||
Sometimes, the users may erase some items in delimited string. Consider this case: say the user want to search semicolon delimited files in a semicolon delimited directories, i.e. search "1.h;2.h" in "f:\sourcecode\1;f:\sourcecode\2". once the file is located, it should be deleted from semicolon delimited files, the code looks like: typedef string_tokeniser<string,char> tokeniser; tokeniser tokendirs("f:\sourcecode\1;f:\sourcecode\2",';'); tokeniser tokenfiles("1.h",';'); tokeniser::const_iterator dir = tokendirs.being(); tokeniser::const_iterator dirEnd = tokendirs.end(); for (; dir!= dirEnd && tokenfiles.size(); ++dir) { string files = join(tokenfiles); // i.e. get semicolon delimited string. string strDir(*dir); findfile_sequence file_seq(strDir.c_str(), files.c_str(), ';', findfile_sequence::files); findfile_sequence::const_iterator foundFile = file_seq.begin(); findfile_sequence::const_iterator foundFileEnd = file_seq.End(); for (; foundFile!= foundFileEnd; ++foundFile) { string sFile((*foundFile).get_filename()); tokeniser:: const_iterator iFound = find(tokenfiles.begin(),tokenfiles.end(),sFile); if (iFound != tokenfiles.end()) tokefiles.erase(iFound); // this function is helpful!!! } } corrently , I split delimited string into vector for applying this way. thanks chang |
December 05, 2005 Re: could string_tokeniser inlcude erase()? | ||||
---|---|---|---|---|
| ||||
Posted in reply to chenchang | I'm not 100% sure what you're driving at, but I'm pretty sure it's not appropriate for a general-purpose class template like string_tokeniser. One of its important features is that it is very efficient - in fact I believe it's pretty much the fastest tokeniser available - and adding a feature to change the string being tokenised would complicate it, and likely reduce its performance characteristics. But I'm very glad you're making good use of the libraries! ;-) "chenchang" <baibaichen@sohu.com> wrote in message news:dn15hr$hgk$1@digitaldaemon.com... > Sometimes, the users may erase some items in delimited string. > > Consider this case: say the user want to search semicolon delimited files > in > a semicolon delimited directories, i.e. search "1.h;2.h" in > "f:\sourcecode\1;f:\sourcecode\2". > > once the file is located, it should be deleted from semicolon delimited files, the code looks like: > > typedef string_tokeniser<string,char> tokeniser; > tokeniser tokendirs("f:\sourcecode\1;f:\sourcecode\2",';'); > tokeniser tokenfiles("1.h",';'); > > tokeniser::const_iterator dir = tokendirs.being(); > tokeniser::const_iterator dirEnd = tokendirs.end(); > > for (; dir!= dirEnd && tokenfiles.size(); ++dir) > { > string files = join(tokenfiles); // i.e. get semicolon delimited > string. > string strDir(*dir); > findfile_sequence file_seq(strDir.c_str(), files.c_str(), ';', > findfile_sequence::files); > > findfile_sequence::const_iterator foundFile = file_seq.begin(); > findfile_sequence::const_iterator foundFileEnd = file_seq.End(); > for (; foundFile!= foundFileEnd; ++foundFile) > { > string sFile((*foundFile).get_filename()); > tokeniser:: const_iterator iFound = > find(tokenfiles.begin(),tokenfiles.end(),sFile); > if (iFound != tokenfiles.end()) > tokefiles.erase(iFound); // this function is > helpful!!! > } > } > > corrently , I split delimited string into vector for applying this way. > > thanks > chang > > > |
December 05, 2005 Re: could string_tokeniser inlcude erase()? | ||||
---|---|---|---|---|
| ||||
Posted in reply to chenchang | btw, if you're doing sophisticated file-system searching, check out http://recls.org/. The docs are no better than those of STLSoft, but the library's well-tested and pretty useful. ;-) "chenchang" <baibaichen@sohu.com> wrote in message news:dn15hr$hgk$1@digitaldaemon.com... > Sometimes, the users may erase some items in delimited string. > > Consider this case: say the user want to search semicolon delimited files > in > a semicolon delimited directories, i.e. search "1.h;2.h" in > "f:\sourcecode\1;f:\sourcecode\2". > > once the file is located, it should be deleted from semicolon delimited files, the code looks like: > > typedef string_tokeniser<string,char> tokeniser; > tokeniser tokendirs("f:\sourcecode\1;f:\sourcecode\2",';'); > tokeniser tokenfiles("1.h",';'); > > tokeniser::const_iterator dir = tokendirs.being(); > tokeniser::const_iterator dirEnd = tokendirs.end(); > > for (; dir!= dirEnd && tokenfiles.size(); ++dir) > { > string files = join(tokenfiles); // i.e. get semicolon delimited > string. > string strDir(*dir); > findfile_sequence file_seq(strDir.c_str(), files.c_str(), ';', > findfile_sequence::files); > > findfile_sequence::const_iterator foundFile = file_seq.begin(); > findfile_sequence::const_iterator foundFileEnd = file_seq.End(); > for (; foundFile!= foundFileEnd; ++foundFile) > { > string sFile((*foundFile).get_filename()); > tokeniser:: const_iterator iFound = > find(tokenfiles.begin(),tokenfiles.end(),sFile); > if (iFound != tokenfiles.end()) > tokefiles.erase(iFound); // this function is > helpful!!! > } > } > > corrently , I split delimited string into vector for applying this way. > > thanks > chang > > > |
Copyright © 1999-2021 by the D Language Foundation