/[pcre]/code/trunk/pcre_ord2utf8.c
ViewVC logotype

Diff of /code/trunk/pcre_ord2utf8.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 369 by ph10, Sun Aug 24 16:53:47 2008 UTC revision 836 by ph10, Wed Dec 28 17:16:11 2011 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2008 University of Cambridge             Copyright (c) 1997-2012 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 52  character value into a UTF8 string. */ Line 52  character value into a UTF8 string. */
52  *       Convert character value to UTF-8         *  *       Convert character value to UTF-8         *
53  *************************************************/  *************************************************/
54    
55  /* This function takes an integer value in the range 0 - 0x7fffffff  /* This function takes an integer value in the range 0 - 0x10ffff
56  and encodes it as a UTF-8 character in 0 to 6 bytes.  and encodes it as a UTF-8 character in 1 to 6 pcre_uchars.
57    
58  Arguments:  Arguments:
59    cvalue     the character value    cvalue     the character value
60    buffer     pointer to buffer for result - at least 6 bytes long    buffer     pointer to buffer for result - at least 6 pcre_uchars long
61    
62  Returns:     number of characters placed in the buffer  Returns:     number of characters placed in the buffer
63  */  */
64    
65  int  int
66  _pcre_ord2utf8(int cvalue, uschar *buffer)  PRIV(ord2utf)(pcre_uint32 cvalue, pcre_uchar *buffer)
67  {  {
68  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
69    
70  register int i, j;  register int i, j;
71  for (i = 0; i < _pcre_utf8_table1_size; i++)  
72    if (cvalue <= _pcre_utf8_table1[i]) break;  /* Checking invalid cvalue character, encoded as invalid UTF-16 character.
73    Should never happen in practice. */
74    if ((cvalue & 0xf800) == 0xd800 || cvalue >= 0x110000)
75      cvalue = 0xfffe;
76    
77    for (i = 0; i < PRIV(utf8_table1_size); i++)
78      if (cvalue <= PRIV(utf8_table1)[i]) break;
79  buffer += i;  buffer += i;
80  for (j = i; j > 0; j--)  for (j = i; j > 0; j--)
81   {   {
82   *buffer-- = 0x80 | (cvalue & 0x3f);   *buffer-- = 0x80 | (cvalue & 0x3f);
83   cvalue >>= 6;   cvalue >>= 6;
84   }   }
85  *buffer = _pcre_utf8_table2[i] | cvalue;  *buffer = PRIV(utf8_table2)[i] | cvalue;
86  return i + 1;  return i + 1;
87    
88  #else  #else
89    
90  (void)(cvalue);  /* Keep compiler happy; this function won't ever be */  (void)(cvalue);  /* Keep compiler happy; this function won't ever be */
91  (void)(buffer);  /* called when SUPPORT_UTF8 is not defined. */  (void)(buffer);  /* called when SUPPORT_UTF is not defined. */
92  return 0;  return 0;
93  #endif  
94    #endif
95  }  }
96    
97  /* End of pcre_ord2utf8.c */  /* End of pcre_ord2utf8.c */

Legend:
Removed from v.369  
changed lines
  Added in v.836

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12