/[pcre]/code/trunk/pcre16_utf16_utils.c
ViewVC logotype

Diff of /code/trunk/pcre16_utf16_utils.c

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

code/branches/pcre16/pcre16_utf16_utils.c revision 789 by zherczeg, Wed Dec 7 14:36:26 2011 UTC code/trunk/pcre16_utf16_utils.c revision 836 by ph10, Wed Dec 28 17:16:11 2011 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2009 University of Cambridge             Copyright (c) 1997-2012 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 67  Arguments: Line 67  Arguments:
67    input      any UTF-16 string    input      any UTF-16 string
68    length     the number of characters in the input string    length     the number of characters in the input string
69               can be less than zero for zero terminated strings               can be less than zero for zero terminated strings
70      host_byte_order
71                 A non-zero value means the input is in host byte
72                 order, which can be dynamically changed by BOMs later.
73                 Initially it contains the starting byte order and returns
74                 with the last byte order so it can be used for stream
75                 processing. It can be NULL, which set the host byte
76                 order mode by default.
77    keep_boms  for a non-zero value, the BOM (0xfeff) characters    keep_boms  for a non-zero value, the BOM (0xfeff) characters
78               are copied as well               are copied as well
79    
# Line 75  Returns:     the number of characters pl Line 82  Returns:     the number of characters pl
82  */  */
83    
84  int  int
85  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,
86      int length, int *host_byte_order, int keep_boms)
87  {  {
88  #ifdef SUPPORT_UTF16  #ifdef SUPPORT_UTF
89  /* 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
90  any Byte Order Marks (BOMS). Returns with the remainig length. */  removes any Byte Order Marks (BOMS). Returns with the remainig length. */
91  BOOL same_bo = TRUE;  int host_bo = host_byte_order != NULL ? *host_byte_order : 1;
92  pcre_uchar *optr = (pcre_uchar *)output;  pcre_uchar *optr = (pcre_uchar *)output;
93  const pcre_uchar *iptr = (const pcre_uchar *)input;  const pcre_uchar *iptr = (const pcre_uchar *)input;
94  const pcre_uchar *end;  const pcre_uchar *end;
# Line 98  while (iptr < end) Line 106  while (iptr < end)
106      {      {
107      /* Detecting the byte order of the machine is unnecessary, it is      /* Detecting the byte order of the machine is unnecessary, it is
108      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. */
109      same_bo = c == 0xfeff;      host_bo = c == 0xfeff;
110      if (keep_boms != 0)      if (keep_boms != 0)
111        *optr++ = 0xfeff;        *optr++ = 0xfeff;
112      else      else
113        length--;        length--;
114      }      }
115    else    else
116      *optr++ = same_bo ? c : ((c >> 8) | (c << 8)); /* Flip bytes if needed. */      *optr++ = host_bo ? c : ((c >> 8) | (c << 8)); /* Flip bytes if needed. */
117    }    }
118    if (host_byte_order != NULL)
119      *host_byte_order = host_bo;
120    
121  #else  #else /* SUPPORT_UTF */
122  (void)(output);  /* Keep picky compilers happy */  (void)(output);  /* Keep picky compilers happy */
123  (void)(input);  (void)(input);
124  (void)(keep_boms);  (void)(keep_boms);
125  #endif  #endif /* SUPPORT_UTF */
126  return length;  return length;
127  }  }
128    

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

  ViewVC Help
Powered by ViewVC 1.1.5