1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-14 14:24:10 +02:00

Basic Utf8 support

This commit is contained in:
Simon Lübeß 2021-12-11 23:38:25 +01:00
parent f9f53eb97b
commit 8847de545a
2 changed files with 34 additions and 22 deletions

View file

@ -405,28 +405,24 @@ namespace IDE.ui
float offset = GS!(20); float offset = GS!(20);
// TODO(FUZZY): this is not unicode compatible int index = 0;
for(int i < mEntryDisplay.Length) for(char32 c in mEntryDisplay.DecodedChars)
loop:
{ {
char8 c = mEntryDisplay[i]; if(mMatchIndices.Contains((uint8)index))
if(mMatchIndices.Contains((uint8)i))
{ {
g.PushColor(.Blue); g.PushColor(DarkTheme.COLOR_MENU_FOCUSED);
} defer:loop g.PopColor();
else
{
g.PushColor(.White);
} }
g.DrawString(.(&c, 1), offset, 0); let str = StringView(mEntryDisplay, index, @c.NextIndex - index);
offset += IDEApp.sApp.mCodeFont.GetWidth(.(&c, 1)); g.DrawString(str, offset, 0);
g.PopColor(); offset += IDEApp.sApp.mCodeFont.GetWidth(str);
index = @c.NextIndex;
} }
//g.DrawString(mEntryDisplay, GS!(20), 0);
} }
} }

View file

@ -37,6 +37,8 @@
#include <cstdio> #include <cstdio>
#include "BeefySysLib/util/UTF8.h"
// Public interface // Public interface
namespace fts { namespace fts {
static bool fuzzy_match_simple(char const* pattern, char const* str); static bool fuzzy_match_simple(char const* pattern, char const* str);
@ -102,8 +104,14 @@ namespace fts {
bool first_match = true; bool first_match = true;
while (*pattern != '\0' && *str != '\0') { while (*pattern != '\0' && *str != '\0') {
int patternOffset = 0;
uint32 patternChar = Beefy::u8_nextchar((char*)pattern, &patternOffset);
int strOffset = 0;
uint32 strChar = Beefy::u8_nextchar((char*)str, &strOffset);
// TODO: tolower only works for A-Z
// Found match // Found match
if (tolower(*pattern) == tolower(*str)) { if (tolower(patternChar) == tolower(strChar)) {
// Supplied matches buffer was too short // Supplied matches buffer was too short
if (nextMatch >= maxMatches) if (nextMatch >= maxMatches)
@ -118,7 +126,7 @@ namespace fts {
// Recursive call that "skips" this match // Recursive call that "skips" this match
uint8_t recursiveMatches[256]; uint8_t recursiveMatches[256];
int recursiveScore; int recursiveScore;
if (fuzzy_match_recursive(pattern, str + 1, recursiveScore, strBegin, matches, recursiveMatches, sizeof(recursiveMatches), nextMatch, recursionCount, recursionLimit)) { if (fuzzy_match_recursive(pattern, str + strOffset, recursiveScore, strBegin, matches, recursiveMatches, sizeof(recursiveMatches), nextMatch, recursionCount, recursionLimit)) {
// Pick best recursive score // Pick best recursive score
if (!recursiveMatch || recursiveScore > bestRecursiveScore) { if (!recursiveMatch || recursiveScore > bestRecursiveScore) {
@ -132,9 +140,9 @@ namespace fts {
matches[nextMatch++] = (uint8_t)(str - strBegin); matches[nextMatch++] = (uint8_t)(str - strBegin);
// Clear the next char so that we know which match is the last one // Clear the next char so that we know which match is the last one
matches[nextMatch + 1] = 0; matches[nextMatch + 1] = 0;
++pattern; pattern += patternOffset;
} }
++str; str += strOffset;
} }
// Determine if full pattern was matched // Determine if full pattern was matched
@ -172,19 +180,27 @@ namespace fts {
for (int i = 0; i < nextMatch; ++i) { for (int i = 0; i < nextMatch; ++i) {
uint8_t currIdx = matches[i]; uint8_t currIdx = matches[i];
int currOffset = currIdx;
uint32 curr = Beefy::u8_nextchar((char*)strBegin, &currOffset);
if (i > 0) { if (i > 0) {
uint8_t prevIdx = matches[i - 1]; uint8_t prevIdx = matches[i - 1];
int offsetPrevidx = prevIdx;
Beefy::u8_inc((char*)strBegin, &offsetPrevidx);
// Sequential // Sequential
if (currIdx == (prevIdx + 1)) if (currIdx == offsetPrevidx)
outScore += sequential_bonus; outScore += sequential_bonus;
} }
// Check for bonuses based on neighbor character value // Check for bonuses based on neighbor character value
if (currIdx > 0) { if (currIdx > 0) {
int neighborOffset = currIdx;
Beefy::u8_dec((char*)strBegin, &neighborOffset);
uint32 neighbor = Beefy::u8_nextchar((char*)strBegin, &neighborOffset);
// Camel case // Camel case
char neighbor = strBegin[currIdx - 1];
char curr = strBegin[currIdx];
if (::islower(neighbor) && ::isupper(curr)) if (::islower(neighbor) && ::isupper(curr))
outScore += camel_bonus; outScore += camel_bonus;