From fecb74d3cd3cd8d78003fd1b35a318d47ff6c1cc Mon Sep 17 00:00:00 2001 From: avolkov Date: Thu, 12 Jan 2006 00:48:28 +0000 Subject: [PATCH] Using own versions of wide char classification funcs to disjoint code from LC_CTYPE git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2164 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/sc2code/getchar.c | 8 +------- sc2/src/sc2code/libs/strings/unicode.c | 15 +++++++++++++++ sc2/src/sc2code/libs/strlib.h | 3 ++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/sc2/src/sc2code/getchar.c b/sc2/src/sc2code/getchar.c index c332a483d..89d48bb36 100644 --- a/sc2/src/sc2code/getchar.c +++ b/sc2/src/sc2code/getchar.c @@ -74,12 +74,6 @@ LoadJoystickAlpha (STRING String, int *count) return chars; } -static inline int -IsPrintableChar (wchar_t ch) -{ - return iswgraph (ch) || (ch == ' '); -} - static int JoyCharFindIn (const joy_char_t *ch, const joy_char_t *set, int setsize) @@ -212,7 +206,7 @@ DoTextEntry (PTEXTENTRY_STATE pTES) pTES->JoystickMode = FALSE; chsize = getStringFromChar (chbuf, sizeof (chbuf), ch); - if (IsPrintableChar (ch) && chsize > 0 + if (isWidePrintChar (ch) && chsize > 0 && (pStr + len - pTES->BaseStr + chsize < pTES->MaxSize)) { // insert character memmove (pStr + chsize, pStr, len + 1); diff --git a/sc2/src/sc2code/libs/strings/unicode.c b/sc2/src/sc2code/libs/strings/unicode.c index fcbc97667..66bf7d870 100644 --- a/sc2/src/sc2code/libs/strings/unicode.c +++ b/sc2/src/sc2code/libs/strings/unicode.c @@ -407,3 +407,18 @@ getStringFromWide(unsigned char *ptr, size_t size, const wchar_t *wstr) return getStringFromWideN(ptr, size, wstr, (end - wstr)); } + +int +isWideGraphChar(wchar_t ch) +{ // this is not technically sufficient, but close enough for us + // we'll consider all non-control (CO and C1) chars in 'graph' class + return (ch > 0xa0) || (ch > 0x20 && ch < 0x7f); +} + +int +isWidePrintChar(wchar_t ch) +{ // this is not technically sufficient, but close enough for us + // chars in 'print' class are 'graph' + 'space' classes + // the only space we currently have defined is 0x20 + return (ch == 0x20) || isWideGraphChar(ch); +} diff --git a/sc2/src/sc2code/libs/strlib.h b/sc2/src/sc2code/libs/strlib.h index 6ee120de5..3c5be5b3a 100644 --- a/sc2/src/sc2code/libs/strlib.h +++ b/sc2/src/sc2code/libs/strlib.h @@ -68,7 +68,8 @@ size_t getStringFromWideN(unsigned char *ptr, size_t size, const wchar_t *wstr, size_t count); size_t getStringFromWide(unsigned char *ptr, size_t size, const wchar_t *wstr); - +int isWideGraphChar(wchar_t ch); +int isWidePrintChar(wchar_t ch); #endif /* _STRLIB_H */