(file) Return to CommonUTF.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 karl  1.10 //%2005////////////////////////////////////////////////////////////////////////
  2 david 1.1  //
  3 karl  1.10 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 karl  1.3  // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.10 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9            // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 david 1.1  //
 12            // Permission is hereby granted, free of charge, to any person obtaining a copy
 13            // of this software and associated documentation files (the "Software"), to
 14            // deal in the Software without restriction, including without limitation the
 15            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 16            // sell copies of the Software, and to permit persons to whom the Software is
 17            // furnished to do so, subject to the following conditions:
 18 chip  1.11 //
 19 david 1.1  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 21            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 22            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 23            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 25            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 26            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27            //
 28            //==============================================================================
 29            //
 30            // Author: Dave Rosckes   (rosckes@us.ibm.com)
 31            //
 32 yi.zhou 1.12 // Modified By: Yi Zhou Hewlett-Packard Company (yi.zhou@hp.com)
 33 david   1.1  //
 34              //%/////////////////////////////////////////////////////////////////////////////
 35              
 36              #ifndef Pegasus_CommonUTF_h
 37              #define Pegasus_CommonUTF_h
 38              #include <Pegasus/Common/Config.h>
 39 chuck   1.6  #include <Pegasus/Common/Linkage.h>
 40 chuck   1.7  #include <Pegasus/Common/String.h>
 41 yi.zhou 1.12 #include <Pegasus/Common/IPC.h>
 42 david   1.1  
 43 chuck   1.2  #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
 44              
 45 david   1.1  PEGASUS_NAMESPACE_BEGIN
 46              
 47              #define FIRST_HIGH_SURROGATE  (Uint32)0xD800
 48              #define LAST_HIGH_SURROGATE   (Uint32)0xDBFF
 49              #define FIRST_LOW_SURROGATE   (Uint32)0xDC00
 50              #define LAST_LOW_SURROGATE    (Uint32)0xDFFF
 51              #define REPLACEMENT_CHARACTER (Uint32)0x0000FFFD
 52              #define MAX_BYTE              (Uint32)0x0000FFFF
 53              #define MAX_UTF16             (Uint32)0x0010FFFF
 54              
 55              static const Uint32 halfBase = 0x0010000UL;
 56              static const Uint32 halfMask = 0x3FFUL;
 57              static const int halfShift  = 10;
 58              static const Uint8 firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
 59              
 60 chip    1.11 static const Uint32 offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL,
 61                           0x03C82080UL, 0xFA082080UL, 0x82082080UL };
 62 david   1.1  
 63              static const char trailingBytesForUTF8[256] = {
 64                  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 65                  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 66                  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 67                  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 68                  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 69                  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 70                  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
 71                  2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
 72              };
 73              
 74              #define UTF_8_COUNT_TRAIL_BYTES(leadByte) (trailingBytesForUTF8[(Uint8)leadByte])
 75              
 76 chuck   1.4  #define UTF8_NEXT(s, i) { \
 77                  (i)=((i) + UTF_8_COUNT_TRAIL_BYTES((s)[(i)]) + 1); \
 78 chip    1.11 }
 79              
 80 david   1.1  
 81 chip    1.11 PEGASUS_COMMON_LINKAGE Boolean isValid_U8(const Uint8 *src,int size);
 82 david   1.1  
 83 chip    1.11 PEGASUS_COMMON_LINKAGE int UTF16toUTF8(
 84                  const Uint16** srcHead,
 85                  const Uint16* srcEnd,
 86                  Uint8** tgtHead,
 87                  Uint8* tgtEnd);
 88              
 89              PEGASUS_COMMON_LINKAGE int UTF8toUTF16(
 90                  const Uint8** srcHead,
 91                  const Uint8* srcEnd,
 92                  Uint16** tgtHead,
 93                  Uint16* tgtEnd);
 94 david   1.1  
 95 mike    1.13 PEGASUS_COMMON_LINKAGE Boolean isUTF8Aux(const char*);
 96              
 97              inline Boolean isUTF8(const char* c)
 98              {
 99                  return (unsigned int)c[0] < 128 || isUTF8Aux(c);
100              }
101 chuck   1.7  
102 chuck   1.9  PEGASUS_COMMON_LINKAGE Boolean isUTF8Str(const char*);
103              
104 chuck   1.7  /** Escape all characters above 7-bit ASCII.
105                  @param String: The string to be escaped Insert text here.
106                  @return String: The escaped string.
107              */
108              PEGASUS_COMMON_LINKAGE String escapeStringEncoder(const String& Str);
109              
110              /** decode string returned from escapeString Encoder.
111                  @param String: The string to be decoded.
112                  @return String: The decoded string.
113              
114 chip    1.11     Prereq: Only the return string from the escapeStringEncoder can be used
115 chuck   1.7              as input.
116              */
117              PEGASUS_COMMON_LINKAGE String escapeStringDecoder(const String& Str);
118              
119 yi.zhou 1.12 /**
120                  The InitializeICU class loads and initializes data items that are required 
121                  internally by various ICU functions. It makes sure that ICU function u_init 
122                  is only called once by a process. A module which is using ICU APIs needs 
123                  to call InitializeICU::initICUSuccessful first before it calls other ICU 
124                  APIs. If InitializeICU::initICUSuccessful is failed, the module should not 
125                  call other ICU APIs. 
126              */
127              
128              #ifdef PEGASUS_HAS_ICU
129              class PEGASUS_COMMON_LINKAGE InitializeICU
130              {
131              public:
132              
133                  /**
134              	Determines if ICU initialization is successful.
135              
136              	@return  true, if u_init is called and success
137              	         false otherwise
138                  */
139              
140 yi.zhou 1.12     static Boolean initICUSuccessful();
141              
142              private:
143                  static Boolean _initAttempted;
144                  static Boolean _initSuccessful;
145              
146                  static Mutex _initMutex;
147              };
148              
149              #endif
150              
151 david   1.5  
152 david   1.1  PEGASUS_NAMESPACE_END
153 chuck   1.2  
154              #endif  // PEGASUS_USE_EXPERIMENTAL_INTERFACES
155              
156 david   1.1  #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2