From a91dfcb39b41a71a6efd9e8e12bfe16ad991f9c1 Mon Sep 17 00:00:00 2001 From: gocha Date: Mon, 16 Jul 2012 19:03:49 +0900 Subject: [PATCH] =?UTF-8?q?win32:=20improve=20DBCS=20processing=20in=20S9x?= =?UTF-8?q?Basename.=20This=20one=20should=20process=20S9xBasename("C:\rom?= =?UTF-8?q?s\=E3=82=BD=E3=82=A6=E3=83=AB=E3=83=96=E3=83=AC=E3=82=A4?= =?UTF-8?q?=E3=83=80=E3=83=BC.smc")=20correctly.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- win32/win32.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/win32/win32.cpp b/win32/win32.cpp index 7d4a52fb..34922807 100644 --- a/win32/win32.cpp +++ b/win32/win32.cpp @@ -611,16 +611,28 @@ void S9xSyncSpeed( void) const char *S9xBasename (const char *f) { - const char *p; - if ((p = strrchr (f, '/')) != NULL || (p = strrchr (f, '\\')) != NULL) - return (p + 1); + const char *p = f; + const char *last = p; + const char *slash; -#ifdef __DJGPP - if (p = _tcsrchr (f, SLASH_CHAR)) - return (p + 1); + // search rightmost separator + while ((slash = strchr (p, '/')) != NULL || (slash = strchr (p, '\\')) != NULL) + { + p = slash + 1; + +#ifdef UNICODE + // update always; UTF-8 doesn't have a problem between ASCII character and multi-byte character. + last = p; +#else + // update if it's not a trailer byte of a double-byte character. + if (CharPrev(f, p) == slash) + { + last = p; + } #endif + } - return (f); + return last; } bool8 S9xReadMousePosition (int which, int &x, int &y, uint32 &buttons)