本文整理汇总了C++中JRegex类的典型用法代码示例。如果您正苦于以下问题:C++ JRegex类的具体用法?C++ JRegex怎么用?C++ JRegex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JRegex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SaveFileForSearch
JBoolean
CBSearchTextDialog::BuildSearchFileList
(
JPtrArray<JString>* fileList,
JPtrArray<JString>* nameList
)
const
{
(JXGetApplication())->DisplayBusyCursor();
fileList->SetCleanUpAction(JPtrArrayT::kDeleteAll);
fileList->SetCompareFunction(JCompareStringsCaseSensitive);
nameList->SetCleanUpAction(JPtrArrayT::kDeleteAll);
nameList->SetCompareFunction(JCompareStringsCaseSensitive);
if (itsMultifileCB->IsChecked())
{
const JPtrArray<JString>& fullNameList = itsFileList->GetFullNameList();
const JSize count = fullNameList.GetElementCount();
for (JIndex i=1; i<=count; i++)
{
SaveFileForSearch(*(fullNameList.NthElement(i)), fileList, nameList);
}
}
JBoolean ok = kJTrue;
JString path, fileFilter, pathFilter;
if (GetSearchDirectory(&path, &fileFilter, &pathFilter))
{
JRegex* fileRegex = NULL;
JString regexStr;
if (JDirInfo::BuildRegexFromWildcardFilter(fileFilter, ®exStr))
{
fileRegex = jnew JRegex(regexStr);
assert( fileRegex != NULL );
fileRegex->SetCaseSensitive(kJFalse);
}
JRegex* pathRegex = NULL;
if (JDirInfo::BuildRegexFromWildcardFilter(pathFilter, ®exStr))
{
pathRegex = jnew JRegex(regexStr);
assert( pathRegex != NULL );
pathRegex->SetCaseSensitive(kJFalse);
}
JLatentPG pg(100);
pg.VariableLengthProcessBeginning("Collecting files...", kJTrue, kJFalse);
ok = SearchDirectory(path, fileRegex, pathRegex, fileList, nameList, pg);
pg.ProcessFinished();
jdelete fileRegex;
jdelete pathRegex;
}
return JI2B( ok && !fileList->IsEmpty() );
}
示例2: lineIndexRegex
void
JExtractFileAndLine
(
const JCharacter* str,
JString* fileName,
JIndex* startLineIndex,
JIndex* endLineIndex
)
{
static JRegex lineIndexRegex(":([0-9]+)(-([0-9]+))?$");
*fileName = str;
JArray<JIndexRange> matchList;
if (lineIndexRegex.Match(*fileName, &matchList))
{
JString s = fileName->GetSubstring(matchList.GetElement(2));
JBoolean ok = s.ConvertToUInt(startLineIndex);
assert( ok );
const JIndexRange endRange = matchList.GetElement(4);
if (endLineIndex != NULL && !endRange.IsEmpty())
{
s = fileName->GetSubstring(endRange);
ok = s.ConvertToUInt(endLineIndex);
assert( ok );
}
else if (endLineIndex != NULL)
{
*endLineIndex = *startLineIndex;
}
fileName->RemoveSubstring(matchList.GetElement(1));
}
else
{
*startLineIndex = 0;
if (endLineIndex != NULL)
{
*endLineIndex = 0;
}
}
}
示例3: ClearWildcardFilter
void
JDirInfo::SetWildcardFilter
(
const JCharacter* filterStr,
const JBoolean negate,
const JBoolean caseSensitive
)
{
JString regexStr;
if (!BuildRegexFromWildcardFilter(filterStr, ®exStr))
{
ClearWildcardFilter();
return;
}
JRegex* r = new JRegex(regexStr);
assert( r != NULL );
r->SetCaseSensitive(caseSensitive);
SetWildcardFilter(r, kJTrue, negate);
}
示例4: JTellg
int
GMScanner::yylex()
{
if (itsCurrentPosition == 0)
{
itsIs >> std::ws;
itsCurrentPosition = JTellg(*itsIs);
itsCurrentHeaderStart = itsCurrentPosition;
itsText = JReadLine(*itsIs);
JRegex regex;
JBoolean matched;
JArray<JStringRange>* subList = new JArray<JStringRange>;
assert(subList != NULL);
err = regex.SetPattern("^From[[:space:]]+.*.{3}[[:space:]]+.{3}[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+:[[:digit:]]+:[[:digit:]]+[[:space:]]+[[:digit:]]{4}");
assert(err.OK());
matched = regex.Match(itsText, subList);
delete subList;
if (matched)
{
itsState = kHeaderStart;
return itsState;
}
}
示例5: JGetPermissions
JBoolean
MatchesCookie
(
const JCharacter* cookie,
const JDirEntry& entry
)
{
JString file = entry.GetFullName();
if (!JFileReadable(file))
{
return kJFalse;
}
mode_t perms;
JError err = JGetPermissions(file, &perms);
if (!err.OK())
{
perms = 0600;
}
ifstream is(file);
is >> ws;
JString line1 = JReadLine(is);
is.close();
if (line1 == "")
{
return kJTrue;
}
JArray<JIndexRange> subList;
JRegex regex;
err = regex.SetPattern(cookie);
JBoolean matched = regex.Match(line1, &subList);
if (matched)
{
return kJTrue;
}
return kJFalse;
}
示例6: XListFonts
void
JXFontManager::GetXFontNames
(
const JRegex& regex,
JPtrArray<JString>* fontNames,
JSortXFontNamesFn compare
)
const
{
fontNames->CleanOut();
fontNames->SetCompareFunction(
compare != NULL ? compare : JCompareStringsCaseInsensitive);
fontNames->SetSortOrder(JOrderedSetT::kSortAscending);
#ifdef _J_USE_XFT
#else
int nameCount;
char** nameList = XListFonts(*itsDisplay, "*", INT_MAX, &nameCount);
if (nameList == NULL)
{
return;
}
for (int i=0; i<nameCount; i++)
{
if (regex.Match(nameList[i]) && strcmp(nameList[i], "nil") != 0)
{
JString name = nameList[i];
JBoolean isDuplicate;
const JIndex index =
fontNames->GetInsertionSortIndex(&name, &isDuplicate);
if (!isDuplicate)
{
JString* n = new JString(name);
assert( n != NULL );
fontNames->InsertAtIndex(index, n);
}
}
}
XFreeFontNames(nameList);
#endif
}
示例7: GetSubject
const JString&
GMessageHeader::GetBaseSubject()
{
if (itsHasBaseSubject)
{
return itsBaseSubject;
}
itsHasBaseSubject = kJTrue;
itsBaseSubject = GetSubject();
kFixSubjectRegex.SetCaseSensitive(kJFalse);
JArray<JIndexRange> subList;
while (kFixSubjectRegex.Match(itsBaseSubject, &subList))
{
itsBaseSubject = itsBaseSubject.GetSubstring(subList.GetElement(subList.GetElementCount()));
itsBaseSubject.TrimWhitespace();
subList.RemoveAll();
}
const JSize length = itsBaseSubject.GetLength();
JIndex findex = 1;
while (findex <= length &&
!isalnum(itsBaseSubject.GetCharacter(findex)))
{
findex++;
}
if (findex > 1 && findex <= length)
{
itsBaseSubject = itsBaseSubject.GetSubstring(findex, length);
}
return itsBaseSubject;
}
示例8: GetX
void
GDBPlot2DCommand::HandleSuccess
(
const JString& data
)
{
JArray<JFloat>* x = GetX();
JArray<JFloat>* y = GetY();
if ((GetLastResult()).BeginsWith("error,msg=\"No symbol"))
{
x->RemoveAll();
y->RemoveAll();
return;
}
const JIndex count = x->GetElementCount();
JIndex i;
JIndexRange r;
JArray<JIndexRange> matchRange1, matchRange2;
JString v1, v2;
for (i=1; i<=count; i++)
{
if (!prefixPattern.MatchAfter(data, r, &matchRange1))
{
break;
}
r = matchRange1.GetElement(1);
if (!prefixPattern.MatchAfter(data, r, &matchRange2))
{
break;
}
r = matchRange2.GetElement(1);
v1 = data.GetSubstring(matchRange1.GetElement(2));
v1.TrimWhitespace();
v2 = data.GetSubstring(matchRange2.GetElement(2));
v2.TrimWhitespace();
JFloat x1, y1;
if (!v1.ConvertToFloat(&x1) ||
!v2.ConvertToFloat(&y1))
{
break;
}
x->SetElement(i, x1);
y->SetElement(i, y1);
}
if (i <= count)
{
const JSize delta = count - (i-1);
x->RemoveNextElements(count - delta + 1, delta);
y->RemoveNextElements(count - delta + 1, delta);
}
}
示例9: if
void
CBTCLStyler::StyleEmbeddedVariables
(
const Token& token
)
{
emptyVariablePattern.SetSingleLine();
variablePattern.SetSingleLine();
const JString& text = GetText();
JFontStyle varStyle = GetTypeStyle(token.type - kWhitespace);
varStyle.underlineCount++;
if (varStyle == GetTypeStyle(kVariable - kWhitespace))
{
varStyle.underlineCount++;
}
JFontStyle errStyle = GetTypeStyle(kError - kWhitespace);
errStyle.underlineCount++;
if (errStyle == GetTypeStyle(kVariable - kWhitespace))
{
errStyle.underlineCount++;
}
JIndexRange r = token.range, r1, r2;
while (!r.IsEmpty())
{
const JCharacter c = text.GetCharacter(r.first);
if (c == '\\')
{
r.first++;
}
else if (c == '$')
{
r1 = r - (r.first-1);
if (emptyVariablePattern.MatchWithin(text.GetCString() + r.first-1, r1, &r2))
{
r2 += r.first-1;
AdjustStyle(r2, errStyle);
r.first = r2.last;
}
else if (variablePattern.MatchWithin(text.GetCString() + r.first-1, r1, &r2))
{
r2 += r.first-1;
AdjustStyle(r2, varStyle);
r.first = r2.last;
}
}
r.first++;
}
}
示例10: if
JBoolean
CBCStyler::SlurpPPComment
(
JIndexRange* totalRange
)
{
const JString& text = GetText();
const JString s = text.GetSubstring((GetPPNameRange()).first, totalRange->last);
if (!ppCommentPattern.Match(s))
{
return kJFalse;
}
Token token;
JString ppCmd;
JSize nestCount = 1;
while (1)
{
token = NextToken();
if (token.type == kEOF)
{
break;
}
else if (token.type == kPPDirective)
{
ppCmd = text.GetSubstring(GetPPNameRange());
if (ppIfPattern.Match(ppCmd))
{
nestCount++;
}
else if (ppEndPattern.Match(ppCmd))
{
nestCount--;
if (nestCount == 0)
{
break;
}
}
else if (ppElsePattern.Match(ppCmd) && nestCount == 1)
{
Undo(token.range, text.GetSubstring(token.range)); // rescan
token.range.last = token.range.first - 1;
break;
}
}
}
totalRange->last = token.range.last;
return kJTrue;
}
示例11:
JXPSPrintSetupDialog*
CBPSPrinter::CreatePrintSetupDialog
(
const Destination destination,
const JCharacter* printCmd,
const JCharacter* fileName,
const JBoolean collate,
const JBoolean bw
)
{
assert( itsCBPrintSetupDialog == NULL );
if (itsFontSize == kUnsetFontSize)
{
JString fontName;
CBGetPrefsManager()->GetDefaultFont(&fontName, &itsFontSize);
JArray<JIndexRange> matchList;
if (nxmRegex.Match(fontName, &matchList))
{
const JString hStr = fontName.GetSubstring(matchList.GetElement(2));
const JBoolean ok = hStr.ConvertToUInt(&itsFontSize);
assert( ok );
itsFontSize--;
}
}
itsCBPrintSetupDialog =
CBPSPrintSetupDialog::Create(destination, printCmd, fileName,
collate, bw, itsFontSize,
(CBGetPTTextPrinter())->WillPrintHeader());
return itsCBPrintSetupDialog;
}
示例12: DecodeMIMEWord
void
GMessageHeader::DecodeMIMEHeader
(
JString* header
)
{
JArray<JIndexRange> subList;
JSize count = encodedMIMEQRegex.MatchAll(*header, &subList);
JBoolean qType = kJTrue;
if (count == 0)
{
count = encodedMIMEBRegex.MatchAll(*header, &subList);
qType = kJFalse;
}
if (count > 0)
{
JString temp;
JIndex mIndex = 1;
const JSize count = subList.GetElementCount();
for (JIndex i = 1; i <= count; i++)
{
JIndexRange range = subList.GetElement(i);
// if ((range.first != mIndex) &&
// RangeContainsNWS(*header, mIndex, range.first))
// {
// temp += header->GetSubstring(mIndex, range.first - 1);
// }
if (range.first != mIndex)
{
JString trimmed = header->GetSubstring(mIndex, range.first - 1);
trimmed.TrimWhitespace();
if (!trimmed.IsEmpty())
{
temp += header->GetSubstring(mIndex, range.first - 1);
}
}
temp += DecodeMIMEWord(qType, header, range);
mIndex = range.last + 1;
}
if (mIndex < header->GetLength())
{
temp += header->GetSubstring(mIndex, header->GetLength());
}
*header = temp;
}
}
示例13: stream
CMLocation
GDBGetStopLocation::GetLocation()
const
{
const JString& data = GetLastResult();
CMLocation loc;
JIndexRange r;
if (locationPattern.Match(data, &r))
{
std::istringstream stream(data.GetCString());
stream.seekg(r.last);
JStringPtrMap<JString> map(JPtrArrayT::kDeleteAll);
JString *s, *s1, *fullName;
JIndex lineIndex;
const JBoolean parsed = GDBLink::ParseMap(stream, &map);
if (!parsed)
{
(CMGetLink())->Log("invalid data map");
}
else if (!map.GetElement("fullname", &fullName))
{
(CMGetLink())->Log("missing file name");
}
else if (!map.GetElement("line", &s))
{
(CMGetLink())->Log("missing line index");
}
else if (!s->ConvertToUInt(&lineIndex))
{
(CMGetLink())->Log("line index is not integer");
}
else
{
loc.SetFileName(*fullName);
loc.SetLineNumber(lineIndex);
}
if (parsed && map.GetElement("func", &s) && map.GetElement("addr", &s1))
{
loc.SetFunctionName(*s);
loc.SetMemoryAddress(*s1);
}
}
else
{
(CMGetLink())->Log("GDBGetStopLocation failed to match");
}
return loc;
}
示例14: parser
void
GDBVarCommand::HandleSuccess
(
const JString& data
)
{
JString s = data;
s.TrimWhitespace();
JBoolean success = kJFalse;
JIndexRange r;
prefixPattern.SetSingleLine();
if (prefixPattern.Match(data, &r))
{
s.RemoveSubstring(r);
SetData(s);
GDBVarTreeParser parser(s);
if (parser.yyparse() == 0)
{
parser.ReportRecoverableError();
success = kJTrue;
Broadcast(ValueMessage(kValueUpdated, parser.GetRootNode()));
}
}
else
{
(CMGetLink())->Log("GDBVarCommand failed to match");
}
if (!success)
{
Broadcast(ValueMessage(kValueFailed, NULL));
}
s.Clear();
SetData(s);
}
示例15: if
JBoolean
CBCommandTable::ExtractInputData
(
const JPoint& cell
)
{
assert( itsTextInput != NULL && cell.x != kOptionsColumn );
CBCommandManager::CmdInfo info = itsCmdList->GetElement(cell.y);
const JString& text = itsTextInput->GetText();
JString* s = NULL;
if (cell.x == kMenuTextColumn)
{
s = info.menuText;
}
else if (cell.x == kMenuShortcutColumn)
{
s = info.menuShortcut;
}
else if (cell.x == kScriptNameColumn)
{
if (illegalNamePattern.Match(text))
{
(JGetUserNotification())->ReportError(JGetString(kNoSpacesInCmdNameID));
return kJFalse;
}
s = info.name;
}
else if (cell.x == kCommandColumn)
{
s = info.cmd;
}
else if (cell.x == kPathColumn)
{
s = info.path;
}
assert( s != NULL );
if (itsTextInput->InputValid())
{
*s = text;
s->TrimWhitespace();
return kJTrue;
}
else
{
return kJFalse;
}
}