mirror of
https://github.com/jezhiggins/arabica
synced 2024-11-17 07:48:50 +01:00
*** empty log message ***
This commit is contained in:
parent
dba21361f7
commit
1201d2057c
4 changed files with 20 additions and 200 deletions
|
@ -3,6 +3,15 @@
|
||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// $Id$
|
// $Id$
|
||||||
|
// Written by Jez Higgins <jez@jezuk.co.uk>
|
||||||
|
// Copyright 1999-2003 Jez UK Ltd, http://www.jezuk.co.uk/
|
||||||
|
//
|
||||||
|
// convert_adaptor is a stream that wraps around another stream. This
|
||||||
|
// may not seem like a big deal, but convert_adaptor applies codecvt
|
||||||
|
// facets along the way. This allows you to apply encryption or
|
||||||
|
// decryption (or any other transcoding) transparently. It can
|
||||||
|
// also adapt wchar_t streams to char streams, or vice versa, allowing
|
||||||
|
// you to write std::wstrings out as UTF-8 chars to a file, for instance.
|
||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
#include <locale>
|
#include <locale>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef CONVERTSTREAM_H
|
#ifndef BASIC_CONVERTSTREAM_H
|
||||||
#define CONVERTSTREAM_H
|
#define BASIC_CONVERTSTREAM_H
|
||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// $Id$
|
// $Id$
|
||||||
|
@ -8,6 +8,9 @@
|
||||||
//
|
//
|
||||||
// basic_iconvertstream, basic_oconvertstream
|
// basic_iconvertstream, basic_oconvertstream
|
||||||
//
|
//
|
||||||
|
// Written by Jez Higgins <jez@jezuk.co.uk>
|
||||||
|
// Copyright 1999-2003 Jez UK Ltd, http://www.jezuk.co.uk/
|
||||||
|
//
|
||||||
// Normal basic_stringstream do not apply the codecvt facet
|
// Normal basic_stringstream do not apply the codecvt facet
|
||||||
// of their locale. These two streams act exactly like
|
// of their locale. These two streams act exactly like
|
||||||
// basic_stringstream except that they do apply the imbued codecvt
|
// basic_stringstream except that they do apply the imbued codecvt
|
||||||
|
|
|
@ -2,30 +2,10 @@
|
||||||
#define basic_socketstreamH
|
#define basic_socketstreamH
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// socketstream.h
|
// socket_stream.h
|
||||||
//
|
//
|
||||||
// Written by Jez Higgins <jez@jezuk.co.uk>
|
// Written by Jez Higgins <jez@jezuk.co.uk>
|
||||||
//
|
// Copyright 1999-2003 Jez UK Ltd, http://www.jezuk.co.uk/
|
||||||
// Copyright 1999-2000 Jez UK Ltd, http://www.jezuk.co.uk/
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose
|
|
||||||
// on any computer system, and redistribute it freely, subject to the
|
|
||||||
// following restrictions:
|
|
||||||
//
|
|
||||||
// 1. This softwre is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
//
|
|
||||||
// 2. The origin of this software must not be misrepresented, either by
|
|
||||||
// explicit claim or by omission.
|
|
||||||
//
|
|
||||||
// 3. Altered version must be plainly marked as such, and must not be
|
|
||||||
// misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 4. If this software is used in any software which is released under
|
|
||||||
// the GNU General Public Licence (GPL), then the terms of that
|
|
||||||
// licence shall supercede any condition above with which it is
|
|
||||||
// incompatible.
|
|
||||||
//
|
//
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
|
@ -3,182 +3,9 @@
|
||||||
|
|
||||||
#pragma warning(disable: 4786 4250 4503)
|
#pragma warning(disable: 4786 4250 4503)
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
|
||||||
#include <DOM/SAX2DOM/SAX2DOM.h>
|
#include <DOM/SAX2DOM/SAX2DOM.h>
|
||||||
#include <XML/UnicodeCharacters.h>
|
#include <DOM/Utils/Stream.h>
|
||||||
|
|
||||||
template<typename char_type, typename traits_type>
|
|
||||||
class escaper
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
typedef char_type charT;
|
|
||||||
typedef traits_type traitsT;
|
|
||||||
typedef std::basic_ostream<charT, traitsT> ostreamT;
|
|
||||||
typedef Unicode<charT> UnicodeT;
|
|
||||||
|
|
||||||
public:
|
|
||||||
escaper(ostreamT& stream) : stream_(stream) { }
|
|
||||||
void operator()(charT ch)
|
|
||||||
{
|
|
||||||
if(ch == UnicodeT::LESS_THAN_SIGN)
|
|
||||||
{
|
|
||||||
stream_ << UnicodeT::AMPERSAND
|
|
||||||
<< UnicodeT::LOWERCASE_L
|
|
||||||
<< UnicodeT::LOWERCASE_T
|
|
||||||
<< UnicodeT::SEMI_COLON;
|
|
||||||
return;
|
|
||||||
} // if(ch == UnicodeT::LESS_THAN_SIGN)
|
|
||||||
if(ch == UnicodeT::GREATER_THAN_SIGN)
|
|
||||||
{
|
|
||||||
stream_ << UnicodeT::AMPERSAND
|
|
||||||
<< UnicodeT::LOWERCASE_G
|
|
||||||
<< UnicodeT::LOWERCASE_T
|
|
||||||
<< UnicodeT::SEMI_COLON;
|
|
||||||
return;
|
|
||||||
} // if(ch == UnicodeT::GREATER_THAN_SIGN)
|
|
||||||
if(ch == UnicodeT::AMPERSAND)
|
|
||||||
{
|
|
||||||
stream_ << UnicodeT::AMPERSAND
|
|
||||||
<< UnicodeT::LOWERCASE_A
|
|
||||||
<< UnicodeT::LOWERCASE_M
|
|
||||||
<< UnicodeT::LOWERCASE_P
|
|
||||||
<< UnicodeT::SEMI_COLON;
|
|
||||||
return;
|
|
||||||
} // if(ch == case UnicodeT::AMPERSAND)
|
|
||||||
if(ch == UnicodeT::QUOTATION_MARK)
|
|
||||||
{
|
|
||||||
stream_ << UnicodeT::AMPERSAND
|
|
||||||
<< UnicodeT::LOWERCASE_Q
|
|
||||||
<< UnicodeT::LOWERCASE_U
|
|
||||||
<< UnicodeT::LOWERCASE_O
|
|
||||||
<< UnicodeT::LOWERCASE_T
|
|
||||||
<< UnicodeT::SEMI_COLON;
|
|
||||||
return;
|
|
||||||
} // if(ch == UnicodeT::QUOTATION_MARK)
|
|
||||||
stream_ << ch;
|
|
||||||
} // operator()
|
|
||||||
|
|
||||||
private:
|
|
||||||
ostreamT& stream_;
|
|
||||||
}; // escaper
|
|
||||||
|
|
||||||
template<class stringT, class charT, class traitsT>
|
|
||||||
void doChildren(std::basic_ostream<charT, traitsT>& stream, DOM::Node<stringT>& node)
|
|
||||||
{
|
|
||||||
DOM::Node<stringT> child = node.getFirstChild();
|
|
||||||
while(child != 0)
|
|
||||||
{
|
|
||||||
stream << child;
|
|
||||||
child = child.getNextSibling();
|
|
||||||
} // while
|
|
||||||
} // doChildren
|
|
||||||
|
|
||||||
|
|
||||||
template<class stringT, class charT, class traitsT>
|
|
||||||
std::basic_ostream<charT, traitsT>&
|
|
||||||
operator<<(std::basic_ostream<charT, traitsT>& stream,
|
|
||||||
DOM::Node<stringT>& node)
|
|
||||||
{
|
|
||||||
typedef Unicode<charT> UnicodeT;
|
|
||||||
|
|
||||||
switch(node.getNodeType())
|
|
||||||
{
|
|
||||||
case DOM::Node<stringT>::DOCUMENT_NODE:
|
|
||||||
stream << UnicodeT::LESS_THAN_SIGN
|
|
||||||
<< UnicodeT::QUESTION_MARK
|
|
||||||
<< UnicodeT::LOWERCASE_X
|
|
||||||
<< UnicodeT::LOWERCASE_M
|
|
||||||
<< UnicodeT::LOWERCASE_L
|
|
||||||
<< UnicodeT::SPACE
|
|
||||||
<< UnicodeT::LOWERCASE_V
|
|
||||||
<< UnicodeT::LOWERCASE_E
|
|
||||||
<< UnicodeT::LOWERCASE_R
|
|
||||||
<< UnicodeT::LOWERCASE_S
|
|
||||||
<< UnicodeT::LOWERCASE_I
|
|
||||||
<< UnicodeT::LOWERCASE_O
|
|
||||||
<< UnicodeT::LOWERCASE_N
|
|
||||||
<< UnicodeT::EQUALS_SIGN
|
|
||||||
<< UnicodeT::QUOTATION_MARK
|
|
||||||
<< UnicodeT::NUMBER_1
|
|
||||||
<< UnicodeT::FULL_STOP
|
|
||||||
<< UnicodeT::NUMBER_0
|
|
||||||
<< UnicodeT::QUOTATION_MARK
|
|
||||||
<< UnicodeT::QUESTION_MARK
|
|
||||||
<< UnicodeT::GREATER_THAN_SIGN
|
|
||||||
<< std::endl;
|
|
||||||
doChildren(stream, node);
|
|
||||||
break;
|
|
||||||
case DOM::Node<stringT>::ELEMENT_NODE:
|
|
||||||
{
|
|
||||||
stream << UnicodeT::LESS_THAN_SIGN << node.getNodeName();
|
|
||||||
DOM::NamedNodeMap<stringT> attrs = node.getAttributes();
|
|
||||||
for(unsigned int a = 0; a < attrs.getLength(); ++a)
|
|
||||||
{
|
|
||||||
DOM::Node<stringT> attr = attrs.item(a);
|
|
||||||
stream << UnicodeT::SPACE
|
|
||||||
<< attr.getNodeName()
|
|
||||||
<< UnicodeT::EQUALS_SIGN
|
|
||||||
<< UnicodeT::QUOTATION_MARK;
|
|
||||||
stringT value = attr.getNodeValue();
|
|
||||||
std::for_each(value.begin(), value.end(), escaper<charT, traitsT>(stream));
|
|
||||||
stream << UnicodeT::QUOTATION_MARK;
|
|
||||||
}
|
|
||||||
stream << UnicodeT::GREATER_THAN_SIGN;
|
|
||||||
doChildren(stream, node);
|
|
||||||
stream << UnicodeT::LESS_THAN_SIGN << UnicodeT::SLASH << node.getNodeName() << UnicodeT::GREATER_THAN_SIGN;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DOM::Node<stringT>::TEXT_NODE:
|
|
||||||
{
|
|
||||||
stringT value = node.getNodeValue();
|
|
||||||
std::for_each(value.begin(), value.end(), escaper<charT, traitsT>(stream));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DOM::Node<stringT>::ENTITY_REFERENCE_NODE:
|
|
||||||
stream << UnicodeT::AMPERSAND
|
|
||||||
<< node.getNodeName()
|
|
||||||
<< UnicodeT::SEMI_COLON;
|
|
||||||
break;
|
|
||||||
case DOM::Node<stringT>::CDATA_SECTION_NODE:
|
|
||||||
stream << UnicodeT::LESS_THAN_SIGN
|
|
||||||
<< UnicodeT::EXCLAMATION_MARK
|
|
||||||
<< UnicodeT::LEFT_SQUARE_BRACKET
|
|
||||||
<< UnicodeT::CAPITAL_C
|
|
||||||
<< UnicodeT::CAPITAL_D
|
|
||||||
<< UnicodeT::CAPITAL_A
|
|
||||||
<< UnicodeT::CAPITAL_T
|
|
||||||
<< UnicodeT::CAPITAL_A
|
|
||||||
<< UnicodeT::LEFT_SQUARE_BRACKET
|
|
||||||
<< node.getNodeValue()
|
|
||||||
<< UnicodeT::RIGHT_SQUARE_BRACKET
|
|
||||||
<< UnicodeT::RIGHT_SQUARE_BRACKET
|
|
||||||
<< UnicodeT::GREATER_THAN_SIGN;
|
|
||||||
break;
|
|
||||||
case DOM::Node<stringT>::PROCESSING_INSTRUCTION_NODE:
|
|
||||||
stream << UnicodeT::LESS_THAN_SIGN
|
|
||||||
<< UnicodeT::QUESTION_MARK
|
|
||||||
<< node.getNodeName()
|
|
||||||
<< UnicodeT::SPACE
|
|
||||||
<< node.getNodeValue()
|
|
||||||
<< UnicodeT::QUESTION_MARK
|
|
||||||
<< UnicodeT::GREATER_THAN_SIGN;
|
|
||||||
break;
|
|
||||||
case DOM::Node<stringT>::COMMENT_NODE:
|
|
||||||
stream << UnicodeT::LESS_THAN_SIGN
|
|
||||||
<< UnicodeT::EXCLAMATION_MARK
|
|
||||||
<< UnicodeT::HYPHEN_MINUS
|
|
||||||
<< UnicodeT::HYPHEN_MINUS
|
|
||||||
<< node.getNodeValue()
|
|
||||||
<< UnicodeT::HYPHEN_MINUS
|
|
||||||
<< UnicodeT::HYPHEN_MINUS
|
|
||||||
<< UnicodeT::GREATER_THAN_SIGN;
|
|
||||||
break;
|
|
||||||
} // switch
|
|
||||||
|
|
||||||
return stream;
|
|
||||||
} // operator<<
|
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
|
@ -189,7 +16,6 @@ int main(int argc, char* argv[])
|
||||||
return 0;
|
return 0;
|
||||||
} // if(argc < 2)
|
} // if(argc < 2)
|
||||||
|
|
||||||
/*
|
|
||||||
{ // narrow
|
{ // narrow
|
||||||
SAX2DOM::Parser<std::string> domParser;
|
SAX2DOM::Parser<std::string> domParser;
|
||||||
|
|
||||||
|
@ -213,8 +39,9 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
std::cout << doc;
|
std::cout << doc;
|
||||||
} // for ...
|
} // for ...
|
||||||
} */
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
{ // wide
|
{ // wide
|
||||||
SAX2DOM::Parser<std::wstring> domParser;
|
SAX2DOM::Parser<std::wstring> domParser;
|
||||||
|
|
||||||
|
@ -228,6 +55,7 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
std::wcout << doc;
|
std::wcout << doc;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} // main
|
} // main
|
||||||
|
|
Loading…
Reference in a new issue