Beispiel #1
0
void
BF_GUI_Text::Find(char *pc_Sample, uint32 i_StartLine, uint32 i_StartCol)
{
	uint32	iColumn = i_StartCol;
	BString *poString;
	char cSample[256];
	bool bFound = false;
	BF_GUI_MessageBox *po_Message;

	ClearMatch();
	if (pc_Sample == NULL) 
	{
		FromUtf8(poMatch->String(),cSample);
	}
	else
	{
		FromUtf8(pc_Sample,cSample);
	}

	for(int32 i = i_StartLine; i < ploString->CountItems();i++)
	{
		poString = (BString *) ploString->ItemAt(i);
		if (poString->FindFirst(cSample,iColumn) != B_ERROR)
		{
			iMatchLine = i;
			bFound = true;
			break;
		};
		iColumn = 0;
	};
	if (bFound)
	{
		if (pc_Sample != NULL)
		{
			if (poMatch != NULL) delete(poMatch);
			poMatch = new BString(pc_Sample);
		};
		bDrawSel = true;
		BRect oRect = Bounds();
		float y = iMatchLine * poSysSetup->oFontNode.fHeight;
		ScrollTo(oRect.left,y);
		iStartSel = iColumn;
		DrawPage();
	}
	else
	{
		bDrawSel = false;
		if (i_StartLine)
		{
			po_Message = new BF_GUI_MessageBox(BRect(30,30,300,150),"Error","Not more samles found!",Parent(),"Ok");
		}
		else
		{
			po_Message = new BF_GUI_MessageBox(BRect(30,30,300,150),"Error","The sample is not found in this file!",Parent(),"Ok");
		}
		Parent()->AddChild(po_Message);
	};
};
Beispiel #2
0
// Line down action
void 
BF_GUI_Text::Nav_LineDown()
{
	if (bFullPage)
	{
		ScrollBy(0,20);
		ClearMatch();
	};		
};
Beispiel #3
0
// Key left action
void 
BF_GUI_Text::Nav_LineLeft()
{
	BRect oRect = Bounds();
	
	if (oRect.left > 0)
	{
		ScrollBy(-10,0);
		ClearMatch();
	};
};
Beispiel #4
0
// Line up action
void 
BF_GUI_Text::Nav_LineUp()
{
	BRect oRect = Bounds();
	
	if (oRect.top > 0)
	{
		ScrollBy(0,(oRect.top > 20) ? -20 : -oRect.top);
		ClearMatch();
	};		
};
Beispiel #5
0
// Page down action
void 
BF_GUI_Text::Nav_PageDown()
{
	if (bFullPage)
	{
		BRect oRect = Bounds();
		if (2 * oRect.bottom - oRect.top > poSysSetup->oFontNode.fHeight * ploString->CountItems())
		{
			ScrollTo(oRect.left,poSysSetup->oFontNode.fHeight * ploString->CountItems() - oRect.Height());
		}
		else
		{
			ScrollBy(0,oRect.Height());
		}
		ClearMatch();
	}
}
Beispiel #6
0
// page up action
void 
BF_GUI_Text::Nav_PageUp()
{
	BRect	oRect = Bounds();
	
	if (oRect.top <= 0) return;

	if (2 * oRect.top - oRect.bottom > 0)
	{
		ScrollBy(0,-oRect.Height());
	}
	else
	{
		ScrollBy(0,-oRect.top);
	};
	ClearMatch();
}
Beispiel #7
0
int RegEx::Match(const char *str)
{
	int rc = 0;

	if (mFree || re == NULL)
		return -1;

	ClearMatch();

	//save str
	subject = new char[strlen(str) + 1];
	strcpy(subject, str);

	rc = pcre_exec(re, NULL, subject, (int)strlen(subject), 0, 0, ovector, REGEX_MAX_SUBPATTERNS);

	if (rc < 0)
	{
		if (rc == PCRE_ERROR_NOMATCH)
		{
			return 0;
		}
		else {
			mErrorOffset = rc;
			return -1;
		}
	}

	RegExSub res;
	mSubStrings.ensure(rc);

	for (int s = 0; s < rc; ++s)
	{
		res.start = ovector[2 * s];
		res.end = ovector[2 * s + 1];
		mSubStrings.append(res);
	}

	return 1;
}
Beispiel #8
0
int RegEx::MatchAll(const char *str)
{
	int rr = 0;
	int rc = 0;
	int startOffset = 0;
	int exoptions = 0;
	int notEmpty = 0;
	int sizeOffsets = mNumSubpatterns * 3;
	int subjectLen = strlen(str);

	if (mFree || re == NULL)
	{
		return -1;
	}

	ClearMatch();
	
	subject = new char[subjectLen + 1];
	strcpy(subject, str);

	RegExSub sub;

	while (1)
	{
		rr = pcre_exec(re, NULL, subject, (int)subjectLen, startOffset, exoptions | notEmpty, ovector, REGEX_MAX_SUBPATTERNS);

		/**
		 * The string was already proved to be valid UTF-8
		 */
		exoptions |= PCRE_NO_UTF8_CHECK;

		/**
		 * Too many substrings
		 */
		if (rr == 0)
		{
			rr = sizeOffsets / 3;
		}

		if (rr > 0)
		{
			mMatchesSubs.append(rr);

			for (int s = 0; s < rr; ++s)
			{
				sub.start = ovector[2 * s];
				sub.end = ovector[2 * s + 1];

				mSubStrings.append(sub);
			}
		}
		else if (rr == PCRE_ERROR_NOMATCH)
		{
			/**
			 * If we previously set PCRE_NOTEMPTY after a null match,
			 * this is not necessarily the end. We need to advance
			 * the start offset, and continue. Fudge the offset values
			 * to achieve this, unless we're already at the end of the string. 
			 */
			if (notEmpty && startOffset < (int)subjectLen) 
			{
				ovector[0] = startOffset;
				ovector[1] = startOffset + 1;
			}
			else
			{
				break;
			}
		}
		else
		{
			mErrorOffset = rr;

			if (mMatchesSubs.length())
			{
				ClearMatch();
			}

			return -1;
		}

		/**
		 * If we have matched an empty string, mimic what Perl's /g options does.
		 * This turns out to be rather cunning. First we set PCRE_NOTEMPTY and try
		 * the match again at the same point. If this fails (picked up above) we
		 * advance to the next character. 
		 */
		notEmpty = (ovector[1] == ovector[0]) ? PCRE_NOTEMPTY | PCRE_ANCHORED : 0;

		/** 
		 * Advance to the next piece. 
		 */
		startOffset = ovector[1];
	}

	if (!mMatchesSubs.length())
	{
		return 0;
	}

	return 1;
}
Beispiel #9
0
// Key right action
void 
BF_GUI_Text::Nav_LineRight()
{
	ScrollBy(10,0);
	ClearMatch();
};