|
Packit |
ae235b |
/*************************************************
|
|
Packit |
ae235b |
* Perl-Compatible Regular Expressions *
|
|
Packit |
ae235b |
*************************************************/
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* PCRE is a library of functions to support regular expressions whose syntax
|
|
Packit |
ae235b |
and semantics are as close as possible to those of the Perl 5 language.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
Written by Philip Hazel
|
|
Packit |
ae235b |
Copyright (c) 1997-2012 University of Cambridge
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
-----------------------------------------------------------------------------
|
|
Packit |
ae235b |
Redistribution and use in source and binary forms, with or without
|
|
Packit |
ae235b |
modification, are permitted provided that the following conditions are met:
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
* Redistributions of source code must retain the above copyright notice,
|
|
Packit |
ae235b |
this list of conditions and the following disclaimer.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
* Redistributions in binary form must reproduce the above copyright
|
|
Packit |
ae235b |
notice, this list of conditions and the following disclaimer in the
|
|
Packit |
ae235b |
documentation and/or other materials provided with the distribution.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
* Neither the name of the University of Cambridge nor the names of its
|
|
Packit |
ae235b |
contributors may be used to endorse or promote products derived from
|
|
Packit |
ae235b |
this software without specific prior written permission.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit |
ae235b |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
ae235b |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit |
ae235b |
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
Packit |
ae235b |
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
Packit |
ae235b |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
Packit |
ae235b |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
Packit |
ae235b |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
Packit |
ae235b |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
Packit |
ae235b |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
Packit |
ae235b |
POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
ae235b |
-----------------------------------------------------------------------------
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* This file contains a private PCRE function that converts an ordinal
|
|
Packit |
ae235b |
character value into a UTF8 string. */
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
#include "config.h"
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
#include "pcre_internal.h"
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/*************************************************
|
|
Packit |
ae235b |
* Convert character value to UTF-8 *
|
|
Packit |
ae235b |
*************************************************/
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* This function takes an integer value in the range 0 - 0x10ffff
|
|
Packit |
ae235b |
and encodes it as a UTF-8 character in 1 to 6 pcre_uchars.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
Arguments:
|
|
Packit |
ae235b |
cvalue the character value
|
|
Packit |
ae235b |
buffer pointer to buffer for result - at least 6 pcre_uchars long
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
Returns: number of characters placed in the buffer
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
int
|
|
Packit |
ae235b |
PRIV(ord2utf)(pcre_uint32 cvalue, pcre_uchar *buffer)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
#ifdef SUPPORT_UTF
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
int i, j;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* Checking invalid cvalue character, encoded as invalid UTF-16 character.
|
|
Packit |
ae235b |
Should never happen in practice. */
|
|
Packit |
ae235b |
if ((cvalue & 0xf800) == 0xd800 || cvalue >= 0x110000)
|
|
Packit |
ae235b |
cvalue = 0xfffe;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
for (i = 0; i < PRIV(utf8_table1_size); i++)
|
|
Packit |
ae235b |
if ((int)cvalue <= PRIV(utf8_table1)[i]) break;
|
|
Packit |
ae235b |
buffer += i;
|
|
Packit |
ae235b |
for (j = i; j > 0; j--)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
*buffer-- = 0x80 | (cvalue & 0x3f);
|
|
Packit |
ae235b |
cvalue >>= 6;
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
*buffer = PRIV(utf8_table2)[i] | cvalue;
|
|
Packit |
ae235b |
return i + 1;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
#else
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
(void)(cvalue); /* Keep compiler happy; this function won't ever be */
|
|
Packit |
ae235b |
(void)(buffer); /* called when SUPPORT_UTF is not defined. */
|
|
Packit |
ae235b |
return 0;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
#endif
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* End of pcre_ord2utf8.c */
|