/[pcre]/code/branches/pcre16/pcre16_utf16_utils.c
ViewVC logotype

Diff of /code/branches/pcre16/pcre16_utf16_utils.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 782 by zherczeg, Sat Dec 3 23:58:37 2011 UTC revision 789 by zherczeg, Wed Dec 7 14:36:26 2011 UTC
# Line 51  strings to host byte order. */ Line 51  strings to host byte order. */
51    
52  #include "pcre_internal.h"  #include "pcre_internal.h"
53    
54    /*************************************************
55    *  Convert any UTF-16 string to host byte order  *
56    *************************************************/
57    
58    /* This function takes an UTF-16 string and converts
59    it to host byte order. The length can be explicitly set,
60    or autmatically detected for zero terminated strings.
61    BOMs can be kept or discarded during the conversion.
62    Conversion can be done in place (output == input).
63    
64    Arguments:
65      output     the output buffer, its size must be greater
66                 or equal than the input string
67      input      any UTF-16 string
68      length     the number of characters in the input string
69                 can be less than zero for zero terminated strings
70      keep_boms  for a non-zero value, the BOM (0xfeff) characters
71                 are copied as well
72    
73    Returns:     the number of characters placed into the output buffer,
74                 including the zero-terminator
75    */
76    
77  int  int
78  pcre16_utf16_to_host_byte_order(PCRE_SCHAR16 *output, PCRE_SPTR16 input, int length, int keep_boms)  pcre16_utf16_to_host_byte_order(PCRE_SCHAR16 *output, PCRE_SPTR16 input, int length, int keep_boms)
79  {  {
# Line 58  pcre16_utf16_to_host_byte_order(PCRE_SCH Line 81  pcre16_utf16_to_host_byte_order(PCRE_SCH
81  /* This function converts any UTF-16 string to host byte order and optionally removes  /* This function converts any UTF-16 string to host byte order and optionally removes
82  any Byte Order Marks (BOMS). Returns with the remainig length. */  any Byte Order Marks (BOMS). Returns with the remainig length. */
83  BOOL same_bo = TRUE;  BOOL same_bo = TRUE;
84  PCRE_SPTR16 end = input + length;  pcre_uchar *optr = (pcre_uchar *)output;
85    const pcre_uchar *iptr = (const pcre_uchar *)input;
86    const pcre_uchar *end;
87  /* The c variable must be unsigned. */  /* The c variable must be unsigned. */
88  register pcre_uchar c;  register pcre_uchar c;
89    
90  while (input < end)  if (length < 0)
91      length = STRLEN_UC(iptr) + 1;
92    end = iptr + length;
93    
94    while (iptr < end)
95    {    {
96    c = *input++;    c = *iptr++;
97    if (c == 0xfeff || c == 0xfffe)    if (c == 0xfeff || c == 0xfffe)
98      {      {
99      /* Detecting the byte order of the machine is unnecessary, it is      /* Detecting the byte order of the machine is unnecessary, it is
100      enough to know that the UTF-16 string has the same byte order or not. */      enough to know that the UTF-16 string has the same byte order or not. */
101      same_bo = c == 0xfeff;      same_bo = c == 0xfeff;
102      if (keep_boms != 0)      if (keep_boms != 0)
103        *output++ = 0xfeff;        *optr++ = 0xfeff;
104      else      else
105        length--;        length--;
106      }      }
107    else    else
108      *output++ = same_bo ? c : ((c >> 8) | (c << 8)); /* Flip bytes if needed. */      *optr++ = same_bo ? c : ((c >> 8) | (c << 8)); /* Flip bytes if needed. */
109    }    }
110    
111  #else  #else

Legend:
Removed from v.782  
changed lines
  Added in v.789

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12