*** ../vim-7.2.025/src/os_mswin.c	Sat Aug  9 18:29:28 2008
--- src/os_mswin.c	Wed Oct 22 18:39:31 2008
***************
*** 891,897 ****
  
  #if defined(FEAT_MBYTE) || defined(PROTO)
  /*
!  * Convert an UTF-8 string to UCS-2.
   * "instr[inlen]" is the input.  "inlen" is in bytes.
   * When "outstr" is NULL only return the number of UCS-2 words produced.
   * Otherwise "outstr" must be a buffer of sufficient size.
--- 891,897 ----
  
  #if defined(FEAT_MBYTE) || defined(PROTO)
  /*
!  * Convert an UTF-8 string to UCS-2(UTF-16 in fact).
   * "instr[inlen]" is the input.  "inlen" is in bytes.
   * When "outstr" is NULL only return the number of UCS-2 words produced.
   * Otherwise "outstr" must be a buffer of sufficient size.
***************
*** 904,909 ****
--- 904,910 ----
      char_u	*p = instr;
      int		todo = inlen;
      int		l;
+     int		ch;
  
      while (todo > 0)
      {
***************
*** 918,924 ****
  	}
  
  	if (outstr != NULL)
! 	    *outstr++ = utf_ptr2char(p);
  	++outlen;
  	p += l;
  	todo -= l;
--- 919,938 ----
  	}
  
  	if (outstr != NULL)
! 	{
! 	    ch = utf_ptr2char(p);
! 	    // Non-BMP character, encoding with surrogate pairs
! 	    if(ch > 0x10000)
! 	    {
! 		*outstr++ = 0xD7C0 + (ch >> 10);
! 		*outstr++ = (0xDC00 | ch & 0x3FF);
! 		++outlen;
! 	    }
! 	    else
! 	    {
! 		*outstr++ = ch;
! 	    }
! 	}
  	++outlen;
  	p += l;
  	todo -= l;
***************
*** 928,934 ****
  }
  
  /*
!  * Convert an UCS-2 string to UTF-8.
   * The input is "instr[inlen]" with "inlen" in number of ucs-2 words.
   * When "outstr" is NULL only return the required number of bytes.
   * Otherwise "outstr" must be a buffer of sufficient size.
--- 942,948 ----
  }
  
  /*
!  * Convert an UCS-2(UTF-16 in fact) string to UTF-8.
   * The input is "instr[inlen]" with "inlen" in number of ucs-2 words.
   * When "outstr" is NULL only return the required number of bytes.
   * Otherwise "outstr" must be a buffer of sufficient size.
***************
*** 941,956 ****
      int		todo = inlen;
      short_u	*p = instr;
      int		l;
  
      while (todo > 0)
      {
  	if (outstr != NULL)
  	{
! 	    l = utf_char2bytes(*p, outstr);
  	    outstr += l;
  	}
  	else
! 	    l = utf_char2len(*p);
  	++p;
  	outlen += l;
  	--todo;
--- 955,984 ----
      int		todo = inlen;
      short_u	*p = instr;
      int		l;
+     int		ch, ch2;
  
      while (todo > 0)
      {
+ 	ch = *p;
+ 	// surrogate pairs handling
+ 	if(ch > 0xD800 && ch < 0xDBFF)
+ 	{
+ 	    ch2 = *(p+1);
+ 	    if(ch2 > 0xDC00 && ch2 < 0xDFFF)
+ 	    {
+ 		ch = (ch - 0xD7C0) << 10;
+ 		ch += (ch2 & 0x3FF);
+ 		++p;
+ 		--todo;
+ 	    }
+ 	}
  	if (outstr != NULL)
  	{
! 	    l = utf_char2bytes(ch, outstr);
  	    outstr += l;
  	}
  	else
! 	    l = utf_char2len(ch);
  	++p;
  	outlen += l;
  	--todo;
***************
*** 1079,1085 ****
   */
  
  /*
!  * Convert "str" from 'encoding' to UCS-2.
   * Input in "str" with length "*lenp".  When "lenp" is NULL, use strlen().
   * Output is returned as an allocated string.  "*lenp" is set to the length of
   * the result.  A trailing NUL is always added.
--- 1107,1113 ----
   */
  
  /*
!  * Convert "str" from 'encoding' to UCS-2(maybe UTF-16).
   * Input in "str" with length "*lenp".  When "lenp" is NULL, use strlen().
   * Output is returned as an allocated string.  "*lenp" is set to the length of
   * the result.  A trailing NUL is always added.
***************
*** 1139,1145 ****
  }
  
  /*
!  * Convert an UCS-2 string to 'encoding'.
   * Input in "str" with length (counted in wide characters) "*lenp".  When
   * "lenp" is NULL, use wcslen().
   * Output is returned as an allocated string.  If "*lenp" is not NULL it is
--- 1167,1173 ----
  }
  
  /*
!  * Convert an UCS-2(maybe UTF-16) string to 'encoding'.
   * Input in "str" with length (counted in wide characters) "*lenp".  When
   * "lenp" is NULL, use wcslen().
   * Output is returned as an allocated string.  If "*lenp" is not NULL it is
