|
lets say i have a regular expression (im using boost::regex)
([a-z],)*
and i Match() with "a," i get the following sub-expressions:
0) a, (the whole expression is first in boost::regex)<br />
1) a, (that's inside parentheses)
if i Match() with "a,b,c," however, i get:
0) a,<br />
1) c, (the last occurence of the things in parentheses)
i NEED to get all of the occurences though, like this:
0) a,<br />
1) a,<br />
2) b,<br />
3) c,
the problem is that, this is not a bug:
from
http://www.boost.org/libs/regex/syntax.htm#syntax[^]:
For example the expression "(ab)*" would match all of the string "ababab". The matching algorithms regex_match and regex_search each take an instance of match_results that reports what caused the match, on exit from these functions the match_results contains information both on what the whole expression matched and on what each sub-expression matched. In the example above match_results[1] would contain a pair of iterators denoting the final "ab" of the matching string.
so, can someone help me figure out how to get ALL of the matching occurences of the sub-expression?
thanks in advance
- Roman -
|
|
|
|
|
If you want to match a string with an arbitrary number of letters and commas, you will not succeed I'm afraid.
What you want is a context-free grammar for your input "language". I'm not sure if you are familiar with BNF (Backis-Naur Form), but here's such a grammar notation:
<string> ::= <string> <letter_comma_group>
| (empty)
<letter_comma_group> ::= ['a'-'z'] ','
Regular expressions can only handle languages which follow something called regular grammars. Regular grammars cannot handle self reference - thus you will not be able to do what you want.
Please see Chomskys grammar hierarchy[^] for more information on this topic.
If you want to solve your problem, I suggest you look into writing a recursive descent parser http://www.wikipedia.org/wiki/Recursive_descent_parser[^]. But before you start implementing the grammar I mentioned above, please make sure you rewrite it to be LL(n) compatible. (Left-recursion in an LL(n) grammar is a big no-no! Try it and you'll find out why.
<string> ::= <letter_comma_group> <opt_string>
| (empty)
<opt_string> ::= <letter_comma_group> <opt_string>
| (empty)
<letter_comma_group> ::= ['a'-'z'] ','
Good luck!
--
Please state the nature of your medical emergency.
|
|
|
|
|
There is no easy solution. How i've solved this in the past is to replace the matched pattern with something else, and loop, like this (perl) :-
$p="a,b,c,d,e,f,g,";
$matchcount=0;
while ($p=~s/([a-z],)
print ++$matchcount.": ".$1."\n";
Note that I lose the * from your pattern; you only want to match 1 at a time. =~ is the pattern operator in perl; // are delimeters around a pattern; s/// substitutes the first pattern with the second, ie nothing in this case. $1 is a special var which contains the first stored match.
Incidentally though, if your pattern really is as simple as a comma separated list, you may as well use a Split type function (theres bound to be one in your regexp library. In perl again:-
$p="a,b,c,d,e,f,g,";
@results = split (/,/ ,$p);
foreach $result (@results)
{
print $result."\n";
}
Hope that helps.
Signature space for rent. Apply by email to....
|
|
|
|
|
Hi,
have you ever come across converting a *.wbmp (wireless bitmap) into normal bitmap or *.jpg and vice versa?
Any answer would be highly appreciated!
Thanks
R.
|
|
|
|
|
Exactly what difference is there between a wireless bitmap and a normal bitmap? Please excuse my ignorance.
--
Please state the nature of your medical emergency.
|
|
|
|
|
A wireless bitmap is, like the small brother of a normal bitmap, small, primitive, monochrom, and on top of all it is of different structure than *.bmp because no MS tool (including IE or Paint) is able to show it.
It is used on wireless devices (handy). WAP pages are written in so called WML (Wireless Markup Laguage) and they can only have references to *.wbmp pictures.
I would want to show these pics on IE if I knew how to convert them to human readable format.
R.
|
|
|
|
|
this will do it: http://www.smalleranimals.com/thumb.htm
there's code on the codeproject site, too (i think), if you need that.
-c
bit, n:
A unit of measure applied to color. Twenty-four-bit color refers to expensive $3 color as opposed to the cheaper 25 cent, or two-bit, color that use to be available a few years ago.
|
|
|
|
|
The question came up today in our shop "can I call one constructor from another just like I can in java" and 'out of curiousity' tried to figure out if it can be done...After a few attempts (at what I thought were direct 'and sensible' approaches that only made the compiler whine) I came up with the following....Now, don't get me wrong, I'm not advocating that anyone *should* do this....only that it appears that you can and that it looks like it 'works'....
#include "stdafx.h"
#include "stdlib.h"
int flag;
class CtorTest
{
public:
CtorTest( void )
{
int x = 1;
}
CtorTest( int iFoo )
{
new( this ) CtorTest;
int x = 2;;
}
~CtorTest( void )
{
int x = 1;
}
void operator delete(void* p, CtorTest* poOuter)
{
free( poOuter );
}
void* operator new(size_t s, CtorTest* poOuter )
{
return poOuter;
}
};
int main(int argc, char* argv[])
{
printf("Hello World!\n");
int aNum = 5;
CtorTest x( aNum );
return 0;
}
Just trying to keep the forces of entropy at bay
|
|
|
|
|
okay, thought a little explanation is due here as well.....in main() we get a CtorTest object and the CtorTest::CtorTest(int) constructor gets called. Then we jump into the placement new function that effectively returns 'this'....Then from that point, we jump into the CtorTest::CtorTest(void) function ( invoked right after the return from the local placement new function. After that, control returns to the 'first constructor' call and we return to main. To support the assertion that there is only one CtorTest object created (?), the destructor is only called once......strange...very strange...
Just trying to keep the forces of entropy at bay
|
|
|
|
|
Sure, why not? It's perfectly legal to do replacement new like that. However, I'm sure it would be frowned upon in a programming team.
One way to do it with a more java-like syntax would be:
template <typename T>
class java_lookalike_helper {
protected:
typedef T this_t;
};
#define this_ new (this) this_t
class Class : java_lookalike_helper<Class> {
int x, int y;
public:
Class(int x_) : x(x_) {
}
Class(int x_, int y_) : y(_y) {
this_(x_);
}
};
--
Please state the nature of your medical emergency.
|
|
|
|
|
thanx for that variant of this idea. I'll add that to the 'tool kit' and play around with that as well.....this arcane-chicanery must be what causes some advocates to lean toward the 'managed code' camp...where we likely can't have this kind of 'fun' with the language ;)
Just trying to keep the forces of entropy at bay
|
|
|
|
|
Hey, exploring seamingly nutty ideas may indeed evolve into something really cool. Just look at ATL and WTL - now there are some wild and crazy ideas that have evolved into something cool and useful
And the advocates can bite me and my gotos.
--
Please state the nature of your medical emergency.
|
|
|
|
|
Jörgen Sigvardsson wrote:
And the advocates can bite me and my gotos
I'm with you buddy! I've been known to sprinkle a goto on an as-needed basis (much to the chagrin of some 'religious types')....but only when it does not violate the idea of 'good taste'
Just trying to keep the forces of entropy at bay
|
|
|
|
|
Hi
I have a Dialogbased MFC Application,
on the Dialog there is a "textfield" (CEdit) called m_thing.
m_thing.SetWindowText("something");
changes the "textfield"'s content to "something"
my problem: i need to change the "textfield" when there comes data
on a tcp/ip network socket
now i have a class CMySock derived from CAsyncSocket.
the OnReceive method is overlayed / overwritten by my own method.
in the dialog class i create a CMySocket and connect it
then there comes data
in my Onreceive method there is code to receive this data
(i can give it out with an AfxMessageBox this works fine)
but i need to change the "textfield" on the dialog
but the m_thing is not known in my CMySocket class
my question:
how do i get the data from the Onreceive method to my textfield /
to the dialog class...
i read stuff about messages and ON_COMMAND's and alot more i do not
understand
do i need to create an new class to use the OnReceive??
please help
and please excuse the bad expressions like "textfield"
thanks mb
|
|
|
|
|
Fist override the Onreceive event of ur CMySock class
like as follows
void CClientSocket::OnReceive(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
AfxGetMainWnd()->PostMessage(WM_APP + 24, 0,0);
CSocket::OnReceive(nErrorCode);
}
Then post a MEssage to the main window from here "AfxGetMainWnd()->PostMessage(WM_APP + 24, 0,0);"
I then dialog catch this message
ON_MESSAGE(SOCK_RCV_MSG, OnReceive)
void CClientDlg::OnReceive()
{
char buff[SEND_BUF_SIZE];
int nBytes;
CString strLog;
nBytes = m_Sock1->Receive(buff, SEND_BUF_SIZE);
if(nBytes == 0)
{
// got disconnected
}
}
Now u can do anything witht he data in the buff
Hope this will help u
|
|
|
|
|
|
Thought some of you might be interested in the following page:
http://msdn.microsoft.com/library/en-us/dnapiover/html/api-overview.asp
It documents some of the APIs that Microsoft has hidden from us to make their programs unique or a step-ahead.
"November 2001, Microsoft, the U.S. Department of Justice, and nine State Attorneys General agreed to a proposed settlement of the government's antitrust case (proposed consent decree). For more information (including a comprehensive archive of documents and transcripts of proceedings) about the proposed consent decree, see the Microsoft Press Pass Settlement Proceedings Web page. For more information about how Microsoft has fulfilled its obligations under the decree, please see the Microsoft Settlement Program Web page.
As part of that settlement, Microsoft agreed to document the interfaces used by "Microsoft Middleware" (as defined in the proposed consent decree) to obtain services from the Microsoft® Windows® 2000 and Windows XP desktop client operating systems. The vast majority of these interfaces were already documented among the thousands of Application Programming Interfaces (APIs) in the Microsoft Platform Software Development Kit (SDK).
Microsoft teams identified a few hundred undocumented Windows interfaces or parameters that were used by one or more of the Microsoft Middleware components. Microsoft's technical writers have documented these interfaces and made them available as APIs in the MSDN Online Library."
Cheers,
uniken
|
|
|
|
|
No big news. Most of this functions are not even correctly documented and few of them are helpful. Calling this an "advantage" is a joke.
The really useful interfaces are still undocumented.
...if you're under 8 or younger. Chris Maunder, the Lounge
|
|
|
|
|
This is puzzling. Execution never goes into either function when either action is done:
void CSortListCtrlTestDlg::OnColumnclickList(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
for (int i = 0; i < 10; i++)
AfxMessageBox (m_ctlList.m_shuffledIndex[i]);
*pResult = 0;
}
void CSortListCtrlTestDlg::OnItemclickList(NMHDR* pNMHDR, LRESULT* pResult)
{
HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
AfxMessageBox("ll");
*pResult = 0;
}
Am I trapping the wrong messages from class wizard? if so, what function can I have that will respond to the column click? (Right now the columnclick fires an OnColumnClick thats a member of the Clistctrl derived class. But not the col click in the dialog where the control is...
Appreciate your help,
ns
|
|
|
|
|
Probably your CSortListCtrl handles these notifications using so-called message reflection. If this is the case, you'll have to change ON_NOTIFY to ON_NOTIFY_EX in CSortListCtrl's message map and return FALSE from handler, which means that dialog will get its chance to respond to the event.
[edit]
Of course, the CSortListCtrl would use ON_NOTIFY_REFLECT, not ON_NOTIFY.
[/edit]
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
I dont have ON_NOTIFY:Instead its ON_NOTIFY_REFLECT Will ON_NOTIFY_REFLECT_EX be what I want?
BEGIN_MESSAGE_MAP(CSortListCtrl, CListCtrl)
ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnClick)
ON_WM_DESTROY()
END_MESSAGE_MAP()
Also, theres no return value for the CListCtrl function, its a void: I presume this is the handler you speak of?
void CSortListCtrl::OnColumnClick( NMHDR* pNMHDR, LRESULT* pResult )
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
const int iColumn = pNMListView->iSubItem;
Sort( iColumn, iColumn == m_iSortColumn ? !m_bSortAscending : TRUE );
RetrieveIndex();
*pResult = 0;
}
Appreciate your help,
ns
|
|
|
|
|
Yes - change macro to ON_NOTIFY_REFLECT, void to BOOL and add 'return TRUE;' as last line on CSortListCtrl::OnColumnClick handler.
If the class was downloaded from CP, don't forget to ask the author to change it in the article sources as well
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
Changed to _EX - no luck. But still havent figured out who is supposed to return false...
Appreciate your help,
ns
|
|
|
|
|
Sorry - it's 'return TRUE;' in CSortListCtrl handler connected to msg map with ON_NOTIFY_REFLECT_EX macro.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
Did both things that you said --BOOL and _EX. Still no response!
Appreciate your help,
ns
rebuilt it too!
|
|
|
|
|