1 #define HAVE_CONFIG_H
2 /*************************************************
3 *      Perl-Compatible Regular Expressions       *
4 *************************************************/
5 
6 /* PCRE is a library of functions to support regular expressions whose syntax
7 and semantics are as close as possible to those of the Perl 5 language.
8 
9                        Written by Philip Hazel
10            Copyright (c) 1997-2012 University of Cambridge
11 
12 -----------------------------------------------------------------------------
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 
16     * Redistributions of source code must retain the above copyright notice,
17       this list of conditions and the following disclaimer.
18 
19     * Redistributions in binary form must reproduce the above copyright
20       notice, this list of conditions and the following disclaimer in the
21       documentation and/or other materials provided with the distribution.
22 
23     * Neither the name of the University of Cambridge nor the names of its
24       contributors may be used to endorse or promote products derived from
25       this software without specific prior written permission.
26 
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 POSSIBILITY OF SUCH DAMAGE.
38 -----------------------------------------------------------------------------
39 */
40 
41 
42 /* This file contains a private PCRE function that converts an ordinal
43 character value into a UTF8 string. */
44 
45 #ifdef HAVE_CONFIG_H
46 #include "config.h"
47 #endif
48 
49 #define COMPILE_PCRE8
50 
51 #include "pcre_internal.h"
52 
53 /*************************************************
54 *       Convert character value to UTF-8         *
55 *************************************************/
56 
57 /* This function takes an integer value in the range 0 - 0x10ffff
58 and encodes it as a UTF-8 character in 1 to 4 pcre_uchars.
59 
60 Arguments:
61   cvalue     the character value
62   buffer     pointer to buffer for result - at least 6 pcre_uchars long
63 
64 Returns:     number of characters placed in the buffer
65 */
66 
67 unsigned
68 int
PRIV(ord2utf)69 PRIV(ord2utf)(pcre_uint32 cvalue, pcre_uchar *buffer)
70 {
71 #ifdef SUPPORT_UTF
72 
73 register int i, j;
74 
75 for (i = 0; i < PRIV(utf8_table1_size); i++)
76   if ((int)cvalue <= PRIV(utf8_table1)[i]) break;
77 buffer += i;
78 for (j = i; j > 0; j--)
79  {
80  *buffer-- = 0x80 | (cvalue & 0x3f);
81  cvalue >>= 6;
82  }
83 *buffer = PRIV(utf8_table2)[i] | cvalue;
84 return i + 1;
85 
86 #else
87 
88 (void)(cvalue);  /* Keep compiler happy; this function won't ever be */
89 (void)(buffer);  /* called when SUPPORT_UTF is not defined. */
90 return 0;
91 
92 #endif
93 }
94 
95 /* End of pcre_ord2utf8.c */
96