本文整理汇总了C++中CVectorSString::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ CVectorSString::push_back方法的具体用法?C++ CVectorSString::push_back怎么用?C++ CVectorSString::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CVectorSString
的用法示例。
在下文中一共展示了CVectorSString::push_back方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exactLookupByKey
/*
* Set the result vector with the word(s) corresponding to the key
*/
void CWordsDictionary::exactLookupByKey( const CSString& key, CVectorSString& resultVec )
{
// Search
for ( CVectorSString::const_iterator ivs=_Keys.begin(); ivs!=_Keys.end(); ++ivs )
{
if ( key == *ivs )
resultVec.push_back( _Words[ivs-_Keys.begin()] );
}
}
示例2: lookup
/*
* Set the result vector with strings corresponding to the input string:
* - If inputStr is partially or completely found in the keys, all the matching <key,words> are returned;
* - If inputStr is partially or completely in the words, all the matching <key, words> are returned.
* The following tags can modify the behaviour of the search algorithm:
* - ^mystring returns mystring only if it is at the beginning of a key or word
* - mystring$ returns mystring only if it is at the end of a key or word
* All returned words are in UTF8.
*/
void CWordsDictionary::lookup( const CSString& inputStr, CVectorSString& resultVec ) const
{
// Prepare search string
if ( inputStr.empty() )
return;
CSString searchStr = inputStr;
bool findAtBeginning = false, findAtEnd = false;
if ( searchStr[0] == '^' )
{
searchStr = searchStr.substr( 1 );
findAtBeginning = true;
}
if ( searchStr[searchStr.size()-1] == '$' )
{
searchStr = searchStr.rightCrop( 1 );
findAtEnd = true;
}
// Search
const vector<string> &vec = reinterpret_cast<const vector<string>&>(_Keys);
// for ( CVectorSString::const_iterator ivs=_Keys.begin(); ivs!=_Keys.end(); ++ivs )
for ( vector<string>::const_iterator ivs=vec.begin(); ivs!=vec.end(); ++ivs )
{
const CSString& key = *ivs;
string::size_type p;
if ( (p = key.findNS( searchStr.c_str() )) != string::npos )
{
if ( ((!findAtBeginning) || (p==0)) && ((!findAtEnd) || (p==key.size()-searchStr.size())) )
resultVec.push_back( makeResult( key, _Words[ivs-vec.begin()] ) );
}
}
for ( CVectorSString::const_iterator ivs=_Words.begin(); ivs!=_Words.end(); ++ivs )
{
const CSString& word = *ivs;
string::size_type p;
if ( (p = word.findNS( searchStr.c_str() )) != string::npos )
{
if ( ((!findAtBeginning) || (p==0)) && ((!findAtEnd) || (p==word.size()-searchStr.size())) )
resultVec.push_back( makeResult( _Keys[ivs-_Words.begin()], word ) );
}
}
}
示例3: importCsv
// read .csv file to fill the structures 'items' and 'fields'
int importCsv(const char *filename)
{
verifCsvFile(filename);
char buffer[1024];
FILE *f = fopen(filename, "r");
if (f == NULL)
nlerror("Can't open file : %s", filename);
// read fields name
{
fgets(buffer, 1024, f);
CSString s(buffer);
s = s.strtok("\n");
do
{
fields.push_back(s.splitTo(';', true));
} while (s != "");
}
// read values for each item
while (fgets(buffer, 1024, f))
{
CSString s(buffer), val;
// first is the number
val = (s.splitTo(';', true));
uint n = val.atosi();
// resize if needed
if (n+1 > items.size())
items.resize(n+1);
// add item id
items[n].push_back(val);
// add others
do
{
val = s.splitTo(';', true);
items[n].push_back(val);
} while (s != "");
}
fclose(f);
return 0;
}
示例4: getFieldsFromFile
// fill 'fields' structure with values from file
int getFieldsFromFile(const char *filename)
{
FILE *f = fopen(filename, "r");
if (f == NULL)
nlerror("Can't open file : %s", filename);
char buffer[1024];
while (fgets(buffer, 1024, f))
{
CSString s(buffer);
s = s.strtok("\n");
// skip null or comment
if (s.empty() || s.find("//") == 0)
continue;
// add the field
fields.push_back(s);
}
fclose(f);
return 0;
}
示例5: main
int main(int argc, char *argv[])
{
string csvFile, itemsFile, scriptFile, curDir;
// check number of arguments
if (argc != 3)
nlerror("Bad arguments number !");
curDir = CPath::standardizePath(CPath::getCurrentPath());
// check extensions
{
string ext = CFile::getExtension(argv[2]);
if (ext == "csv")
csvFile = argv[2];
else if (ext == "script")
scriptFile = argv[2];
else
nlerror("Bad extension : %s (use .csv or .script)", ext.c_str());
itemsFile = argv[1];
}
// create a .csv file
if (scriptFile != "")
{
if (CFile::getFilename(scriptFile) == scriptFile)
scriptFile = curDir + scriptFile;
if (CFile::getFilename(itemsFile) == itemsFile)
itemsFile = curDir + itemsFile;
// auto-add : _LocSlot & _PhraseId & _SheetId & _Recommended
fields.push_back("_LocSlot");
fields.push_back("_PhraseId");
fields.push_back("_SheetId");
fields.push_back("_Recommended");
// add other fields from file
getFieldsFromFile(scriptFile.c_str());
// verify file
verifItemsFile(itemsFile.c_str());
// How many items ?
uint n = getNbItemFromFile(itemsFile.c_str()) + 1;
items.resize(n);
// reserve memory
for (uint i=0 ; i<n ; i++)
items[i].resize(fields.size());
// read values from items file
getItemsFromFile(itemsFile.c_str());
// generate the new file
string csv = CFile::getFilename(itemsFile);
string ext = CFile::getExtension(csv);
exportCsv((CSString(csv).replace(string('.' + ext).c_str(), ".csv")).c_str());
}
// create a .txt file
if (csvFile != "")
{
if (CFile::getFilename(csvFile) == csvFile)
csvFile = curDir + csvFile;
// load csv values
importCsv(csvFile.c_str());
if (!itemsFile.empty() && CFile::isExists(itemsFile.c_str()))
updateItems(itemsFile.c_str());
else
nlerror("Can't find file : %s", itemsFile.c_str());
}
return 0;
}