本文整理汇总了C++中CVectorSString类的典型用法代码示例。如果您正苦于以下问题:C++ CVectorSString类的具体用法?C++ CVectorSString怎么用?C++ CVectorSString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CVectorSString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CSString
void CWords_dicDlg::lookUp( const CString& inputStr )
{
// Look up
CVectorSString resultVec;
Dico.lookup( CSString(inputStr), resultVec );
// Display results
clear();
if ( resultVec.empty() )
{
m_Results.AddString( "<no result>" );
return;
}
else
{
bool showAll = (((CButton*)(GetDlgItem( IDC_ShowAll )))->GetCheck() == 1);
bool lvlRemoved = false;
m_Results.SetRedraw( false );
for ( CVectorSString::const_iterator ivs=resultVec.begin(); ivs!=resultVec.end(); ++ivs )
{
const CSString& res = (*ivs);
if ( showAll || (res.find( "lvl" ) == string::npos) )
{
m_Results.AddString( res.c_str() );
}
else
lvlRemoved = true;
}
m_Results.SetRedraw( true );
CString s;
s.Format( "%u results found for \"%s\".%s", resultVec.size(), inputStr, lvlRemoved?" Results containing \"lvl\" not shown":"" );
GetDlgItem( IDC_Status )->SetWindowText( s );
}
}
示例2: 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()] );
}
}
示例3: cbExecCommandResult
static void cbExecCommandResult(CMessage &msgin, const std::string &serviceName, TServiceId sid)
{
// treat the rely message sent back from a service whom we asked to execute a command
NLMISC::InfoLog->displayNL("EXEC_COMMAND_RESULT' Received from: %3d: %s", sid.get() ,serviceName.c_str());
// retrieve the text from the input message
CSString txt;
msgin.serial(txt);
// divide the text into lines because NeL doesn't like long texts
CVectorSString lines;
txt.splitLines(lines);
// display the lines of text
for (uint32 i=0;i<lines.size();++i)
{
NLMISC::InfoLog->displayNL("%s",lines[i].c_str());
}
}
示例4: makeResult
/*
* 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 ) );
}
}
}
示例5: runForFile
bool CCharacterScanJob::runForFile(const std::string& fileName)
{
// load the file into a pdr record
static CPersistentDataRecord pdr;
pdr.clear();
pdr.readFromFile(fileName.c_str());
// create a character representation and apply the pdr
CStatsScanCharacter c;
c.apply(pdr);
// iterate over the filters executing their core code
for (uint32 i=(uint32)_Filters.size();i--;)
{
if (!_Filters[i]->evaluate(&c))
return true;
}
// we've been accepted by the filters so add this file to the file list (if there is one)
if (_FileList!=NULL)
{
_FileList->addFile(fileName);
}
// iterate over the info extractors executing their core code
for (uint32 i=0;i<_InfoExtractors.size();++i)
{
_InfoExtractors[i]->execute(this,&c);
}
// flush the info collected by the info extractors to the output file
CVectorSString words;
CSString(fileName).splitFrom("account_").splitTo("_pdr.").splitBySeparator('_',words,false,true,true,true);
if (words.size()==2)
{
charTblFlushRow(words[0].atoi(),words[1].atoi());
}
return true;
}
示例6: updateItems
// update all items with new values
int updateItems(const char *filename)
{
// verify file
verifItemsFile(filename);
CSString data;
data.readFromFile(filename);
CVectorSString lines;
data.splitLines(lines);
for (uint itemIndex=0 ; itemIndex<items.size() ; itemIndex++)
{
nlassert(fields.size() >= items[itemIndex].size());
cout << "Updating item " << itemIndex << endl;
uint a, b;
getItemBounds(lines, itemIndex, a, b);
// no bound found, it's a new item
if (b == 0)
{
addNewItem(lines, itemIndex);
getItemBounds(lines, itemIndex, a, b);
}
for (uint fieldIndex=0 ; fieldIndex<items[itemIndex].size() ; fieldIndex++)
updateItemField(lines, itemIndex, fieldIndex, a, b);
}
// rewrite file
data.clear();
for (uint i=0 ; i<lines.size() ; i++)
data += lines[i] + "\n";
data.writeToFile(filename);
return 0;
}
示例7: getItemBounds
// compute item boundary in the file (min and max lines)
void getItemBounds(const CVectorSString &lines, uint num, uint &a, uint &b)
{
a = b = 0;
uint i = -1;
bool ok = false;
while (++i < lines.size() && !ok)
{
if (lines[i].empty() || lines[i].find("//") != string::npos)
continue;
// get item number
uint n;
if (sscanf(lines[i].c_str(), "_Items#%d", &n) == 0)
continue;
// find it
if (n == num)
{
// frist line
if (a == 0)
a = b = i+1;
// more line
else
b++;
}
else
{
// end
if (a != 0)
ok = true;
}
}
// found it ?
if (a != 0)
{
ok = true;
b++;
}
}
示例8: addNewItem
// add a new item a the end of the file
void addNewItem(CVectorSString &lines, uint itemIndex)
{
CVectorSString::iterator it = lines.end();
string s = "_Items#" + toString(itemIndex);
lines.insert(lines.end(), s);
lines.insert(lines.end(), s + "._SheetId=undef");
lines.insert(lines.end(), s + "._ClientInventoryPosition= -1");
lines.insert(lines.end(), s + "._Recommended= 250");
lines.insert(lines.end(), s + "._LocSlot= " + toString(itemIndex));
lines.insert(lines.end(), s + "._PhraseId=undef");
lines.insert(lines.end(), s + "._CraftParameters");
lines.insert(lines.end(), "\n");
}
示例9: updateItemField
// update an item field with a new value
void updateItemField(CVectorSString &lines, uint itemIndex, uint fieldIndex, uint &a, uint &b)
{
string field = fields[fieldIndex];
string val = items[itemIndex][fieldIndex];
string s = "_Items#";
s += toString(itemIndex);
s += ".";
s += field;
// remove jump
val = CSString(val).strtok("\n");
uint craftLine = 0;
bool found = false;
uint i = a-1;
// first pass to check if param have changed
for (i=a ; i<b ; i++)
{
string line = s + "= " + val;
string::size_type pos = lines[i].find(line.c_str());
if (pos != string::npos)
{
found = true;
break;
}
}
// second pass if new value
i = a-1;
while (++i<b && !found)
{
string::size_type pos;
// store the line "_CraftParameters" : reference line
if (craftLine == 0)
{
pos = lines[i].find("_CraftParameters");
if (pos != string::npos)
craftLine = i;
}
// search string
pos = lines[i].find(s.c_str());
if (pos == string::npos)
continue;
if (val != "")
{
// check if the attribute is the right one and not included in another one
// for example: Protection is in ProtectionFactor
if (!CSString::isValidFileNameChar(lines[i][s.size()]))
{
found = true;
if (val != "nul")
{
// udpdate value
lines[i] = s;
lines[i] += "= ";
lines[i] += val;
}
else
{
// remove value
CVectorSString::iterator it = lines.begin() + i;
lines.erase(it);
i--;
b--;
}
}
}
}
// param not found
if (!found && !val.empty() && val != "nul")
{
// add it
if (field.find("_CraftParameters") == string::npos)
{
// before craftLine
CVectorSString::iterator it = lines.begin() + craftLine;
lines.insert(it, s + "= " + val);
}
else
{
// after craftLine
CVectorSString::iterator it = lines.begin() + craftLine + 1;
lines.insert(it, s + "= " + val);
}
}
}
示例10: executeScriptBuf
//void executeScriptBuf(char *txt)
void executeScriptBuf(const string &text)
{
CSString buf = text;
CVectorSString lines;
vector<string> tmpLines;
NLMISC::explode(std::string(buf.c_str()), std::string("\n"), tmpLines, true);
lines.resize(tmpLines.size());
for (uint i=0; i<tmpLines.size();i++)
{
lines[i]= tmpLines[i];
}
for (uint i=0; i<lines.size(); ++i)
{
CSString line = lines[i];
line = line.strip();
if (line.empty() || line.find("//") == 0)
{
// comment or empty line, skip
continue;
}
CSString command = line.strtok(" \t");
line = line.strip();
if (command == "DFNPATH")
{
//CPath::getPathContent(args,true,false,true,files);
CPath::addSearchPath(line, true, false); // for the dfn files
}
else if (command == "PATH")
{
files.clear();
CPath::getPathContent(line, true,false,true,files);
CPath::addSearchPath(line, true, false); // for the dfn files
}
else if (command == "OUTPUT")
{
setOutputFile(line);
}
else if (command == "FIELD")
{
addField(line);
}
else if (command == "SOURCE")
{
addSource(line);
}
else if (command == "SCANFILES")
{
scanFiles(line);
}
else if (command == "SCRIPT")
{
executeScriptFile(line);
}
else
{
fprintf(stderr,"Unknown command: '%s' '%s'\n", command.c_str(), line.c_str());
}
}
}
示例11: exportCsv
// generate .csv file based on actual filled structure
int exportCsv(const char *filename)
{
nlassert(fields.size() != 0);
uint i, j;
FILE *f = fopen(filename, "w");
if (f == NULL)
nlerror("Can't open file : %s", filename);
// print fields name
for (i=0 ; i<fields.size()-1 ; i++)
fprintf(f, "%s;", fields[i].c_str());
fprintf(f, "%s\n", fields[fields.size()-1].c_str());
// print values for each item
for (i=0 ; i<items.size() ; i++)
{
for (j=0 ; j<items[i].size()-1 ; j++)
fprintf(f, "%s;", items[i][j].c_str());
fprintf(f, "%s\n", items[i][items[i].size()-1].c_str());
}
fclose(f);
return 0;
}
示例12: 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;
}
示例13: 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;
}
示例14: processItemLine
// parse a line from source file
void processItemLine(const string &s)
{
// null or comment
if (s.empty() || s.find("//") == 0)
return;
// other stuff
if (s.find("_Items#") == string::npos)
return;
// get item number
int n;
sscanf(s.c_str(), "_Items#%d", &n);
// check fields
for (uint i=0 ; i<fields.size() ; i++)
{
string field = "_Items#" + toString(n) + "." + fields[i];
// compare line with field
if (s.find(fields[i]) != string::npos)
{
// check is next char is not valid because of names like Protection in Protection1
if (!CSString::isValidFileNameChar(s[field.size()]))
{
// get value
string::size_type pos = s.find("=");
nlassert(pos != string::npos);
string val(s, pos+1);
items[n][i] = (CSString(val).strtok("\n")).strip();
break;
}
}
}
}
示例15: 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;
}