[Pcre-svn] [763] code/branches/pcre16: string utilities adde…

Startseite
Nachricht löschen
Autor: Subversion repository
Datum:  
To: pcre-svn
Betreff: [Pcre-svn] [763] code/branches/pcre16: string utilities added
Revision: 763
          http://vcs.pcre.org/viewvc?view=rev&revision=763
Author:   zherczeg
Date:     2011-11-22 21:46:22 +0000 (Tue, 22 Nov 2011)


Log Message:
-----------
string utilities added

Modified Paths:
--------------
    code/branches/pcre16/Makefile.am
    code/branches/pcre16/pcre.h.in
    code/branches/pcre16/pcre16_valid_utf16.c
    code/branches/pcre16/pcre_compile.c
    code/branches/pcre16/pcre_exec.c
    code/branches/pcre16/pcre_internal.h
    code/branches/pcre16/pcre_jit_compile.c


Added Paths:
-----------
    code/branches/pcre16/pcre_str_utils.c


Modified: code/branches/pcre16/Makefile.am
===================================================================
--- code/branches/pcre16/Makefile.am    2011-11-22 13:36:51 UTC (rev 762)
+++ code/branches/pcre16/Makefile.am    2011-11-22 21:46:22 UTC (rev 763)
@@ -189,6 +189,7 @@
   pcre_newline.c \
   pcre_ord2utf8.c \
   pcre_refcount.c \
+  pcre_str_utils.c \
   pcre_study.c \
   pcre_tables.c \
   pcre_try_flipped.c \
@@ -208,6 +209,7 @@
 if WITH_PCRE16
 lib_LTLIBRARIES += libpcre16.la
 libpcre16_la_SOURCES = \
+  pcre_str_utils.c \
   pcre16_compile.c \
   pcre16_convert_utf16.c \
   pcre16_valid_utf16.c


Modified: code/branches/pcre16/pcre.h.in
===================================================================
--- code/branches/pcre16/pcre.h.in    2011-11-22 13:36:51 UTC (rev 762)
+++ code/branches/pcre16/pcre.h.in    2011-11-22 21:46:22 UTC (rev 763)
@@ -350,7 +350,7 @@
                   const unsigned char *);
 PCRE_EXP_DECL pcre *pcre_compile2(const char *, int, int *, const char **,
                   int *, const unsigned char *);
-PCRE_EXP_DECL pcre *pcre16_compile2(PCRE_SPTR16, int, int *, const short **,
+PCRE_EXP_DECL pcre *pcre16_compile2(PCRE_SPTR16, int, int *, const char **,
                   int *, const unsigned char *);
 PCRE_EXP_DECL int  pcre_config(int, void *);
 PCRE_EXP_DECL int  pcre_copy_named_substring(const pcre *, const char *,


Modified: code/branches/pcre16/pcre16_valid_utf16.c
===================================================================
--- code/branches/pcre16/pcre16_valid_utf16.c    2011-11-22 13:36:51 UTC (rev 762)
+++ code/branches/pcre16/pcre16_valid_utf16.c    2011-11-22 21:46:22 UTC (rev 763)
@@ -78,10 +78,10 @@
 */


int
-_pcre16_valid_utf16(USPTR string, int length, int *erroroffset)
+_pcre16_valid_utf16(PCRE_PUCHAR string, int length, int *erroroffset)
{
#ifdef SUPPORT_UTF16
-register USPTR p;
+register PCRE_PUCHAR p;
register uschar c;

if (length < 0)

Modified: code/branches/pcre16/pcre_compile.c
===================================================================
--- code/branches/pcre16/pcre_compile.c    2011-11-22 13:36:51 UTC (rev 762)
+++ code/branches/pcre16/pcre_compile.c    2011-11-22 21:46:22 UTC (rev 763)
@@ -1072,7 +1072,7 @@
 {
 int c, i, bot, top;
 const pcre_uchar *ptr = *ptrptr;
-char name[32];
+pcre_uchar name[32];


 c = *(++ptr);
 if (c == 0) goto ERROR_RETURN;
@@ -1118,7 +1118,7 @@
 while (bot < top)
   {
   i = (bot + top) >> 1;
-  c = strcmp(name, _pcre_utt_names + _pcre_utt[i].name_offset);
+  c = STRCMP_UC_C8(name, _pcre_utt_names + _pcre_utt[i].name_offset);
   if (c == 0)
     {
     *dptr = _pcre_utt[i].value;
@@ -1324,7 +1324,7 @@
       thisname = ptr;
       while (*ptr != term) ptr++;
       if (name != NULL && lorn == ptr - thisname &&
-          strncmp((const char *)name, (const char *)thisname, lorn) == 0)
+          STRNCMP_UC_UC(name, thisname, lorn) == 0)
         return *count;
       term++;
       }
@@ -1367,7 +1367,7 @@
         {
         if (ptr[2] == CHAR_E)
           ptr+= 2;
-        else if (strncmp((const char *)ptr+2,
+        else if (STRNCMP_UC_C8(ptr + 2,
                  STR_Q STR_BACKSLASH STR_E, 3) == 0)
           ptr += 4;
         else
@@ -2579,7 +2579,7 @@
 while (posix_name_lengths[yield] != 0)
   {
   if (len == posix_name_lengths[yield] &&
-    strncmp((const char *)ptr, pn, len) == 0) return yield;
+    STRNCMP_UC_C8(ptr, pn, len) == 0) return yield;
   pn += posix_name_lengths[yield] + 1;
   yield++;
   }
@@ -2915,7 +2915,7 @@
 /* If the next thing is itself optional, we have to give up. */


 if (*ptr == CHAR_ASTERISK || *ptr == CHAR_QUESTION_MARK ||
-  strncmp((char *)ptr, STR_LEFT_CURLY_BRACKET STR_0 STR_COMMA, 3) == 0)
+  STRNCMP_UC_C8(ptr, STR_LEFT_CURLY_BRACKET STR_0 STR_COMMA, 3) == 0)
     return FALSE;


 /* Now compare the next item with the previous opcode. First, handle cases when
@@ -3177,7 +3177,7 @@
       to the original \d etc. At this point, ptr will point to a zero byte. */


       if (*ptr == CHAR_ASTERISK || *ptr == CHAR_QUESTION_MARK ||
-        strncmp((char *)ptr, STR_LEFT_CURLY_BRACKET STR_0 STR_COMMA, 3) == 0)
+        STRNCMP_UC_C8(ptr, STR_LEFT_CURLY_BRACKET STR_0 STR_COMMA, 3) == 0)
           return FALSE;


       /* Do the property check. */
@@ -3617,7 +3617,7 @@
         {
         if (ptr[1] == CHAR_E)
           ptr++;
-        else if (strncmp((const char *)ptr+1,
+        else if (STRNCMP_UC_C8(ptr + 1,
                           STR_Q STR_BACKSLASH STR_E, 3) == 0)
           ptr += 3;
         else
@@ -5295,7 +5295,7 @@
       for (i = 0; i < verbcount; i++)
         {
         if (namelen == verbs[i].len &&
-            strncmp((char *)name, vn, namelen) == 0)
+            STRNCMP_UC_C8(name, vn, namelen) == 0)
           {
           /* Check for open captures before ACCEPT and convert it to
           ASSERT_ACCEPT if in an assertion. */
@@ -5519,7 +5519,7 @@
         slot = cd->name_table;
         for (i = 0; i < cd->names_found; i++)
           {
-          if (strncmp((char *)name, (char *)slot+2, namelen) == 0) break;
+          if (STRNCMP_UC_UC(name, slot+IMM2_SIZE, namelen) == 0) break;
           slot += cd->name_entry_size;
           }


@@ -5576,7 +5576,7 @@
         /* Similarly, check for the (?(DEFINE) "condition", which is always
         false. */


-        else if (namelen == 6 && strncmp((char *)name, STRING_DEFINE, 6) == 0)
+        else if (namelen == 6 && STRNCMP_UC_C8(name, STRING_DEFINE, 6) == 0)
           {
           code[1+LINK_SIZE] = OP_DEF;
           skipbytes = 1;
@@ -5894,7 +5894,7 @@
           slot = cd->name_table;
           for (i = 0; i < cd->names_found; i++)
             {
-            if (strncmp((char *)name, (char *)slot+2, namelen) == 0 &&
+            if (STRNCMP_UC_UC(name, slot+IMM2_SIZE, namelen) == 0 &&
                 slot[2+namelen] == 0)
               break;
             slot += cd->name_entry_size;
@@ -7348,27 +7348,27 @@
   int newnl = 0;
   int newbsr = 0;


-  if (strncmp((char *)(ptr+skipatstart+2), STRING_UTF8_RIGHTPAR, 5) == 0)
+  if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF8_RIGHTPAR, 5) == 0)
     { skipatstart += 7; options |= PCRE_UTF8; continue; }
-  else if (strncmp((char *)(ptr+skipatstart+2), STRING_UCP_RIGHTPAR, 4) == 0)
+  else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UCP_RIGHTPAR, 4) == 0)
     { skipatstart += 6; options |= PCRE_UCP; continue; }
-  else if (strncmp((char *)(ptr+skipatstart+2), STRING_NO_START_OPT_RIGHTPAR, 13) == 0)
+  else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_NO_START_OPT_RIGHTPAR, 13) == 0)
     { skipatstart += 15; options |= PCRE_NO_START_OPTIMIZE; continue; }


-  if (strncmp((char *)(ptr+skipatstart+2), STRING_CR_RIGHTPAR, 3) == 0)
+  if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_CR_RIGHTPAR, 3) == 0)
     { skipatstart += 5; newnl = PCRE_NEWLINE_CR; }
-  else if (strncmp((char *)(ptr+skipatstart+2), STRING_LF_RIGHTPAR, 3)  == 0)
+  else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_LF_RIGHTPAR, 3)  == 0)
     { skipatstart += 5; newnl = PCRE_NEWLINE_LF; }
-  else if (strncmp((char *)(ptr+skipatstart+2), STRING_CRLF_RIGHTPAR, 5)  == 0)
+  else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_CRLF_RIGHTPAR, 5)  == 0)
     { skipatstart += 7; newnl = PCRE_NEWLINE_CR + PCRE_NEWLINE_LF; }
-  else if (strncmp((char *)(ptr+skipatstart+2), STRING_ANY_RIGHTPAR, 4) == 0)
+  else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_ANY_RIGHTPAR, 4) == 0)
     { skipatstart += 6; newnl = PCRE_NEWLINE_ANY; }
-  else if (strncmp((char *)(ptr+skipatstart+2), STRING_ANYCRLF_RIGHTPAR, 8) == 0)
+  else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_ANYCRLF_RIGHTPAR, 8) == 0)
     { skipatstart += 10; newnl = PCRE_NEWLINE_ANYCRLF; }


-  else if (strncmp((char *)(ptr+skipatstart+2), STRING_BSR_ANYCRLF_RIGHTPAR, 12) == 0)
+  else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_BSR_ANYCRLF_RIGHTPAR, 12) == 0)
     { skipatstart += 14; newbsr = PCRE_BSR_ANYCRLF; }
-  else if (strncmp((char *)(ptr+skipatstart+2), STRING_BSR_UNICODE_RIGHTPAR, 12) == 0)
+  else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_BSR_UNICODE_RIGHTPAR, 12) == 0)
     { skipatstart += 14; newbsr = PCRE_BSR_UNICODE; }


if (newnl != 0)
@@ -7486,7 +7486,7 @@
cd->start_code = cworkspace;
cd->hwm = cworkspace;
cd->start_pattern = (const pcre_uchar *)pattern;
-cd->end_pattern = (const pcre_uchar *)(pattern + strlen(pattern));
+cd->end_pattern = (const pcre_uchar *)(pattern + STRLEN_UC(pattern));
cd->req_varyopt = 0;
cd->external_options = options;
cd->external_flags = 0;

Modified: code/branches/pcre16/pcre_exec.c
===================================================================
--- code/branches/pcre16/pcre_exec.c    2011-11-22 13:36:51 UTC (rev 762)
+++ code/branches/pcre16/pcre_exec.c    2011-11-22 21:46:22 UTC (rev 763)
@@ -713,7 +713,7 @@
     unaltered. */


     if (rrc == MATCH_SKIP_ARG &&
-        strcmp((char *)markptr, (char *)(md->start_match_ptr)) == 0)
+        STRCMP_UC_UC(markptr, md->start_match_ptr) == 0)
       {
       md->start_match_ptr = eptr;
       RRETURN(MATCH_SKIP);
@@ -1279,7 +1279,7 @@
             while (slotB > md->name_table)
               {
               slotB -= md->name_entry_size;
-              if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
+              if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
                 {
                 condition = GET2(slotB, 0) == md->recursive->group_num;
                 if (condition) break;
@@ -1295,7 +1295,7 @@
               for (i++; i < md->name_count; i++)
                 {
                 slotB += md->name_entry_size;
-                if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
+                if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
                   {
                   condition = GET2(slotB, 0) == md->recursive->group_num;
                   if (condition) break;
@@ -1343,7 +1343,7 @@
           while (slotB > md->name_table)
             {
             slotB -= md->name_entry_size;
-            if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
+            if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
               {
               offset = GET2(slotB, 0) << 1;
               condition = offset < offset_top &&
@@ -1361,7 +1361,7 @@
             for (i++; i < md->name_count; i++)
               {
               slotB += md->name_entry_size;
-              if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
+              if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
                 {
                 offset = GET2(slotB, 0) << 1;
                 condition = offset < offset_top &&


Modified: code/branches/pcre16/pcre_internal.h
===================================================================
--- code/branches/pcre16/pcre_internal.h    2011-11-22 13:36:51 UTC (rev 762)
+++ code/branches/pcre16/pcre_internal.h    2011-11-22 21:46:22 UTC (rev 763)
@@ -51,6 +51,11 @@
 #define PCRE_DEBUG
 #endif


+/* PCRE is compiled as an 8 bit library if it is not requested otherwise. */
+#ifndef COMPILE_PCRE16
+#define COMPILE_PCRE8
+#endif
+
/* We do not support both EBCDIC and UTF-8/16 at the same time. The "configure"
script prevents both being selected, but not everybody uses "configure". */

@@ -222,7 +227,7 @@
pcre.h(.in) and disable (comment out) this message. */
#error Warning: PCRE_SCHAR16 is not a 16 bit data type.
#endif
-typedef pcre_uint16 uschar;
+typedef pcre_uint16 pcre_uchar;
#endif

/* This is an unsigned int value that no character can ever have. UTF-8
@@ -407,6 +412,10 @@
offsets changes. There are used for repeat counts and for other things such as
capturing parenthesis numbers in back references. */

+#ifdef COMPILE_PCRE8
+
+#define IMM2_SIZE 2
+
#define PUT2(a,n,d) \
a[n] = (d) >> 8; \
a[(n)+1] = (d) & 255
@@ -414,9 +423,23 @@
#define GET2(a,n) \
(((a)[n] << 8) | (a)[(n)+1])

-#define PUT2INC(a,n,d) PUT2(a,n,d), a += 2

+#elif defined(COMPILE_PCRE16)

+#define IMM2_SIZE 1
+
+#define PUT2(a,n,d) \
+ a[n] = d
+
+#define GET2(a,n) \
+ a[n]
+
+#else
+#error Unsupported compiling mode
+#endif /* COMPILE_PCRE8 */
+
+#define PUT2INC(a,n,d) PUT2(a,n,d), a += IMM2_SIZE
+
/* When UTF-8 encoding is being used, a character is no longer just a single
byte. The macros for character handling generate simple sequences when used in
byte-mode, and more complicated ones for UTF-8 characters. GETCHARLENTEST is
@@ -1943,6 +1966,43 @@
one of the exported public functions. They have to be "external" in the C
sense, but are not part of the PCRE public API. */

+/* String comparison functions. */
+#ifdef COMPILE_PCRE8
+
+#define STRCMP_UC_UC(str1, str2) \
+  strcmp((char *)(str1), (char *)(str2))
+#define STRCMP_UC_C8(str1, str2) \
+  strcmp((char *)(str1), (str2))
+#define STRNCMP_UC_UC(str1, str2, num) \
+  strncmp((char *)(str1), (char *)(str2), (num))
+#define STRNCMP_UC_C8(str1, str2, num) \
+  strncmp((char *)(str1), (str2), (num))
+#define STRLEN_UC(str) strlen(str)
+
+#else
+
+extern int               _pcre_strcmp_uc_uc(const pcre_uchar *,
+                           const pcre_uchar *);
+extern int               _pcre_strcmp_uc_c8(const pcre_uchar *,
+                           const char *);
+extern int               _pcre_strncmp_uc_uc(const pcre_uchar *,
+                           const pcre_uchar *, unsigned int num);
+extern int               _pcre_strncmp_uc_c8(const pcre_uchar *,
+                           const char *, unsigned int num);
+extern unsigned int      _pcre_strlen_uc(const pcre_uchar *str);
+
+#define STRCMP_UC_UC(str1, str2) \
+  _pcre_strcmp_uc_uc((str1), (str2))
+#define STRCMP_UC_C8(str1, str2) \
+  _pcre_strcmp_uc_c8((str1), (str2))
+#define STRNCMP_UC_UC(str1, str2, num) \
+  _pcre_strncmp_uc_uc((str1), (str2), (num))
+#define STRNCMP_UC_C8(str1, str2, num) \
+  _pcre_strncmp_uc_c8((str1), (str2), (num))
+#define STRLEN_UC(str) _pcre_strlen_uc(str)
+
+#endif /* COMPILE_PCRE8 */
+
 extern const pcre_uchar *_pcre_find_bracket(const pcre_uchar *, BOOL, int);
 extern BOOL              _pcre_is_newline(PCRE_PUCHAR, int, PCRE_PUCHAR,
                            int *, BOOL);


Modified: code/branches/pcre16/pcre_jit_compile.c
===================================================================
--- code/branches/pcre16/pcre_jit_compile.c    2011-11-22 13:36:51 UTC (rev 762)
+++ code/branches/pcre16/pcre_jit_compile.c    2011-11-22 21:46:22 UTC (rev 763)
@@ -3832,7 +3832,7 @@
   while (slotB > name_table)
     {
     slotB -= name_entry_size;
-    if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
+    if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
       {
       condition = locals[GET2(slotB, 0) << 1] != no_capture;
       if (condition) break;
@@ -3847,7 +3847,7 @@
     for (i++; i < name_count; i++)
       {
       slotB += name_entry_size;
-      if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
+      if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
         {
         condition = locals[GET2(slotB, 0) << 1] != no_capture;
         if (condition) break;
@@ -3885,7 +3885,7 @@
   while (slotB > name_table)
     {
     slotB -= name_entry_size;
-    if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
+    if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
       {
       condition = GET2(slotB, 0) == group_num;
       if (condition) break;
@@ -3900,7 +3900,7 @@
     for (i++; i < name_count; i++)
       {
       slotB += name_entry_size;
-      if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
+      if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
         {
         condition = GET2(slotB, 0) == group_num;
         if (condition) break;


Added: code/branches/pcre16/pcre_str_utils.c
===================================================================
--- code/branches/pcre16/pcre_str_utils.c                            (rev 0)
+++ code/branches/pcre16/pcre_str_utils.c    2011-11-22 21:46:22 UTC (rev 763)
@@ -0,0 +1,168 @@
+/*************************************************
+*      Perl-Compatible Regular Expressions       *
+*************************************************/
+
+/* PCRE is a library of functions to support regular expressions whose syntax
+and semantics are as close as possible to those of the Perl 5 language.
+
+                       Written by Philip Hazel
+           Copyright (c) 1997-2010 University of Cambridge
+
+-----------------------------------------------------------------------------
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+
+    * Neither the name of the University of Cambridge nor the names of its
+      contributors may be used to endorse or promote products derived from
+      this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+-----------------------------------------------------------------------------
+*/
+
+
+/* This module contains an internal function that is used to match an extended
+class. It is used by both pcre_exec() and pcre_def_exec(). */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "pcre_internal.h"
+
+#ifndef COMPILE_PCRE8
+
+/*************************************************
+*           Compare string utilities             *
+*************************************************/
+
+/* The following two functions compares two strings. Basically an strcmp
+for non 8 bit characters.
+
+Arguments:
+  str1        first string
+  str2        second string
+
+Returns:      0 if both string are equal (like strcmp), 1 otherwise
+*/
+
+int
+_pcre_strcmp_uc_uc(const pcre_uchar *str1, const pcre_uchar *str2)
+{
+pcre_uchar c1;
+pcre_uchar c2;
+
+while (*str1 != '\0' || *str2 != '\0')
+  {
+  c1 = *str1++;
+  c2 = *str2++;
+  if (c1 != c2)
+    return ((c1 > c2) << 1) - 1;
+  }
+/* Both length and characters must be equal. */
+return 0;
+}
+
+int
+_pcre_strcmp_uc_c8(const pcre_uchar *str1, const char *str2)
+{
+const pcre_uint8 *ustr2 = (pcre_uint8 *)str2;
+pcre_uchar c1;
+pcre_uchar c2;
+
+while (*str1 != '\0' || *ustr2 != '\0')
+  {
+  c1 = *str1++;
+  c2 = (pcre_uchar)*ustr2++;
+  if (c1 != c2)
+    return ((c1 > c2) << 1) - 1;
+  }
+/* Both length and characters must be equal. */
+return 0;
+}
+
+/* The following two functions compares two, fixed length
+strings. Basically an strncmp for non 8 bit characters.
+
+Arguments:
+  str1        first string
+  str2        second string
+  num         size of the string
+
+Returns:      0 if both string are equal (like strcmp), 1 otherwise
+*/
+
+int
+_pcre_strncmp_uc_uc(const pcre_uchar *str1, const pcre_uchar *str2, unsigned int num)
+{
+pcre_uchar c1;
+pcre_uchar c2;
+
+while (num-- > 0)
+  {
+  c1 = *str1++;
+  c2 = *str2++;
+  if (c1 != c2)
+    return ((c1 > c2) << 1) - 1;
+  }
+/* Both length and characters must be equal. */
+return 0;
+}
+
+int
+_pcre_strncmp_uc_c8(const pcre_uchar *str1, const char *str2, unsigned int num)
+{
+const pcre_uint8 *ustr2 = (pcre_uint8 *)str2;
+pcre_uchar c1;
+pcre_uchar c2;
+
+while (num-- > 0)
+  {
+  c1 = *str1++;
+  c2 = (pcre_uchar)*ustr2++;
+  if (c1 != c2)
+    return ((c1 > c2) << 1) - 1;
+  }
+/* Both length and characters must be equal. */
+return 0;
+}
+
+/* The following function returns with the length of
+a zero terminated string. Basically an strlen for non 8 bit characters.
+
+Arguments:
+  str         string
+
+Returns:      length of the string
+*/
+
+unsigned int
+_pcre_strlen_uc(const pcre_uchar *str)
+{
+unsigned int len = 0;
+while (*str++ != 0)
+  len++;
+return len;
+}
+
+#endif /* COMPILE_PCRE8 */
+
+/* End of pcre_str_utils.c */