/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock

« back to all changes in this revision

Viewing changes to src/utility/string_iostream

  • Committer: edam
  • Date: 2012-02-28 16:50:26 UTC
  • Revision ID: edam@waxworlds.org-20120228165026-pwnwo300xx2e2kg6
removed ulibc, fixed button, added text rendering

Show diffs side-by-side

added added

removed removed

1
 
/*      Copyright (C) 2004 Garrett A. Kajmowicz
2
 
 
3
 
        This file is part of the uClibc++ Library.
4
 
 
5
 
        This library is free software; you can redistribute it and/or
6
 
        modify it under the terms of the GNU Lesser General Public
7
 
        License as published by the Free Software Foundation; either
8
 
        version 2.1 of the License, or (at your option) any later version.
9
 
 
10
 
        This library is distributed in the hope that it will be useful,
11
 
        but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
        Lesser General Public License for more details.
14
 
 
15
 
        You should have received a copy of the GNU Lesser General Public
16
 
        License along with this library; if not, write to the Free Software
17
 
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
*/
19
 
 
20
 
#include <istream>
21
 
#include <ostream>
22
 
#include <string>
23
 
 
24
 
#ifdef __UCLIBCXX_HAS_WCHAR__
25
 
#include <cwchar>
26
 
#include <cwctype>
27
 
#endif
28
 
 
29
 
#ifndef __HEADER_STD_STRING_IOSTREAM
30
 
#define __HEADER_STD_STRING_IOSTREAM 1
31
 
 
32
 
#pragma GCC visibility push(default)
33
 
 
34
 
namespace std{
35
 
 
36
 
 
37
 
 
38
 
template<class charT, class traits, class Allocator> _UCXXEXPORT basic_ostream<charT, traits>&
39
 
        operator<<(basic_ostream<charT, traits>& os, const basic_string<charT,traits,Allocator>& str)
40
 
{
41
 
        return os.write(str.data(), str.length());
42
 
}
43
 
 
44
 
template<class charT, class traits, class Allocator> _UCXXEXPORT basic_istream<charT,traits>&
45
 
        operator>>(basic_istream<charT,traits>& is, basic_string<charT,traits,Allocator>& str)
46
 
{
47
 
 
48
 
        typename basic_istream<charT, traits>::sentry s(is);
49
 
        if(s == false){
50
 
                return is;
51
 
        }
52
 
 
53
 
        str.clear();
54
 
 
55
 
        typename basic_istream<charT, traits>::int_type c;
56
 
        typename Allocator::size_type n = is.width();
57
 
        bool exitnow = false;
58
 
        if(n == 0){
59
 
                n = str.max_size();
60
 
        }
61
 
 
62
 
//      //Clear out preliminary spaces first
63
 
//      c = is.get();
64
 
//      while(isspace(c)){
65
 
//              c = is.get();
66
 
//      }
67
 
//
68
 
//      is.putback(c);
69
 
 
70
 
        do{
71
 
                c = is.get();
72
 
                if(c == traits::eof() || isspace(c) || n == 0){
73
 
                        is.putback(c);
74
 
                        exitnow = true;
75
 
                }else{
76
 
                        str.append(1, traits::to_char_type(c) );
77
 
                        --n;
78
 
                }
79
 
        }while(exitnow == false);
80
 
        return is;
81
 
}
82
 
 
83
 
template<class charT, class traits, class Allocator> _UCXXEXPORT basic_istream<charT,traits>&
84
 
        getline(basic_istream<charT,traits>& is, basic_string<charT,traits,Allocator>& str, charT delim)
85
 
{
86
 
        typename basic_istream<charT,traits>::sentry s(is);
87
 
        if(s == false){
88
 
                return is;
89
 
        }
90
 
 
91
 
        str.erase();
92
 
 
93
 
        streamsize i = 0;
94
 
        typename basic_istream<charT,traits>::int_type c_i;
95
 
        charT c;
96
 
        unsigned int n = str.max_size();
97
 
        for(i=0;i<n;++i){
98
 
                c_i=is.get();
99
 
                if(c_i == traits::eof() ){
100
 
                        return is;
101
 
                }
102
 
                c = traits::to_char_type(c_i);
103
 
                if(c == delim){
104
 
                        return is;
105
 
                }
106
 
                str.append(1, c);
107
 
        }
108
 
        return is;      
109
 
}
110
 
 
111
 
template<class charT, class traits, class Allocator> _UCXXEXPORT basic_istream<charT,traits>&
112
 
        getline(basic_istream<charT,traits>& is, basic_string<charT,traits,Allocator>& str)
113
 
{
114
 
        return getline(is, str, '\n');
115
 
}
116
 
 
117
 
 
118
 
#ifdef __UCLIBCXX_EXPAND_STRING_CHAR__
119
 
#ifndef __UCLIBCXX_COMPILE_STRING__
120
 
 
121
 
 
122
 
#ifdef __UCLIBCXX_EXPAND_ISTREAM_CHAR__
123
 
template<> _UCXXEXPORT basic_istream<char, char_traits<char> >& operator>>(
124
 
        basic_istream<char,char_traits<char> >& is,
125
 
        basic_string<char, char_traits<char>, allocator<char> >& str);
126
 
#endif
127
 
 
128
 
 
129
 
#ifdef __UCLIBCXX_EXPAND_OSTREAM_CHAR__
130
 
template<> _UCXXEXPORT basic_ostream<char, char_traits<char> >&
131
 
        operator<<(basic_ostream<char, char_traits<char> >& os, 
132
 
        const basic_string<char,char_traits<char>, std::allocator<char> >& str);
133
 
 
134
 
#endif
135
 
 
136
 
 
137
 
#endif
138
 
#endif
139
 
 
140
 
 
141
 
}
142
 
 
143
 
#pragma GCC visibility pop
144
 
 
145
 
#endif
146