Skip to content

Commit

Permalink
Remove UTF8 StrAt in favor of converting to/from UTF16
Browse files Browse the repository at this point in the history
Add SBCS detection and fallback to StrCase.
Increase version for new release.
  • Loading branch information
Kawa-oneechan committed Aug 20, 2020
1 parent 2ebc448 commit 52ba977
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 40 deletions.
2 changes: 1 addition & 1 deletion BASE/INFO.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ char makeDate[] = __DATE__;
char makeTime[] = __TIME__;
char maker[] = "Kawa";
char makeLocation[] = "C:/BASE";
char version[] = "1.KAWA.042";
char version[] = "1.KAWA.043";
char makeComment[] = "Built by Kawa";
2 changes: 1 addition & 1 deletion EXT/INFO.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ char makeDate[] = __DATE__;
char makeTime[] = __TIME__;
char maker[] = "Kawa";
char makeLocation[] = "C:/EXT";
char version[] = "1.KAWA.042";
char version[] = "1.KAWA.043";
char makeComment[] = "Built by Kawa";
40 changes: 23 additions & 17 deletions EXT/KERNEL.C
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,24 @@ global KERNEL(StrCase)
strptr str = Native(arg(1));
char work[255];
strptr str2 = work;
if (GetNumChars() <= 256)
{
/*
Fall back to SBCS if the current port uses a font
with 256 or fewer characters. Assume the best.
At worst, an input like "Pokémon" will uppercase
as "POKéMON" thanks to Unicode and ISO-8859-1
overlapping the way they do, which is a better
result than "POKoN". -- KAWA
*/
if (argCount == 2 && arg(2) > 0)
for (; *str != '\0'; ++str)
*str = toupper(*str);
else
for (; *str != '\0'; ++str)
*str = tolower(*str);
return;
}
if (argCount == 2 && arg(2) > 0)
{
while (*str)
Expand Down Expand Up @@ -1708,28 +1726,16 @@ global KERNEL(ShakeScreen)
//is present, set the byte to that value.
global KERNEL(StrAt)
{
#ifdef UTF8
memptr sp = (memptr)Native(arg(1));
int cnt = (int)arg(2) + 1;
while (cnt--)
sp = GetUTF8Char(sp);
acc = UTF8Char;
//TODO: allow setting
if (argCount == 3)
{
//if ((short)arg(3) < 0x80)
// *(sp - UTF8Count) = (byte)arg(3);
SetUTF8CharAt((memptr)Native(arg(1)), (int)arg(2), (short)arg(3));
//acc = (short)arg(3);
}
#else
memptr sp;

/*
There used to be a path for UTF-8 here. I removed it shortly after
fixing a dumb if-with-assignment bug figuring that the proper, safer
way to do it would be to use Utf8to16 and its counterpart. -- KAWA
*/
sp = (memptr)Native(arg(1)) + (int)arg(2);
acc = *sp;
if (argCount == 3)
*sp = (byte)arg(3);
#endif
}


Expand Down
21 changes: 0 additions & 21 deletions EXT/STRING.C
Original file line number Diff line number Diff line change
Expand Up @@ -138,33 +138,12 @@ void SetUTF8CharAt(char *str, int index, short utf)
//Return the length of the string pointed to by 's'.
global uint strlen(strptr s)
{
/*
#ifdef UTF8
int r = 0;
while (*s++)
{
r++;
if ((*s & 0xE0) == 0xC0)
{
s++;
r++;
}
else if ((*s & 0xF0) == 0xE0)
{
s += 2;
r += 2;
}
}
return r;
#else
*/
strptr t;

t = s;
while (*t++)
;
return (t - s - 1);
//#endif
}


Expand Down

0 comments on commit 52ba977

Please sign in to comment.