Stuck...
detroit (174)
Feb 12, 2013 at 12:51am UTC
Hi everyone...
I am working on a school project where I have to make some addition to matching braces.
The code below has matching braces only for (...){...}[...] and I have to add /*...*/ and #ifndef...#endif
I am stuck as I am having a hard time understanding the code and let alone apply mine after words.
Here is the function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
void Notepad_plus::findMatchingBracePos(int & braceAtCaret, int & braceOpposite)
{
int caretPos = int (_pEditView->execute(SCI_GETCURRENTPOS));
braceAtCaret = -1;
braceOpposite = -1;
TCHAR charBefore = '\0' ;
int lengthDoc = int (_pEditView->execute(SCI_GETLENGTH));
if ((lengthDoc > 0) && (caretPos > 0))
{
charBefore = TCHAR(_pEditView->execute(SCI_GETCHARAT, caretPos - 1, 0));
}
// Priority goes to character before caret
if (charBefore && generic_strchr(TEXT("[](){}" ), charBefore))
{
braceAtCaret = caretPos - 1;
}
if (lengthDoc > 0 && (braceAtCaret < 0))
{
// No brace found so check other side
TCHAR charAfter = TCHAR(_pEditView->execute(SCI_GETCHARAT, caretPos, 0));
if (charAfter && generic_strchr(TEXT("[](){}" ), charAfter))
{
braceAtCaret = caretPos;
}
}
if (braceAtCaret >= 0)
braceOpposite = int (_pEditView->execute(SCI_BRACEMATCH, braceAtCaret, 0));
}
Any help is appreciated
Thanks