iconv390transservice.cpp
来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 607 行 · 第 1/2 页
CPP
607 行
/* * Copyright 1999-2004 The Apache Software Foundation. * * Licensed 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: Iconv390TransService.cpp,v 1.10 2004/09/08 13:56:45 peiyongz Exp $ */// ---------------------------------------------------------------------------// Includes// ---------------------------------------------------------------------------#include "Iconv390TransService.hpp"#include <xercesc/util/XMLUniDefs.hpp>#include <xercesc/util/XMLUni.hpp>#include <xercesc/util/regx/XMLUniCharacter.hpp>#include <xercesc/framework/MemoryManager.hpp>#include <wchar.h>#include <string.h>#include <stdlib.h>#include <stdio.h>#ifdef OS390BATCH#include <unistd.h>#endif#include <ctype.h>XERCES_CPP_NAMESPACE_BEGIN//// Cannot use the OS/390 c/c++ towupper and towlower functions in the// Unicode environment. We will use mytowupper and mytowlower here.//#undef towupper#undef towlower#define towupper mytowupper#define towlower mytowlower// ---------------------------------------------------------------------------// Local, const data// ---------------------------------------------------------------------------static const int gTempBuffArraySize = 1024;static const XMLCh gMyServiceId[] ={ chLatin_I, chLatin_C, chLatin_o, chLatin_n, chLatin_v, chNull};// ---------------------------------------------------------------------------// gUnicodeToIBM037XlatTable// This is the translation table for Unicode to ibm-037. This table// contains 255 entries.// ---------------------------------------------------------------------------static const XMLByte gUnicodeToIBM037XlatTable[256] ={ 0x00, 0x01, 0x02, 0x03, 0x37, 0x2D, 0x2E, 0x2F , 0x16, 0x05, 0x25, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F , 0x10, 0x11, 0x12, 0x13, 0x3C, 0x3D, 0x32, 0x26 , 0x18, 0x19, 0x3F, 0x27, 0x1C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77 , 0xAC, 0x69, 0xED, 0xEE, 0xEB, 0xEF, 0xEC, 0xBF , 0x80, 0xFD, 0xFE, 0xFB, 0xFC, 0xAD, 0xAE, 0x59 , 0x44, 0x45, 0x42, 0x46, 0x43, 0x47, 0x9C, 0x48 , 0x54, 0x51, 0x52, 0x53, 0x58, 0x55, 0x56, 0x57 , 0x8C, 0x49, 0xCD, 0xCE, 0xCB, 0xCF, 0xCC, 0xE1 , 0x70, 0xDD, 0xDE, 0xDB, 0xDC, 0x8D, 0x8E, 0xDF};iconvconverter * converterList;XMLMutex converterListMutex;iconvconverter * addConverter(const char* const EncodingName ,XMLTransService::Codes& resValue){ XMLMutexLock lockConverterlist(&converterListMutex); iconvconverter *tconv=converterList; while ( (tconv) && (strcmp(tconv->name,EncodingName)) ) tconv = tconv->nextconverter; if (tconv) { tconv->usecount++; } else { tconv = new iconvconverter; strcpy(tconv->name,EncodingName); tconv->usecount=1; tconv->fIconv390Descriptor = iconv_open("UCS-2",EncodingName); if (tconv->fIconv390Descriptor == (iconv_t)(-1)) { resValue = XMLTransService::UnsupportedEncoding; delete tconv; return 0; } tconv->nextconverter = converterList; converterList = tconv; } return tconv;}void removeConverter(iconvconverter* const converter){ iconvconverter *pconv,*tconv; tconv = 0; if (converter) { XMLMutexLock lockConverterlist(&converterListMutex); if (--converter->usecount==0) { tconv = converterList; pconv = (iconvconverter*)&converterList; while ( (tconv) && (tconv!=converter) ) { pconv=tconv; tconv=tconv->nextconverter; } pconv->nextconverter=tconv->nextconverter; } } if (tconv) { iconv_close(tconv->fIconv390Descriptor); delete tconv; }}// ---------------------------------------------------------------------------// Local methods// ---------------------------------------------------------------------------static unsigned int getWideCharLength(const XMLCh* const src){ if (!src) return 0; unsigned int len = 0; const XMLCh* pTmp = src; while (*pTmp++) len++; return len;}// ---------------------------------------------------------------------------// Iconv390TransService: Constructors and Destructor// ---------------------------------------------------------------------------Iconv390TransService::Iconv390TransService(){}Iconv390TransService::~Iconv390TransService(){}// ---------------------------------------------------------------------------// Iconv390TransService: The virtual transcoding service API// ---------------------------------------------------------------------------int Iconv390TransService::compareIString( const XMLCh* const comp1 , const XMLCh* const comp2){ const XMLCh* cptr1 = comp1; const XMLCh* cptr2 = comp2; while ( (*cptr1 != 0) && (*cptr2 != 0) ) { wint_t wch1 = towupper(*cptr1); wint_t wch2 = towupper(*cptr2); if (wch1 != wch2) break; cptr1++; cptr2++; } return (int) ( towupper(*cptr1) - towupper(*cptr2) );}int Iconv390TransService::compareNIString( const XMLCh* const comp1 , const XMLCh* const comp2 , const unsigned int maxChars){ unsigned int n = 0; const XMLCh* cptr1 = comp1; const XMLCh* cptr2 = comp2; while (true && maxChars) { wint_t wch1 = towupper(*cptr1); wint_t wch2 = towupper(*cptr2); if (wch1 != wch2) return (int) (wch1 - wch2); // If either ended, then both ended, so equal if (!*cptr1 || !*cptr2) break; cptr1++; cptr2++; // Bump the count of chars done. If it equals the count then we // are equal for the requested count, so break out and return // equal. n++; if (n == maxChars) break; } return 0;}const XMLCh* Iconv390TransService::getId() const{ return gMyServiceId;}bool Iconv390TransService::isSpace(const XMLCh toCheck) const{ unsigned short chartype = XMLUniCharacter::getType(toCheck); if ( (chartype == XMLUniCharacter::SPACE_SEPARATOR) || (chartype == XMLUniCharacter::LINE_SEPARATOR) || (chartype == XMLUniCharacter::PARAGRAPH_SEPARATOR) ) return true; else return false;}XMLLCPTranscoder* Iconv390TransService::makeNewLCPTranscoder(){ XMLTransService::Codes resValue; // native MVS default code page is IBM-037 iconvconverter *tconv=addConverter("IBM-037",resValue); if (tconv == 0) { return 0; } return new Iconv390LCPTranscoder(tconv);}bool Iconv390TransService::supportsSrcOfs() const{ return true;}// ---------------------------------------------------------------------------// Iconv390TransService: The protected virtual transcoding service API// ---------------------------------------------------------------------------XMLTranscoder*Iconv390TransService::makeNewXMLTranscoder(const XMLCh* const encodingName , XMLTransService::Codes& resValue , const unsigned int , MemoryManager* const){ // This is a minimalist transcoding service, that only supports a local // default transcoder. All named encodings return zero as a failure, // which means that only the intrinsic encodings supported by the parser // itself will work for XML data. // resValue = XMLTransService::UnsupportedEncoding; return 0;}void Iconv390TransService::upperCase(XMLCh* const toUpperCase) const{ XMLCh* outPtr = toUpperCase; while (*outPtr != 0) { if ((*outPtr >= 0x61) && (*outPtr <= 0x7A)) *outPtr = *outPtr - 0x20; outPtr++; }}void Iconv390TransService::lowerCase(XMLCh* const toLowerCase) const{ XMLCh* outPtr = toLowerCase;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?