This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Simplify usage of __jp2uc


Corinna Vinschen wrote:
Hi,

This patch is a prerequisite for the new wcwidth/wcswidth implementation.

It's a bit burdensome that the conversion from JIS/SJIS/EUCJP to Unicode
is a 6-liner in every function which requires the conversion.  The idea
of this patch is to combine the functionality into a single function
_jp2uc, which in turn calls __jp2uc with the correct type value.  This
way, you only have a single line in the calling functions:

c = _jp2uc(c);

Ok to check in?

Ok.

-- Jeff J.
Thanks,
Corinna


* libc/ctype/local.h (JP_JIS, JP_SJIS, JP_EUCJP): Move definition to jp2uc.c. (__jp2uc): Remove declaration. (_jp2uc): Declare. * libc/ctype/jp2uc.c (JP_JIS, JP_SJIS, JP_EUCJP): Define. (__jp2uc): Remove Cygwin special case. (_jp2uc): New function. On Cygwin, just return c. * libc/ctype/iswalpha.c (iswalpha): Just call _jp2uc. * libc/ctype/iswblank.c (iswblank): Ditto. * libc/ctype/iswcntrl.c (iswcntrl): Ditto. * libc/ctype/iswprint.c (iswprint): Ditto. * libc/ctype/iswpunct.c (iswpunt): Ditto. * libc/ctype/iswspace.c (iswspace): Ditto. * libc/ctype/towlower.c (towlower): Ditto. * libc/ctype/towupper.c (towupper): Ditto.


Index: libc/ctype/iswalpha.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/ctype/iswalpha.c,v
retrieving revision 1.6
diff -u -p -r1.6 iswalpha.c
--- libc/ctype/iswalpha.c 24 Mar 2009 10:13:27 -0000 1.6
+++ libc/ctype/iswalpha.c 14 May 2009 08:30:59 -0000
@@ -76,12 +76,7 @@ _DEFUN(iswalpha,(c), wint_t c)
int size;
wint_t x;
- if (!strcmp (__locale_charset (), "JIS"))
- c = __jp2uc (c, JP_JIS);
- else if (!strcmp (__locale_charset (), "SJIS"))
- c = __jp2uc (c, JP_SJIS);
- else if (!strcmp (__locale_charset (), "EUCJP"))
- c = __jp2uc (c, JP_EUCJP);
+ c = _jp2uc (c);
x = (c >> 8);
/* for some large sections, all characters are alphabetic so handle them here */
Index: libc/ctype/iswblank.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/ctype/iswblank.c,v
retrieving revision 1.6
diff -u -p -r1.6 iswblank.c
--- libc/ctype/iswblank.c 24 Mar 2009 10:13:27 -0000 1.6
+++ libc/ctype/iswblank.c 14 May 2009 08:30:59 -0000
@@ -66,12 +66,7 @@ int
_DEFUN(iswblank,(c), wint_t c)
{
#ifdef _MB_CAPABLE
- if (!strcmp (__locale_charset (), "JIS"))
- c = __jp2uc (c, JP_JIS);
- else if (!strcmp (__locale_charset (), "SJIS"))
- c = __jp2uc (c, JP_SJIS);
- else if (!strcmp (__locale_charset (), "EUCJP"))
- c = __jp2uc (c, JP_EUCJP);
+ c = _jp2uc (c);
return (c == 0x0009 || c == 0x0020 || c == 0x1680 ||
(c >= 0x2000 && c <= 0x2006) ||
(c >= 0x2008 && c <= 0x200b) ||
Index: libc/ctype/iswcntrl.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/ctype/iswcntrl.c,v
retrieving revision 1.6
diff -u -p -r1.6 iswcntrl.c
--- libc/ctype/iswcntrl.c 24 Mar 2009 10:13:27 -0000 1.6
+++ libc/ctype/iswcntrl.c 14 May 2009 08:30:59 -0000
@@ -66,12 +66,7 @@ int
_DEFUN(iswcntrl,(c), wint_t c)
{
#ifdef _MB_CAPABLE
- if (!strcmp (__locale_charset (), "JIS"))
- c = __jp2uc (c, JP_JIS);
- else if (!strcmp (__locale_charset (), "SJIS"))
- c = __jp2uc (c, JP_SJIS);
- else if (!strcmp (__locale_charset (), "EUCJP"))
- c = __jp2uc (c, JP_EUCJP);
+ c = _jp2uc (c);
return ((c >= 0x0000 && c <= 0x001f) || (c >= 0x007f && c <= 0x009f) ||
c == 0x2028 || c == 0x2029);
Index: libc/ctype/iswprint.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/ctype/iswprint.c,v
retrieving revision 1.6
diff -u -p -r1.6 iswprint.c
--- libc/ctype/iswprint.c 24 Mar 2009 10:13:27 -0000 1.6
+++ libc/ctype/iswprint.c 14 May 2009 08:30:59 -0000
@@ -76,12 +76,7 @@ _DEFUN(iswprint,(c), wint_t c)
int size;
wint_t x;
- if (!strcmp (__locale_charset (), "JIS"))
- c = __jp2uc (c, JP_JIS);
- else if (!strcmp (__locale_charset (), "SJIS"))
- c = __jp2uc (c, JP_SJIS);
- else if (!strcmp (__locale_charset (), "EUCJP"))
- c = __jp2uc (c, JP_EUCJP);
+ c = _jp2uc (c);
x = (c >> 8);
/* for some large sections, all characters are printuation so handle them here */
Index: libc/ctype/iswpunct.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/ctype/iswpunct.c,v
retrieving revision 1.6
diff -u -p -r1.6 iswpunct.c
--- libc/ctype/iswpunct.c 24 Mar 2009 10:13:27 -0000 1.6
+++ libc/ctype/iswpunct.c 14 May 2009 08:30:59 -0000
@@ -76,12 +76,7 @@ _DEFUN(iswpunct,(c), wint_t c)
int size;
wint_t x;
- if (!strcmp (__locale_charset (), "JIS"))
- c = __jp2uc (c, JP_JIS);
- else if (!strcmp (__locale_charset (), "SJIS"))
- c = __jp2uc (c, JP_SJIS);
- else if (!strcmp (__locale_charset (), "EUCJP"))
- c = __jp2uc (c, JP_EUCJP);
+ c = _jp2uc (c);
x = (c >> 8);
/* for some large sections, all characters are punctuation so handle them here */
Index: libc/ctype/iswspace.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/ctype/iswspace.c,v
retrieving revision 1.6
diff -u -p -r1.6 iswspace.c
--- libc/ctype/iswspace.c 24 Mar 2009 10:13:27 -0000 1.6
+++ libc/ctype/iswspace.c 14 May 2009 08:30:59 -0000
@@ -66,12 +66,7 @@ int
_DEFUN(iswspace,(c), wint_t c)
{
#ifdef _MB_CAPABLE
- if (!strcmp (__locale_charset (), "JIS"))
- c = __jp2uc (c, JP_JIS);
- else if (!strcmp (__locale_charset (), "SJIS"))
- c = __jp2uc (c, JP_SJIS);
- else if (!strcmp (__locale_charset (), "EUCJP"))
- c = __jp2uc (c, JP_EUCJP);
+ c = _jp2uc (c);
return ((c >= 0x0009 && c <= 0x000d) || c == 0x0020 || c == 0x1680 ||
(c >= 0x2000 && c <= 0x2006) ||
(c >= 0x2008 && c <= 0x200b) ||
Index: libc/ctype/jp2uc.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/ctype/jp2uc.c,v
retrieving revision 1.4
diff -u -p -r1.4 jp2uc.c
--- libc/ctype/jp2uc.c 24 Mar 2009 10:13:27 -0000 1.4
+++ libc/ctype/jp2uc.c 14 May 2009 08:30:59 -0000
@@ -38,14 +38,14 @@
#include "local.h"
#include "jp2uc.h"
+/* Japanese encoding types supported */
+#define JP_JIS 1
+#define JP_SJIS 2
+#define JP_EUCJP 3
+
wint_t
_DEFUN (__jp2uc, (c, type), wint_t c _AND int type)
{
-/* Under Cygwin, the incoming wide character is already given in UTF due
- to the requirements of the underlying OS. */
-#ifdef __CYGWIN__
- return c;
-#else
int index, adj;
unsigned char byte1, byte2;
wint_t ret;
@@ -145,7 +145,22 @@ _DEFUN (__jp2uc, (c, type), wint_t c _AN
}
return WEOF; +}
+
+wint_t
+_DEFUN (_jp2uc, (c), wint_t c)
+{
+/* Under Cygwin, the incoming wide character is already given in UTF due
+ to the requirements of the underlying OS. */
+#ifndef __CYGWIN__
+ if (!strcmp (__locale_charset (), "JIS"))
+ c = __jp2uc (c, JP_JIS);
+ else if (!strcmp (__locale_charset (), "SJIS"))
+ c = __jp2uc (c, JP_SJIS);
+ else if (!strcmp (__locale_charset (), "EUCJP"))
+ c = __jp2uc (c, JP_EUCJP);
#endif
+ return c;
}
#endif /* _MB_CAPABLE */
Index: libc/ctype/local.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/ctype/local.h,v
retrieving revision 1.2
diff -u -p -r1.2 local.h
--- libc/ctype/local.h 3 Mar 2009 09:28:45 -0000 1.2
+++ libc/ctype/local.h 14 May 2009 08:30:59 -0000
@@ -22,11 +22,6 @@
extern char *__locale_charset ();
-/* Japanese encoding types supported */
-#define JP_JIS 1
-#define JP_SJIS 2
-#define JP_EUCJP 3
-
/* internal function to translate JP to Unicode */
-wint_t _EXFUN (__jp2uc, (wint_t, int));
+wint_t _EXFUN (_jp2uc, (wint_t));
Index: libc/ctype/towlower.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/ctype/towlower.c,v
retrieving revision 1.6
diff -u -p -r1.6 towlower.c
--- libc/ctype/towlower.c 24 Mar 2009 10:13:27 -0000 1.6
+++ libc/ctype/towlower.c 14 May 2009 08:30:59 -0000
@@ -70,13 +70,7 @@ wint_t
_DEFUN(towlower,(c), wint_t c)
{
#ifdef _MB_CAPABLE
- if (!strcmp (__locale_charset (), "JIS"))
- c = __jp2uc (c, JP_JIS);
- else if (!strcmp (__locale_charset (), "SJIS"))
- c = __jp2uc (c, JP_SJIS);
- else if (!strcmp (__locale_charset (), "EUCJP"))
- c = __jp2uc (c, JP_EUCJP);
-
+ c = _jp2uc (c);
if (c < 0x100)
{
if ((c >= 0x0041 && c <= 0x005a) ||
Index: libc/ctype/towupper.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/ctype/towupper.c,v
retrieving revision 1.6
diff -u -p -r1.6 towupper.c
--- libc/ctype/towupper.c 24 Mar 2009 10:13:27 -0000 1.6
+++ libc/ctype/towupper.c 14 May 2009 08:30:59 -0000
@@ -70,13 +70,7 @@ wint_t
_DEFUN(towupper,(c), wint_t c)
{
#ifdef _MB_CAPABLE
- if (!strcmp (__locale_charset (), "JIS"))
- c = __jp2uc (c, JP_JIS);
- else if (!strcmp (__locale_charset (), "SJIS"))
- c = __jp2uc (c, JP_SJIS);
- else if (!strcmp (__locale_charset (), "EUCJP"))
- c = __jp2uc (c, JP_EUCJP);
-
+ c = _jp2uc (c);
if (c < 0x100)
{
if (c == 0x00b5)




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]