Bladeren bron

Basic Utf8 support

Simon Lübeß 3 jaren geleden
bovenliggende
commit
8847de545a
2 gewijzigde bestanden met toevoegingen van 34 en 22 verwijderingen
  1. 11 15
      IDE/src/ui/AutoComplete.bf
  2. 23 7
      IDEHelper/Compiler/FtsFuzzyMatch.h

+ 11 - 15
IDE/src/ui/AutoComplete.bf

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

+ 23 - 7
IDEHelper/Compiler/FtsFuzzyMatch.h

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