1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00
This commit is contained in:
jules 2007-08-06 17:22:43 +00:00
parent 45cfdc3ea9
commit 136023ab95
2 changed files with 28 additions and 46 deletions

View file

@ -2358,67 +2358,49 @@ static int getCharacterCategory (const tchar character) throw()
? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
}
int TextEditor::findWordBreakAfter (int position) const throw()
int TextEditor::findWordBreakAfter (const int position) const throw()
{
const String t (getTextSubstring (position, position + 512));
const int totalLength = t.length();
int i = 0;
while (i < totalLength)
{
if (CharacterFunctions::isWhitespace (t [i]))
++position;
else
break;
while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
++i;
}
const int type = getCharacterCategory (t [i]);
while (i < totalLength)
{
if (type == getCharacterCategory (t [i]))
++position;
else
break;
const int type = getCharacterCategory (t[i]);
while (i < totalLength && type == getCharacterCategory (t[i]))
++i;
}
return position;
while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
++i;
return position + i;
}
int TextEditor::findWordBreakBefore (int position) const throw()
int TextEditor::findWordBreakBefore (const int position) const throw()
{
if (position > 0)
if (position <= 0)
return 0;
const int startOfBuffer = position - jmin (512, position);
const String t (getTextSubstring (startOfBuffer, position));
int i = position - startOfBuffer;
while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
--i;
if (i > 0)
{
const int maximumToDo = jmin (512, position);
const int startOfBuffer = position - maximumToDo;
const String t (getTextSubstring (startOfBuffer, position));
const int type = getCharacterCategory (t [i - 1]);
while (position > startOfBuffer)
{
if (CharacterFunctions::isWhitespace (t [position - 1 - startOfBuffer]))
--position;
else
break;
}
const int type = (position > startOfBuffer)
? getCharacterCategory (t [position - 1 - startOfBuffer])
: 0;
while (position > startOfBuffer)
{
if (type == getCharacterCategory (t [position - 1 - startOfBuffer]))
--position;
else
break;
}
while (i > 0 && type == getCharacterCategory (t [i - 1]))
--i;
}
return jmax (position, 0);
jassert (startOfBuffer + i >= 0);
return startOfBuffer + i;
}

View file

@ -665,8 +665,8 @@ private:
int indexAtPosition (const float x,
const float y) throw();
int findWordBreakAfter (int position) const throw();
int findWordBreakBefore (int position) const throw();
int findWordBreakAfter (const int position) const throw();
int findWordBreakBefore (const int position) const throw();
friend class TextHolderComponent;
friend class TextEditorViewport;