Best way to match a group of characters (not a keyword)

44 views
Skip to first unread message

rhkr...@gmail.com

unread,
Jun 23, 2016, 7:05:21 AM6/23/16
to scintilla...@googlegroups.com

For the folder / lexer I want to write for the TWiki Markup Language (with variations and extensions), I need to recognize strings of characters like "---+". "---++". ..., "---++++++" to increment and decrement folding levels.

 

In the var'aq tutorial, I see code like this:

 

if ( scCTX . Match ( ’* ’ , ’) ’ )) {

scCTX . Forward ();

// Move over the )

 

and I'm thinking that one way to look for those strings might be something like this:

 

 

if ( scCTX . Match ('-', '-', '-', '+', '+')) {

 

followed by a for statement or similar that moves forward 5 characters (in this case).

 

Questions:

* would that Match statement work?

* is there a better way?

 

If it makes any difference, these strings only affect folding levels if they are at the beginning of a line, but I will have other things to match that will not necessarily be at the beginning of a line--I'll probably end up asking a separate question about those.

 

 

 

rhkr...@gmail.com

unread,
Jun 24, 2016, 12:18:22 PM6/24/16
to scintilla...@googlegroups.com
Ok, I found, in StyleContext.h:

1. the function (method, iiuc) bool Match(char ch0, char ch1) which answers
my first question, the approach I had in mind (using more than two arguments to
the method) will not work

2. the methods bool Match(const char *s) and the similar bool
MatchIgnoreCase(const char *s)

So, my next question is, how do I write the string argument to such a method:

* can I do something like:

scCTX.Match("---++ ")

* or must I do something more like

const char *s
...
s = "---++ "
scCTX.Match(s)

* or, something else?


For reference, here is the method from StyleContext.h:

bool Match(const char *s) {
if (ch != static_cast<unsigned char>(*s))
return false;
s++;
if (!*s)
return true;
if (chNext != static_cast<unsigned char>(*s))
return false;
s++;
for (int n=2; *s; n++) {
if (*s != styler.SafeGetCharAt(currentPos+n))
return false;
s++;
}
return true;
}

BTW, matches like the above should work only at the start of a line--I think
I've seen code that will let me see how to do that...

Neil Hodgson

unread,
Aug 16, 2016, 1:27:10 AM8/16/16
to scintilla...@googlegroups.com
rhkramer:

> So, my next question is, how do I write the string argument to such a method:
>
> * can I do something like:
>
> scCTX.Match("---++ “)

Yes.

> BTW, matches like the above should work only at the start of a line--I think
> I've seen code that will let me see how to do that…

If (scCTX.atLineStart)

Neil

rhkr...@gmail.com

unread,
Aug 16, 2016, 7:45:04 AM8/16/16
to scintilla...@googlegroups.com
Neil,

Thanks, and welcome back!

regards,
Randy Kramer
Reply all
Reply to author
Forward
0 new messages