[Pcre-svn] [1198] code/trunk/pcre_internal.h: Rewrite 32-bit…

Startseite
Nachricht löschen
Autor: Subversion repository
Datum:  
To: pcre-svn
Betreff: [Pcre-svn] [1198] code/trunk/pcre_internal.h: Rewrite 32-bit GETCHAR* macros
Revision: 1198
          http://vcs.pcre.org/viewvc?view=rev&revision=1198
Author:   chpe
Date:     2012-11-01 19:23:35 +0000 (Thu, 01 Nov 2012)


Log Message:
-----------
Rewrite 32-bit GETCHAR* macros

Move the high-bit masking to a dedicated macro, and use that in the GETCHAR*
and RAWUCHAR* macros.

Modified Paths:
--------------
    code/trunk/pcre_internal.h


Modified: code/trunk/pcre_internal.h
===================================================================
--- code/trunk/pcre_internal.h    2012-11-01 19:23:27 UTC (rev 1197)
+++ code/trunk/pcre_internal.h    2012-11-01 19:23:35 UTC (rev 1198)
@@ -934,31 +934,41 @@


#define UTF32_MASK (0x1fffffu)

+/* Base macro to pick up an UTF-32 character out of a uint32 */
+
+#define MASKHIGHBITS(c) ((c) & UTF32_MASK)
+
+/* Base macro to pick up an UTF-32 character, not advancing the pointer */
+
+#define GETUTF32(eptr) (MASKHIGHBITS(*(eptr)))
+
+/* Base macro to pick up an UTF-32 character, advancing the pointer */
+
+#define GETUTF32INC(eptr) (MASKHIGHBITS(*((eptr)++)))
+
/* Get the next UTF-32 character, not advancing the pointer. This is called when
we know we are in UTF-32 mode. */

#define GETCHAR(c, eptr) \
- c = (*eptr) & UTF32_MASK;
+ c = GETUTF32(eptr);

/* Get the next UTF-32 character, testing for UTF-32 mode, and not advancing the
pointer. */

#define GETCHARTEST(c, eptr) \
- c = *eptr; \
- if (utf) c &= UTF32_MASK;
+ c = (utf ? GETUTF32(eptr) : *(eptr));

/* Get the next UTF-32 character, advancing the pointer. This is called when we
know we are in UTF-32 mode. */

#define GETCHARINC(c, eptr) \
- c = (*eptr++) & UTF32_MASK;
+ c = GETUTF32INC(eptr);

/* Get the next character, testing for UTF-32 mode, and advancing the pointer.
This is called when we don't know if we are in UTF-32 mode. */

#define GETCHARINCTEST(c, eptr) \
- c = *eptr++; \
- if (utf) c &= UTF32_MASK;
+ c = (utf ? GETUTF32INC(eptr) : *((eptr)++));

/* Get the next UTF-32 character, not advancing the pointer, not incrementing
length (since all UTF-32 is of length 1). This is called when we know we are in
@@ -978,25 +988,25 @@
we know we are in UTF mode. */

#define RAWUCHAR(eptr) \
- (*(eptr) & UTF32_MASK)
+ (MASKHIGHBITS(*(eptr)))

/* Returns the next uchar, advancing the pointer. This is called when
we know we are in UTF mode. */

#define RAWUCHARINC(eptr) \
- (*((eptr)++) & UTF32_MASK)
+ (MASKHIGHBITS(*((eptr)++)))

/* Returns the next uchar, testing for UTF mode, and not advancing the
pointer. */

#define RAWUCHARTEST(eptr) \
- (utf ? (*(eptr) & UTF32_MASK) : *(eptr))
+ (utf ? (MASKHIGHBITS(*(eptr))) : *(eptr))

/* Returns the next uchar, testing for UTF mode, advancing the
pointer. */

#define RAWUCHARINCTEST(eptr) \
- (utf ? (*((eptr)++) & UTF32_MASK) : *((eptr)++))
+ (utf ? (MASKHIGHBITS(*((eptr)++))) : *((eptr)++))

/* If the pointer is not at the start of a character, move it back until
it is. This is called only in UTF-32 mode - we don't put a test within the