本文整理汇总了C++中re函数的典型用法代码示例。如果您正苦于以下问题:C++ re函数的具体用法?C++ re怎么用?C++ re使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了re函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: regexpPreFilter
/** Construct a filter expression from a regular expression
* Returns SQLITE_ERROR and sets user relevant error message on error */
int regexpPreFilter(expr **ppExpr, bool *pAll, trilite_vtab *pTrgVtab, const unsigned char *expr, int nExpr){
int rc = SQLITE_OK;
*ppExpr = NULL;
/* Options for regular expressions */
re2::RE2::Options options;
options.set_log_errors(false);
options.set_max_mem(pTrgVtab->maxRegExpMemory);
/* Create regular expression from string */
re2::RE2 re(re2::StringPiece((const char*)expr, nExpr), options);
/* TODO if re.ProgramSize() > SOME_THRESHOLD return and error message */
/* Ideally this threshold should be a runtime setting */
/* Provide error message if regular expression compilation failed */
if(!re.ok()){
/* Error codes from re2 */
std::string msg;
switch(re.error_code()){
case re2::RE2::ErrorBadEscape:
msg = "Bad escape sequence at '%s'";
break;
case re2::RE2::ErrorBadCharClass:
msg = "Bad character class at '%s'";
break;
case re2::RE2::ErrorBadCharRange:
msg = "Bad character range at '%s'";
break;
case re2::RE2::ErrorMissingBracket:
msg = "Missing bracket in '%s'";
break;
case re2::RE2::ErrorMissingParen:
msg = "Missing paranthesis in '%s'";
break;
case re2::RE2::ErrorTrailingBackslash:
msg = "Trailing backslash in '%s'";
break;
case re2::RE2::ErrorRepeatArgument:
msg = "Repeat argument missing in '%s'";
break;
case re2::RE2::ErrorRepeatSize:
msg = "Bad repeat argument at '%s'";
break;
case re2::RE2::ErrorRepeatOp:
msg = "Bad repeatition operator at '%s'";
break;
case re2::RE2::ErrorBadPerlOp:
msg = "Bad perl operator at '%s'";
break;
case re2::RE2::ErrorBadUTF8:
msg = "Invalid UTF-8 at '%s'";
break;
case re2::RE2::ErrorBadNamedCapture:
msg = "Bad named capture group at '%s'";
break;
case re2::RE2::ErrorPatternTooLarge:
msg = "Pattern '%s' is too large";
break;
case re2::RE2::ErrorInternal:
default:
msg = "Unknown internal error at '%s'";
break;
}
/* Now set the error message */
triliteError(pTrgVtab, ("REGEXP: " + msg).c_str(), re.error_arg().c_str());
/* Return error */
return SQLITE_ERROR;
}
/* Compute a prefilter */
re2::Prefilter* pf = re2::Prefilter::FromRE2(&re);
/* Provide error message if a filter couldn't be devised, as we shall not */
/* permit full table scans. */
if(!pf){
triliteError(pTrgVtab, "REGEXP: Failed to build a filter for the regular expression");
return SQLITE_ERROR;
}
rc = exprFromPreFilter(ppExpr, pAll, pTrgVtab, pf);
assert(rc == SQLITE_OK);
/* Release the prefilter */
delete pf;
return rc;
}
开发者ID:abbeyj,项目名称:trilite,代码行数:92,代码来源:regexp.cpp
示例2: re
void Strings::regexReplace(string& target, string& from, string& to) {
boost::regex re(from);
target = boost::regex_replace(target, re, to,
boost::match_default | boost::format_all);
}
开发者ID:getcontext,项目名称:zf2ns,代码行数:5,代码来源:Strings.cpp
示例3: findFastqPathPairs
flowcell::Layout FastqFlowcell::createFilteredFlowcell(
const std::string &tilesFilter,
const boost::filesystem::path &baseCallsDirectory,
const bool compressed,
const unsigned laneNumberMax,
const unsigned readNameLength,
std::string useBasesMask,
const bool allowVariableFastqLength,
const char fastqQ0,
const std::string &seedDescriptor,
const unsigned seedLength,
const reference::ReferenceMetadataList &referenceMetadataList,
unsigned &firstPassSeeds)
{
FastqPathPairList flowcellFilePaths = findFastqPathPairs(compressed, laneNumberMax, baseCallsDirectory);
if (flowcellFilePaths.empty())
{
const boost::format message = boost::format("\n *** Could not find any fastq lanes in: %s ***\n") %
baseCallsDirectory;
BOOST_THROW_EXCEPTION(common::InvalidOptionException(message.str()));
}
FastqFlowcellInfo flowcellInfo = parseFastqFlowcellInfo(flowcellFilePaths, allowVariableFastqLength, fastqQ0, readNameLength);
std::vector<unsigned int> readLengths;
if (flowcellInfo.readLengths_.first)
{
readLengths.push_back(flowcellInfo.readLengths_.first);
}
if (flowcellInfo.readLengths_.second)
{
readLengths.push_back(flowcellInfo.readLengths_.second);
}
if ("default" == useBasesMask)
{
if (readLengths.size() == 1)
{
useBasesMask = "y*n";
}
else if (readLengths.size() == 2)
{
useBasesMask = "y*n,y*n";
}
else
{
const boost::format message =
boost::format("\n *** Could not guess the use-bases-mask for '%s', please supply the explicit value ***\n") %
baseCallsDirectory.string();
BOOST_THROW_EXCEPTION(common::InvalidOptionException(message.str()));
}
}
std::vector<unsigned int> readFirstCycles;
ParsedUseBasesMask parsedUseBasesMask;
alignment::SeedMetadataList seedMetadataList;
if (!readLengths.empty())
{
parsedUseBasesMask = parseUseBasesMask(readFirstCycles, readLengths, seedLength, useBasesMask, baseCallsDirectory);
seedMetadataList = parseSeedDescriptor(parsedUseBasesMask.dataReads_, seedDescriptor, seedLength, firstPassSeeds);
}
flowcell::Layout fc(baseCallsDirectory,
flowcell::Layout::Fastq,
flowcell::FastqFlowcellData(compressed, fastqQ0),
laneNumberMax,
flowcellInfo.readNameLength_,
std::vector<unsigned>(),
parsedUseBasesMask.dataReads_,
seedMetadataList, flowcellInfo.flowcellId_);
std::string regexString(tilesFilter);
std::replace(regexString.begin(), regexString.end(), ',', '|');
boost::regex re(regexString);
BOOST_FOREACH(const unsigned int lane, flowcellInfo.getLanes())
{
std::string laneString((boost::format("s_%d") % lane).str());
if (boost::regex_search(laneString, re))
{
fc.addTile(lane, 1);
}
}
return fc;
}
开发者ID:Illumina,项目名称:isaac2,代码行数:87,代码来源:FastqFlowcell.cpp
示例4: nonre
int nonre(long int s){
if(re(s)==s)
return 1;
else return 0;
}
开发者ID:evely211,项目名称:Norman,代码行数:5,代码来源:palindnum.c
示例5: re
QByteArray SecureRNG::random(int size)
{
QByteArray re(size, 0);
random(re.data(), size);
return re;
}
开发者ID:Alex237,项目名称:ricochet,代码行数:6,代码来源:SecureRNG.cpp
示例6: TEST
TEST( Exception, two_param )
{
RainbrurpgException re("aze", "poi");
cout << re.what();
EXPECT_STREQ( re.what(), "azepoi");
}
开发者ID:rainbru,项目名称:rainbrurpg,代码行数:6,代码来源:Exception_Test.cpp
示例7: while
void PipedProcessCtrl::OnDClick(wxMouseEvent &e)
{
//First retrieve the link text
if(!m_linkclicks)
return;
long pos=m_textctrl->PositionFromPoint(e.GetPosition());
int style=m_textctrl->GetStyleAt(pos);
if((style&PP_LINK_STYLE)!=PP_LINK_STYLE)
return; //didn't click a link
long start=pos;
while(start>0)
{
style=m_textctrl->GetStyleAt(start-1);
if((style&PP_LINK_STYLE)!=PP_LINK_STYLE)
break;
start--;
}
long end=pos;
while(end<m_textctrl->PositionFromLine(m_textctrl->GetLineCount()-1))
{
style=m_textctrl->GetStyleAt(end+1);
if((style&PP_LINK_STYLE)!=PP_LINK_STYLE)
break;
end++;
}
wxString text=m_textctrl->GetTextRange(start,end+1);
//retrieve the file and line number parts of the link
wxRegEx re(m_linkregex,wxRE_ADVANCED|wxRE_NEWLINE);
wxString file;
long line;
if(!re.Matches(text))
return;
size_t ind,len;
re.GetMatch(&ind,&len,0);
if(re.GetMatch(&ind,&len,1))
file=text.Mid(ind,len);
else
file=wxEmptyString;
if(re.GetMatch(&ind,&len,3))
text.Mid(ind,len).ToLong(&line);
else
line=0;
//open the file in the editor
wxFileName f(file);
if(f.FileExists())
{
cbEditor* ed = Manager::Get()->GetEditorManager()->Open(f.GetFullPath());
if (ed)
{
ed->Show(true);
// if (!ed->GetProjectFile())
// ed->SetProjectFile(f.GetFullPath());
ed->GotoLine(line - 1, false);
if(line>0)
if(!ed->HasBookmark(line - 1))
ed->ToggleBookmark(line -1);
}
}
}
开发者ID:stahta01,项目名称:EmBlocks,代码行数:62,代码来源:PipedProcessCtrl.cpp
示例8: loadHist
//void loadHist(const char* filename, const char* pfx, const char* pat, Bool_t doAdd, Double_t scaleFactor)
void loadHist(const char* filename="in.root", const char* pfx=0, const char* pat="*", Bool_t doAdd=kFALSE, Double_t scaleFactor=-1.0)
{
cout << " Reading histograms from file: " << filename << endl ;
TFile inf(filename) ;
//inf.ReadAll() ;
TList* list = inf.GetListOfKeys() ;
TIterator* iter = list->MakeIterator();
TRegexp re(pat,kTRUE) ;
std::cout << "pat = " << pat << std::endl ;
gDirectory->cd("Rint:") ;
TObject* obj ;
TKey* key ;
std::cout << "doAdd = " << (doAdd?"T":"F") << std::endl ;
std::cout << "loadHist: reading." ;
while((key=(TKey*)iter->Next())) {
Int_t ridx = TString(key->GetName()).Index(re) ;
if (ridx==-1) {
continue ;
}
obj = inf.Get(key->GetName()) ;
TObject* clone ;
if (pfx) {
// Find existing TH1-derived objects
TObject* oldObj = 0 ;
if (doAdd){
oldObj = gDirectory->Get(Form("%s_%s",pfx,obj->GetName())) ;
if (oldObj && !oldObj->IsA()->InheritsFrom(TH1::Class())) {
oldObj = 0 ;
}
}
if (oldObj) {
clone = oldObj ;
//// ((TH1*)clone)->Add((TH1*)obj) ;
if ( scaleFactor > 0 ) {
((TH1*)clone)->Sumw2() ;
((TH1*)clone)->Add((TH1*)obj, scaleFactor) ;
} else {
((TH1*)clone)->Add((TH1*)obj) ;
}
} else {
clone = obj->Clone(Form("%s_%s",pfx,obj->GetName())) ;
}
} else {
// Find existing TH1-derived objects
TObject* oldObj = 0 ;
if (doAdd){
oldObj = gDirectory->Get(key->GetName()) ;
if (oldObj && !oldObj->IsA()->InheritsFrom(TH1::Class())) {
oldObj = 0 ;
}
}
if (oldObj) {
clone = oldObj ;
///// ((TH1*)clone)->Add((TH1*)obj) ;
if ( scaleFactor > 0 ) {
((TH1*)clone)->Sumw2() ;
((TH1*)clone)->Add((TH1*)obj, scaleFactor) ;
} else {
((TH1*)clone)->Add((TH1*)obj) ;
}
} else {
clone = obj->Clone() ;
}
}
if ( scaleFactor > 0 && !doAdd ) {
((TH1*) clone)->Sumw2() ;
((TH1*) clone)->Scale(scaleFactor) ;
}
if (!gDirectory->GetList()->FindObject(clone)) {
gDirectory->Append(clone) ;
}
std::cout << "." ;
std::cout.flush() ;
}
std::cout << std::endl;
inf.Close() ;
delete iter ;
}
开发者ID:SusyRa2b,项目名称:Statistics,代码行数:89,代码来源:histio.c
示例9: f
/**
* Read the Makefile.am and return a map of all the variables.
* Will take notice of backslash and += constructs.
* @param fileName
* @param variables
*/
void AutoProjectTool::parseMakefileam(const QString &fileName, QMap<QString, QString> *variables)
{
QFile f(fileName);
if (!f.open(IO_ReadOnly))
{
return ;
}
QTextStream stream(&f);
QRegExp re("^(#kdevelop:[ \t]*)?([A-Za-z][@A-Za-z0-9_]*)[ \t]*([:\\+]?=)[ \t]*(.*)$");
QString last;
bool multiLine = false;
while (!stream.atEnd())
{
QString s = stream.readLine().stripWhiteSpace();
if (re.exactMatch(s))
{
QString lhs = re.cap(2);
QString rhs = re.cap(4);
if (rhs[ rhs.length() - 1 ] == '\\')
{
multiLine = true;
last = lhs;
rhs[rhs.length() - 1] = ' ';
}
// The need for stripWhiteSpace seems to be a Qt bug.
// make our list nice and neat.
QStringList bits = QStringList::split(" ", rhs);
rhs = bits.join(" ");
if (re.cap(3) == "+=")
{
((*variables)[lhs] += ' ') += rhs;
}
else
{
variables->insert(lhs, rhs);
}
}
else if (multiLine)
{
if (s[s.length()-1] == '\\')
{
s[s.length()-1] = ' ';
}
else
{
multiLine = false;
}
QStringList bits = QStringList::split(" ", s);
((*variables)[last] += ' ') += bits.join(" ");
}
}
f.close();
QMap<QString, QString> list;
for (QMap<QString, QString>::iterator iter = variables->begin();iter != variables->end();iter++)
{
QStringList items = QStringList::split(" ", iter.data());
QMap<QString, QString> unique;
for (uint i = 0;i < items.size();i++)
{
unique.insert(items[i], "");
}
QString line;
for (QMap<QString, QString>::iterator it = unique.begin();it != unique.end();it++)
{
line += it.key() + ' ';
}
if (line.length() > 1)
{
line.setLength(line.length() - 1);
}
list.insert(iter.key(), line);
}
*variables = list;
}
开发者ID:serghei,项目名称:kde3-kdevelop,代码行数:86,代码来源:misc.cpp
示例10: moveToRoot
AbstractCommand::ReturnCodes Record::record()
{
if (! checkInRepository())
return NotInRepo;
moveToRoot(CheckFileSystem);
if (m_mode != Unset)
m_all = m_mode == AllChanges;
const bool needHunks = !m_all || m_patchName.isEmpty();
ChangeSet changeSet;
changeSet.fillFromCurrentChanges(rebasedArguments(), needHunks);
changeSet.waitForFinishFirstFile();
bool shouldDoRecord = changeSet.count() > 0;
if (!shouldDoRecord) {
Logger::warn() << "No changes!" << endl;
return Ok;
}
QString email = m_author;
if (email.isEmpty())
email = getenv("EMAIL");
QStringList environment;
if (! email.isEmpty()) {
QRegExp re("(.*) <([@\\S]+)>");
if (re.exactMatch(email)) { // meaning its an email AND name
environment << "GIT_AUTHOR_NAME="+ re.cap(1);
environment << "GIT_COMMITTER_NAME="+ re.cap(1);
environment << "GIT_AUTHOR_EMAIL="+ re.cap(2);
environment << "GIT_COMMITTER_EMAIL="+ re.cap(2);
}
else if (m_author.isEmpty()) { // if its an account or shell wide option; just use the git defs.
environment << "GIT_AUTHOR_EMAIL="+ email;
environment << "GIT_COMMITTER_EMAIL="+ email;
}
else {
Logger::error() << "Author format invalid. Please provide author formatted like; `name <[email protected]>\n";
return InvalidOptions;
}
}
if (shouldDoRecord && !m_all && m_mode != Index) { // then do interview
HunksCursor cursor(changeSet);
cursor.setConfiguration(m_config);
Interview interview(cursor, name());
interview.setUsePager(shouldUsePager());
if (! interview.start()) {
Logger::warn() << "Cancelled." << endl;
return UserCancelled;
}
}
if (shouldDoRecord && !m_all && m_mode != Index) { // check if there is anything selected
shouldDoRecord = changeSet.hasAcceptedChanges();
if (! shouldDoRecord) {
Logger::warn() << "Ok, if you don't want to record anything, that's fine!" <<endl;
return UserCancelled;
}
}
if (dryRun())
return Ok;
if ((m_editComment || m_patchName.isEmpty()) && getenv("EDITOR")) {
class Deleter : public QObject {
public:
Deleter() : commitMessage(0) { }
~Deleter() {
if (commitMessage)
commitMessage->remove();
}
QFile *commitMessage;
};
Deleter parent;
QFile *commitMessage;
int i = 0;
do {
commitMessage = new QFile(QString("vng-record-%1").arg(i++), &parent);
} while (commitMessage->exists());
parent.commitMessage = commitMessage; // make sure the file is removed from FS.
if (! commitMessage->open(QIODevice::WriteOnly)) {
Logger::error() << "Vng failed. Could not create a temporary file for the record message '"
<< commitMessage->fileName() << "`\n";
return WriteError;
}
const char * defaultCommitMessage1 = "\n***END OF DESCRIPTION***"; // we will look for this string later
const char * defaultCommitMessage2 = "\nPlace the long patch description above the ***END OF DESCRIPTION*** marker.\n\nThis patch contains the following changes:\n\n";
if (! m_patchName.isEmpty())
commitMessage->write(m_patchName);
else
commitMessage->write("\n", 1);
commitMessage->write(defaultCommitMessage1, strlen(defaultCommitMessage1));
commitMessage->write(defaultCommitMessage2, strlen(defaultCommitMessage2));
QBuffer buffer;
changeSet.writeDiff(buffer, m_all ? ChangeSet::AllHunks : ChangeSet::UserSelection);
ChangeSet actualChanges;
actualChanges.fillFromDiffFile(buffer);
QTextStream out (commitMessage);
for (int i=0; i < actualChanges.count(); ++i) {
File file = actualChanges.file(i);
//.........这里部分代码省略.........
开发者ID:ruphy,项目名称:plasma-studio,代码行数:101,代码来源:Record.cpp
示例11: re
void OutputPane::OnBuildWindowDClick(const wxString &line, int lineno)
{
wxString fileName, strLineNumber;
bool match = false;
//get the selected compiler for the current line that was DClicked
if(lineno >= (int)m_buildLineInfo.GetCount()){
return;
}
//find the project selected build configuration for the workspace selected
//configuration
wxString projectName = m_buildLineInfo.Item(lineno);
if(projectName.IsEmpty())
return;
BuildMatrixPtr matrix = ManagerST::Get()->GetWorkspaceBuildMatrix();
wxString projecBuildConf = matrix->GetProjectSelectedConf(matrix->GetSelectedConfigurationName(),
projectName );
ProjectSettingsPtr settings = ManagerST::Get()->GetProject(projectName)->GetSettings();
if(!settings)
{
return;
}
BuildConfigPtr bldConf = settings->GetBuildConfiguration(projecBuildConf);
if( !bldConf )
{
return;
}
wxString cmpType = bldConf->GetCompilerType();
CompilerPtr cmp = BuildSettingsConfigST::Get()->GetCompiler(cmpType);
if( !cmp )
{
return;
}
long idx;
//try to match an error pattern to the line
RegexProcessor re(cmp->GetErrPattern());
cmp->GetErrFileNameIndex().ToLong(&idx);
if(re.GetGroup(line, idx, fileName))
{
//we found the file name, get the line number
cmp->GetErrLineNumberIndex().ToLong(&idx);
re.GetGroup(line, idx, strLineNumber);
match = true;
}
//try to match warning pattern
if(!match)
{
RegexProcessor re(cmp->GetWarnPattern());
cmp->GetWarnFileNameIndex().ToLong(&idx);
if(re.GetGroup(line, idx, fileName))
{
//we found the file name, get the line number
cmp->GetWarnLineNumberIndex().ToLong(&idx);
re.GetGroup(line, idx, strLineNumber);
match = true;
}
}
if(match)
{
long lineNumber = -1;
strLineNumber.ToLong(&lineNumber);
// open the file in the editor
// get the project name that is currently being built
wxString projName(wxEmptyString);
if(lineno < (int)m_buildLineInfo.GetCount())
{
projName = m_buildLineInfo.Item(lineno);
}
// if no project found, dont do anything
if(projName.IsEmpty())
{
return;
}
DirSaver ds;
ProjectPtr pro = ManagerST::Get()->GetProject(projName);
::wxSetWorkingDirectory(pro->GetFileName().GetPath());
wxFileName fn(fileName);
fn.MakeAbsolute(pro->GetFileName().GetPath());
ManagerST::Get()->OpenFile(fn.GetFullPath(), projName, lineNumber - 1 );
}
}
开发者ID:BackupTheBerlios,项目名称:codelite-svn,代码行数:93,代码来源:output_pane.cpp
示例12: TEST
TEST(GeoLib, SurfaceIsPointInSurface)
{
std::vector<std::function<double(double, double)>> surface_functions;
surface_functions.push_back(constant);
surface_functions.push_back(coscos);
for (auto f : surface_functions) {
std::random_device rd;
std::string name("Surface");
// generate ll and ur in random way
std::mt19937 random_engine_mt19937(rd());
std::normal_distribution<> normal_dist_ll(-10, 2);
std::normal_distribution<> normal_dist_ur(10, 2);
MathLib::Point3d ll(std::array<double,3>({{
normal_dist_ll(random_engine_mt19937),
normal_dist_ll(random_engine_mt19937),
0.0
}
}));
MathLib::Point3d ur(std::array<double,3>({{
normal_dist_ur(random_engine_mt19937),
normal_dist_ur(random_engine_mt19937),
0.0
}
}));
for (std::size_t k(0); k<3; ++k)
if (ll[k] > ur[k])
std::swap(ll[k], ur[k]);
// random discretization of the domain
std::default_random_engine re(rd());
std::uniform_int_distribution<std::size_t> uniform_dist(2, 25);
std::array<std::size_t,2> n_steps = {{uniform_dist(re),uniform_dist(re)}};
std::unique_ptr<MeshLib::Mesh> sfc_mesh(
MeshLib::MeshGenerator::createSurfaceMesh(
name, ll, ur, n_steps, f
)
);
// random rotation angles
std::normal_distribution<> normal_dist_angles(
0, boost::math::double_constants::two_pi);
std::array<double,3> euler_angles = {{
normal_dist_angles(random_engine_mt19937),
normal_dist_angles(random_engine_mt19937),
normal_dist_angles(random_engine_mt19937)
}
};
MathLib::DenseMatrix<double, std::size_t> rot_mat(getRotMat(
euler_angles[0], euler_angles[1], euler_angles[2]));
std::vector<MeshLib::Node*> const& nodes(sfc_mesh->getNodes());
GeoLib::rotatePoints<MeshLib::Node>(rot_mat, nodes);
MathLib::Vector3 const normal(0,0,1.0);
MathLib::Vector3 const surface_normal(rot_mat * normal);
double const eps(1e-6);
MathLib::Vector3 const displacement(eps * surface_normal);
GeoLib::GEOObjects geometries;
MeshLib::convertMeshToGeo(*sfc_mesh, geometries);
std::vector<GeoLib::Surface*> const& sfcs(*geometries.getSurfaceVec(name));
GeoLib::Surface const*const sfc(sfcs.front());
std::vector<GeoLib::Point*> const& pnts(*geometries.getPointVec(name));
// test triangle edge point of the surface triangles
for (auto const p : pnts) {
EXPECT_TRUE(sfc->isPntInSfc(*p));
MathLib::Point3d q(*p);
for (std::size_t k(0); k<3; ++k)
q[k] += displacement[k];
EXPECT_FALSE(sfc->isPntInSfc(q));
}
// test edge middle points of the triangles
for (std::size_t k(0); k<sfc->getNTriangles(); ++k) {
MathLib::Point3d p, q, r;
std::tie(p,q,r) = getEdgeMiddlePoints(*(*sfc)[k]);
EXPECT_TRUE(sfc->isPntInSfc(p));
EXPECT_TRUE(sfc->isPntInSfc(q));
EXPECT_TRUE(sfc->isPntInSfc(r));
}
}
}
开发者ID:rschroers,项目名称:ogs,代码行数:86,代码来源:TestSurfaceIsPointInSurface.cpp
示例13: isURI
/*!
* see http://people.w3.org/~dom/archives/2005/09/integrating-a-new-uris-scheme-handler-to-gnome-and-firefox/
* to learn how to handle "tel:0123456" uri scheme
*
* tel:number is in RFC 3966
* callto:number is unofficial (read 7.3. in RFC 3966)
* callto://number is unofficial and used by Skype
* we support tel:number and callto:number
* \return true if the parameter matches RFC 3966
*/
bool BASELIB_EXPORT isURI(const QString &string)
{
QRegExp re("^(tel|callto):", Qt::CaseInsensitive);
return (! (re.indexIn(string) < 0));
}
开发者ID:pcadottemichaud,项目名称:xivo-client-qt,代码行数:15,代码来源:phonenumber.cpp
示例14: MetaSQLBlock
bool MetaSQLQueryPrivate::parse_query(const QString & query) {
_top = new MetaSQLBlock(this, "generic", QString::null);
QList<MetaSQLBlock*> _blocks;
_blocks.append(_top);
MetaSQLBlock * _current = _top;
QRegExp re("<\\?(.*)\\?>");
QRegExp nw("[^\\w]"); // will find the first non word character
re.setMinimal(TRUE);
QString s;
int lastPos = 0;
int currPos = 0;
while(currPos >= 0) {
currPos = re.search(query, currPos);
if(lastPos != currPos) {
_current->append(new MetaSQLString(this, query.mid(lastPos, (currPos==-1?query.length():currPos)-lastPos)));
}
if(currPos >= 0) {
s = re.cap(1);
s = s.stripWhiteSpace();
int i = nw.search(s);
QString cmd, options;
if(i == -1) {
cmd = s;
options = QString::null;
} else {
cmd = s.left(i);
options = s.mid(i);
}
cmd = cmd.lower();
if(cmd == "endif" || cmd == "endforeach") {
MetaSQLBlock::Block _block = _current->type();
if( (cmd == "endif" && ( _block == MetaSQLBlock::BlockIf
|| _block == MetaSQLBlock::BlockElseIf
|| _block == MetaSQLBlock::BlockElse) )
|| (cmd == "endforeach" && ( _block == MetaSQLBlock::BlockForEach ) ) ) {
_blocks.removeLast();
_current = _blocks.last();
} else {
// uh oh! We encountered an end block tag when we were either not in a
// block or were in a block of a different type.
*_logger << "Encountered an unexpected " << cmd << "." << endl;
_valid = false;
return false;
}
} else if(cmd == "if" || cmd == "foreach") {
// we have a control statement here and need to create a new block
MetaSQLBlock * b = new MetaSQLBlock(this, cmd, options);
if(b->isValid()) {
_current->append(b);
_blocks.append(b);
_current = b;
} else {
*_logger << "Failed to create new " << cmd << " block." << endl;
delete b;
_valid = false;
return false;
}
} else if(cmd == "elseif" || cmd == "else") {
// we need to switch up are if block to include this new alternate
if(_current->type() == MetaSQLBlock::BlockElse) {
*_logger << "Encountered unexpected " << cmd << " statement within else block." << endl;
_valid = false;
return false;
} else if(_current->type() != MetaSQLBlock::BlockIf && _current->type() != MetaSQLBlock::BlockElseIf) {
*_logger << "Encountered unexpected " << cmd << " statement outside of if/elseif block." << endl;
_valid = false;
return false;
} else {
MetaSQLBlock * b = new MetaSQLBlock(this, cmd, options);
if(b->isValid()) {
_current->setAlternate(b);
_blocks.removeLast();
_blocks.append(b);
_current = b;
} else {
*_logger << "Failed to create new " << cmd << " block." << endl;
delete b;
_valid = false;
return false;
}
}
} else {
// we must have a function... if not then i don't know what it could be.
// first we must parse the options into a list of parameters for the function
options = options.stripWhiteSpace();
QStringList plist;
if(!options.isEmpty()) {
// first if we have a '(' then we will only parse out the information between it
// and the following ')'
QChar qc = options[0];
bool enclosed = false;
bool working = !enclosed;
bool in_string = false;
QChar string_starter = '"';
QString wip = QString::null;
if(qc == '(') enclosed = true;
//.........这里部分代码省略.........
开发者ID:Wushaowei001,项目名称:xtuple,代码行数:101,代码来源:metasql.cpp
示例15: send
virtual void send( gloox::IQ& iq, gloox::IqHandler* ih, int context )
{
m_context = context;
gloox::Tag* tag = iq.tag();
if( !tag->hasAttribute( "id" ) )
tag->addAttribute( "id", "id" );
switch( m_test )
{
case 1:
if( tag && tag->hasAttribute( "id", "id" ) && tag->hasAttribute( "to", g_server )
&& tag->hasAttribute( "type", "get" ) && tag->hasChild( "query", "xmlns",
gloox::XMLNS_REGISTER ) )
m_result = true;
m_test = 0;
break;
case 4:
{
gloox::Tag *t = 0;
if( tag && tag->hasAttribute( "id", "id" ) && tag->hasAttribute( "to", g_server )
&& tag->hasAttribute( "type", "set" )
&& ( t = tag->findChild( "query", "xmlns", gloox::XMLNS_REGISTER ) ) != 0
&& t->hasChildWithCData( "username", "foobar" )
&& t->hasChildWithCData( "password", "password" )
&& t->hasChildWithCData( "email", "email" ) )
{
gloox::IQ re( gloox::IQ::Result, iq.from(), iq.id() );
ih->handleIqID( re, context );
}
break;
}
case 6:
{
gloox::Tag *t = 0;
if( tag && tag->hasAttribute( "id", "id" ) && tag->hasAttribute( "to", g_server )
&& tag->hasAttribute( "type", "set" )
&& ( ( t = tag->findChild( "query", "xmlns", gloox::XMLNS_REGISTER ) ) != 0 )
&& t->hasChild( "x", "xmlns", gloox::XMLNS_X_DATA ) )
{
gloox::IQ re( gloox::IQ::Result, iq.from(), iq.id() );
ih->handleIqID( re, context );
}
break;
}
case 7:
{
gloox::Tag *t = 0;
if( tag && tag->hasAttribute( "id", "id" ) && tag->hasAttribute( "to", g_server )
&& tag->hasAttribute( "type", "set" )
&& ( ( t = tag->findChild( "query", "xmlns", gloox::XMLNS_REGISTER ) ) != 0 )
&& t->hasChild( "remove" ) )
{
gloox::IQ re( gloox::IQ::Result, iq.from(), iq.id() );
ih->handleIqID( re, context );
}
break;
}
case 8:
{
gloox::Tag *t = 0;
if( tag && tag->hasAttribute( "id", "id" ) && tag->hasAttribute( "to", g_server )
&& tag->hasAttribute( "type", "set" )
&& ( ( t = tag->findChild( "query", "xmlns", gloox::XMLNS_REGISTER ) ) != 0 )
&& t->hasChildWithCData( "username", "foobar" )
&& t->hasChildWithCData( "password", "newpwd" ) )
{
gloox::IQ re( gloox::IQ::Result, iq.from(), iq.id() );
ih->handleIqID( re, context );
}
break;
}
default:
break;
}
delete tag;
}
开发者ID:liuzhuan23,项目名称:testcode-byWinTrust,代码行数:76,代码来源:registration_test.cpp
示例16: fin
/**
* Add entries to a variable. Will just add the variables to the existing line, removing duplicates
* Will preserve += constructs and make sure that the variable only has one copy of the value across
* all += constructs
* @param fileName
* @param variables key=value string of entries to add
* @param add true= add these key,value pairs, false = remove. You can have empty values for an add - the whole line is
* removed. For adding, we will not add an empty line.
*/
void AutoProjectTool::addRemoveMakefileam(const QString &fileName, QMap<QString, QString> variables, bool add)
{
// input file reading
QFile fin(fileName);
if (!fin.open(IO_ReadOnly))
{
return ;
}
QTextStream ins(&fin);
// output file writing.
QFile fout(fileName + "#");
if (!fout.open(IO_WriteOnly))
{
fin.close();
return ;
}
QTextStream outs(&fout);
// variables
QRegExp re("^(#kdevelop:[ \t]*)?([A-Za-z][@A-Za-z0-9_]*)[ \t]*([:\\+]?=)[ \t]*(.*)$");
// build key=map of values to add
// map can be empty.we never add an empty key, but do remove empty keys from the file..
QDict< QMap<QString, bool> > interest;
for (QMap<QString, QString>::Iterator it0 = variables.begin(); it0 != variables.end(); ++it0)
{
kdDebug(9020) << "key (" << add<<"): " << it0.key() << "="<< it0.data() << endl;
QMap<QString, bool>* set = new QMap<QString, bool>();
if (!it0.data().stripWhiteSpace().isEmpty())
{
QStringList variableList = QStringList::split(' ', it0.data());
for (uint i = 0; i < variableList.count(); i++)
{
set->insert(variableList[i], true);
}
}
interest.insert(it0.key(), set);
}
bool multiLine = false;
QString lastLhs;
QStringList lastRhs;
QMap<QString, QString> seenLhs;
while (!fin.atEnd())
{
QString s = ins.readLine();
if (re.exactMatch(s))
{
QString lhs = re.cap(2);
QMap<QString, bool>* ourRhs = interest.find(lhs);
if (!ourRhs)
{
// not interested in this line at all
// write it out as is..
outs << s << endl;
}
else
{
// we are interested in this line..
QString rhs = re.cap(4).stripWhiteSpace();
if (rhs[ rhs.length() - 1 ] == '\\')
{
// save it for when we have the whole line..
multiLine = true;
lastLhs = lhs;
rhs.setLength(rhs.length() - 1);
lastRhs += QStringList::split(" ", rhs);
}
else
{
// deal with it now.
QStringList bits = QStringList::split(" ", rhs);
if (add)
{
// we are adding our interested values to this line and writing it
// add this line to we we want to add to remove duplicates.
for (uint index = 0; index < bits.size(); index++)
{
QMap<QString, bool>::iterator findEntry = ourRhs->find(bits[index]);
if (findEntry == ourRhs->end())
{
// we haven't seen it, so add it, so we don't add it again later..
ourRhs->insert(bits[index], true);
}
// else we have this value in our 'to add list' , it is either already been
//.........这里部分代码省略.........
开发者ID:serghei,项目名称:kde3-kdevelop,代码行数:101,代码来源:misc.cpp
示例17: readSettings
bool KatePrinter::print (KateDocument *doc)
{
QPrinter printer;
readSettings(printer);
// docname is now always there, including the right Untitled name
printer.setDocName(doc->documentName());
KatePrintTextSettings *kpts = new KatePrintTextSettings;
KatePrintHeaderFooter *kphf = new KatePrintHeaderFooter;
KatePrintLayout *kpl = new KatePrintLayout;
QList<QWidget*> tabs;
tabs << kpts;
tabs << kphf;
tabs << kpl;
QWidget *parentWidget=doc->widget();
if ( !parentWidget )
parentWidget=QApplication::activeWindow();
QScopedPointer<QPrintDialog> printDialog(KdePrint::createPrintDialog(&printer, KdePrint::SystemSelectsPages, tabs, parentWidget));
if ( doc->activeView()->selection() ) {
printer.setPrintRange(QPrinter::Selection);
printDialog->setOption(QAbstractPrintDialog::PrintSelection, true);
}
if ( printDialog->exec() )
{
writeSettings(printer);
KateRenderer renderer(doc, doc->activeKateView());
renderer.config()->setSchema (kpl->colorScheme());
renderer.setPrinterFriendly(true);
QPainter paint( &printer );
/*
* We work in tree cycles:
* 1) initialize variables and retrieve print settings
* 2) prepare data according to those settings
* 3) draw to the printer
*/
uint pdmWidth = printer.width();
uint pdmHeight = printer.height();
int y = 0;
uint xstart = 0; // beginning point for painting lines
uint lineCount = 0;
uint maxWidth = pdmWidth;
int headerWidth = pdmWidth;
int startCol = 0;
int endCol = 0;
bool pageStarted = true;
int remainder = 0; // remaining sublines from a wrapped line (for the top of a new page)
// Text Settings Page
bool selectionOnly = (printDialog->printRange() == QAbstractPrintDialog::Selection);
bool useGuide = kpts->printGuide();
bool printLineNumbers = kpts->printLineNumbers();
uint lineNumberWidth( 0 );
// Header/Footer Page
QFont headerFont(kphf->font()); // used for header/footer
bool useHeader = kphf->useHeader();
QColor headerBgColor(kphf->headerBackground());
QColor headerFgColor(kphf->headerForeground());
uint headerHeight( 0 ); // further init only if needed
QStringList headerTagList; // do
bool headerDrawBg = false; // do
bool useFooter = kphf->useFooter();
QColor footerBgColor(kphf->footerBackground());
QColor footerFgColor(kphf->footerForeground());
uint footerHeight( 0 ); // further init only if needed
QStringList footerTagList; // do
bool footerDrawBg = false; // do
// Layout Page
renderer.config()->setSchema( kpl->colorScheme() );
bool useBackground = kpl->useBackground();
bool useBox = kpl->useBox();
int boxWidth(kpl->boxWidth());
QColor boxColor(kpl->boxColor());
int innerMargin = useBox ? kpl->boxMargin() : 6;
// Post initialization
int maxHeight = (useBox ? pdmHeight-innerMargin : pdmHeight);
uint currentPage( 1 );
uint lastline = doc->lastLine(); // necessary to print selection only
uint firstline( 0 );
const int fontHeight = renderer.fontHeight();
KTextEditor::Range selectionRange;
/*
* Now on for preparations...
* during preparations, variable names starting with a "_" means
* those variables are local to the enclosing block.
//.........这里部分代码省略.........
开发者ID:niteshnarayanlal,项目名称:Kate,代码行数:101,代码来源:kateprinter.cpp
|
请发表评论