Newer
Older
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id$
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
Alberto Massari
committed
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/TranscodingException.hpp>
#include <xercesc/util/XMLException.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/XMLUni.hpp>
#include <xercesc/util/RefHashTableOf.hpp>
#include "Win32TransService.hpp"
#include <windows.h>
// ---------------------------------------------------------------------------
// Local, const data
// ---------------------------------------------------------------------------
static const XMLCh gMyServiceId[] =
{
chLatin_W, chLatin_i, chLatin_n, chDigit_3, chDigit_2, chNull
};
Alberto Massari
committed
#if !HAVE_WCSUPR
void wcsupr(LPWSTR str)
{
int nLen=XMLString::stringLen(str);
::LCMapStringW( GetThreadLocale(), LCMAP_UPPERCASE, str, nLen, str, nLen);
}
#endif
Alberto Massari
committed
#if !HAVE_WCSLWR
void wcslwr(LPWSTR str)
{
int nLen=XMLString::stringLen(str);
::LCMapStringW( GetThreadLocale(), LCMAP_LOWERCASE, str, nLen, str, nLen);
}
#endif
#if !HAVE_WCSNICMP
int wcsnicmp(LPCWSTR comp1, LPCWSTR comp2, unsigned int nLen)
{
unsigned int len = XMLString::stringLen( comp1);
unsigned int otherLen = XMLString::stringLen( comp2);
unsigned int countChar = 0;
unsigned int maxChars;
int theResult = 0;
Alberto Massari
committed
// Determine at what string index the comparison stops.
len = ( len > nLen ) ? nLen : len;
otherLen = ( otherLen > nLen ) ? nLen : otherLen;
maxChars = ( len > otherLen ) ? otherLen : len;
Alberto Massari
committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Handle situation when one argument or the other is NULL
// by returning +/- string length of non-NULL argument (inferred
// from XMLString::CompareNString).
// Obs. Definition of stringLen(XMLCh*) implies NULL ptr and ptr
// to Empty String are equivalent. It handles NULL args, BTW.
if ( !comp1 )
{
// Negative because null ptr (c1) less than string (c2).
return ( 0 - otherLen );
}
if ( !comp2 )
{
// Positive because string (c1) still greater than null ptr (c2).
return len;
}
// Copy const parameter strings (plus terminating nul) into locals.
XMLCh* firstBuf = (XMLCh*) XMLPlatformUtils::fgMemoryManager->allocate( (++len) * sizeof(XMLCh) );//new XMLCh[ ++len];
XMLCh* secondBuf = (XMLCh*) XMLPlatformUtils::fgMemoryManager->allocate( (++otherLen) * sizeof(XMLCh) );//new XMLCh[ ++otherLen];
memcpy( firstBuf, comp1, len * sizeof(XMLCh));
memcpy( secondBuf, comp2, otherLen * sizeof(XMLCh));
// Then uppercase both strings, losing their case info.
::LCMapStringW( GetThreadLocale(), LCMAP_UPPERCASE, (LPWSTR)firstBuf, len, (LPWSTR)firstBuf, len);
::LCMapStringW( GetThreadLocale(), LCMAP_UPPERCASE, (LPWSTR)secondBuf, otherLen, (LPWSTR)secondBuf, otherLen);
// Strings are equal until proven otherwise.
while ( ( countChar < maxChars ) && ( !theResult ) )
{
theResult = (int)(firstBuf[countChar]) - (int)(secondBuf[countChar]);
++countChar;
}
XMLPlatformUtils::fgMemoryManager->deallocate(firstBuf);//delete [] firstBuf;
XMLPlatformUtils::fgMemoryManager->deallocate(secondBuf);//delete [] secondBuf;
return theResult;
}
#endif
#if !HAVE_WCSICMP
int wcsicmp(LPCWSTR comp1, LPCWSTR comp2)
{
unsigned int len = XMLString::stringLen( comp1);
unsigned int otherLen = XMLString::stringLen( comp2);
// Must compare terminating NUL to return difference if one string is shorter than the other.
unsigned int maxChars = ( len > otherLen ) ? otherLen : len;
return wcsnicmp(comp1, comp2, maxChars+1);
}
#endif
// ---------------------------------------------------------------------------
// This is the simple CPMapEntry class. It just contains an encoding name
// and a code page for that encoding.
// ---------------------------------------------------------------------------
class CPMapEntry : public XMemory
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
{
public :
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
CPMapEntry
(
const XMLCh* const encodingName
, const unsigned int cpId
, const unsigned int ieId
);
CPMapEntry
(
const char* const encodingName
, const unsigned int cpId
, const unsigned int ieId
);
~CPMapEntry();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
const XMLCh* getEncodingName() const;
const XMLCh* getKey() const;
unsigned int getWinCP() const;
unsigned int getIEEncoding() const;
private :
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
CPMapEntry();
CPMapEntry(const CPMapEntry&);
CPMapEntry& operator=(const CPMapEntry&);
// -----------------------------------------------------------------------
// Private data members
//
// fEncodingName
// This is the encoding name for the code page that this instance
// represents.
//
// fCPId
// This is the Windows specific code page for the encoding that this
// instance represents.
//
// fIEId
// This is the IE encoding id. Its not used at this time, but we
// go ahead and get it and store it just in case for later.
// -----------------------------------------------------------------------
XMLCh* fEncodingName;
unsigned int fCPId;
unsigned int fIEId;
};
Loading
Loading full blame...