~zorba-coders/zorba/pul-and-xdm-schemas

« back to all changes in this revision

Viewing changes to src/util/passthru_streambuf.cpp

- Added transcode_streambuf
- file:read-text now respects encodings
- http:send-request now respects encodings Approved: Matthias Brantner, Paul J. Lucas

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2006-2008 The FLWOR Foundation.
 
3
 * 
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 * 
 
8
 * http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
#include "passthru_streambuf.h"
 
18
 
 
19
using namespace std;
 
20
 
 
21
namespace zorba {
 
22
 
 
23
///////////////////////////////////////////////////////////////////////////////
 
24
 
 
25
passthru_streambuf::passthru_streambuf( char const*, streambuf *orig ) :
 
26
  proxy_streambuf( orig )
 
27
{
 
28
  if ( !orig )
 
29
    throw invalid_argument( "null streambuf" );
 
30
}
 
31
 
 
32
passthru_streambuf::~passthru_streambuf() {
 
33
  // out-of-line since it's virtual
 
34
}
 
35
 
 
36
void passthru_streambuf::imbue( std::locale const &loc ) {
 
37
  original()->pubimbue( loc );
 
38
}
 
39
 
 
40
bool passthru_streambuf::is_necessary( char const *cc_charset ) {
 
41
  zstring charset( cc_charset );
 
42
  ascii::trim_whitespace( charset );
 
43
  ascii::to_upper( charset );
 
44
  return charset != "ASCII"
 
45
      && charset != "US-ASCII"
 
46
      && charset != "UTF-8";
 
47
}
 
48
 
 
49
bool passthru_streambuf::is_supported( char const *cc_charset ) {
 
50
  return !is_necessary( charset );
 
51
}
 
52
 
 
53
passthru_streambuf::pos_type
 
54
passthru_streambuf::seekoff( off_type o, ios_base::seekdir d,
 
55
                             ios_base::openmode m ) {
 
56
  return original()->pubseekoff( o, d, m );
 
57
}
 
58
 
 
59
passthru_streambuf::pos_type
 
60
passthru_streambuf::seekpos( pos_type p, ios_base::openmode m ) {
 
61
  return original()->pubseekpos( p, m );
 
62
}
 
63
 
 
64
streambuf* passthru_streambuf::setbuf( char_type *p, streamsize s ) {
 
65
  original()->pubsetbuf( p, s );
 
66
  return this;
 
67
}
 
68
 
 
69
streamsize passthru_streambuf::showmanyc() {
 
70
  return original()->in_avail();
 
71
}
 
72
 
 
73
int passthru_streambuf::sync() {
 
74
  return original()->pubsync();
 
75
}
 
76
 
 
77
passthru_streambuf::int_type passthru_streambuf::overflow( int_type c ) {
 
78
  return original()->sputc( c );
 
79
}
 
80
 
 
81
passthru_streambuf::int_type passthru_streambuf::pbackfail( int_type c ) {
 
82
  return original()->sputbackc( traits_type::to_char_type( c ) );
 
83
}
 
84
 
 
85
passthru_streambuf::int_type passthru_streambuf::uflow() {
 
86
  return original()->sbumpc();
 
87
}
 
88
 
 
89
passthru_streambuf::int_type passthru_streambuf::underflow() {
 
90
  return original()->sgetc();
 
91
}
 
92
 
 
93
streamsize passthru_streambuf::xsgetn( char_type *to, streamsize size ) {
 
94
  return original()->sgetn( to, size );
 
95
}
 
96
 
 
97
streamsize passthru_streambuf::xsputn( char_type const *from,
 
98
                                       streamsize size ) {
 
99
  return original()->sputn( from, size );
 
100
}
 
101
 
 
102
///////////////////////////////////////////////////////////////////////////////
 
103
 
 
104
} // namespace zorba
 
105
/* vim:set et sw=2 ts=2: */