[Rd] problem gsub in the locale of CP932 and SJIS (PR#9751)

nakama at ki.rim.or.jp nakama at ki.rim.or.jp
Sun Jun 24 15:46:53 CEST 2007


Full_Name: Ei-ji Nakama
Version: R-2.5.0
OS: any
Submission from: (NULL) (219.117.236.5)


problem by operation of gsub in the locale of CP932 and SJIS.
The inconvenient character code which used 0x5c after the first byte.

--- R-2.5.0.orig/src/main/character.c   2007-04-03 11:05:05.000000000 +0900
+++ R-2.5.0/src/main/character.c        2007-06-24 22:31:06.000000000 +0900
@@ -986,6 +986,17 @@
     char *p = repl;
     n = strlen(repl) - (regmatch[0].rm_eo - regmatch[0].rm_so);
     while (*p) {
+#ifdef  SUPPORT_MBCS
+       if(mbcslocale){
+           int clen;
+           mbstate_t mb_st;
+           mbs_init(&mb_st);
+           if((clen = Mbrtowc(NULL, p, MB_CUR_MAX, &mb_st)) > 1){
+               p+=clen;
+               continue;
+           }
+       }
+#endif
        if (*p == '\\') {
            if ('1' <= p[1] && p[1] <= '9') {
                k = p[1] - '0';
@@ -1014,6 +1025,18 @@
     int i, k;
     char *p = repl, *t = target;
     while (*p) {
+#ifdef  SUPPORT_MBCS
+       if(mbcslocale){
+           int clen;
+           mbstate_t mb_st;
+           mbs_init(&mb_st);
+           if((clen = Mbrtowc(NULL, p, MB_CUR_MAX, &mb_st)) > 1){
+               for ( i=0; i<clen; i++)
+                   *t++ = *p++;
+               continue;
+           }
+       }
+#endif
        if (*p == '\\') {
            if ('1' <= p[1] && p[1] <= '9') {
                k = p[1] - '0';



More information about the R-devel mailing list