/[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 1221 by ph10, Sun Nov 11 20:27:03 2012 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 45  character value into a UTF8 string. */ Line 45  character value into a UTF8 string. */
45  #include "config.h"  #include "config.h"
46  #endif  #endif
47    
48  #include "pcre_internal.h"  #define COMPILE_PCRE8
49    
50    #include "pcre_internal.h"
51    
52  /*************************************************  /*************************************************
53  *       Convert character value to UTF-8         *  *       Convert character value to UTF-8         *
54  *************************************************/  *************************************************/
55    
56  /* This function takes an integer value in the range 0 - 0x7fffffff  /* This function takes an integer value in the range 0 - 0x10ffff
57  and encodes it as a UTF-8 character in 0 to 6 bytes.  and encodes it as a UTF-8 character in 1 to 4 pcre_uchars.
58    
59  Arguments:  Arguments:
60    cvalue     the character value    cvalue     the character value
61    buffer     pointer to buffer for result - at least 6 bytes long    buffer     pointer to buffer for result - at least 6 pcre_uchars long
62    
63  Returns:     number of characters placed in the buffer  Returns:     number of characters placed in the buffer
64  */  */
65    
66    unsigned
67  int  int
68  _pcre_ord2utf8(int cvalue, uschar *buffer)  PRIV(ord2utf)(pcre_uint32 cvalue, pcre_uchar *buffer)
69  {  {
70  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
71    
72  register int i, j;  register int i, j;
73  for (i = 0; i < _pcre_utf8_table1_size; i++)  
74    if (cvalue <= _pcre_utf8_table1[i]) break;  for (i = 0; i < PRIV(utf8_table1_size); i++)
75      if ((int)cvalue <= PRIV(utf8_table1)[i]) break;
76  buffer += i;  buffer += i;
77  for (j = i; j > 0; j--)  for (j = i; j > 0; j--)
78   {   {
79   *buffer-- = 0x80 | (cvalue & 0x3f);   *buffer-- = 0x80 | (cvalue & 0x3f);
80   cvalue >>= 6;   cvalue >>= 6;
81   }   }
82  *buffer = _pcre_utf8_table2[i] | cvalue;  *buffer = PRIV(utf8_table2)[i] | cvalue;
83  return i + 1;  return i + 1;
84    
85  #else  #else
86    
87  (void)(cvalue);  /* Keep compiler happy; this function won't ever be */  (void)(cvalue);  /* Keep compiler happy; this function won't ever be */
88  (void)(buffer);  /* called when SUPPORT_UTF8 is not defined. */  (void)(buffer);  /* called when SUPPORT_UTF is not defined. */
89  return 0;  return 0;
90  #endif  
91    #endif
92  }  }
93    
94  /* End of pcre_ord2utf8.c */  /* End of pcre_ord2utf8.c */

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

  ViewVC Help
Powered by ViewVC 1.1.5