Work around MinGW mangling of "host:/path"
[msysgit/historical-msysgit.git] / mingw / include / c++ / 3.4.2 / ext / pod_char_traits.h
blobc69025e005d268a5abefb8b52cb99e5d7b1008f9
1 // POD character, std::char_traits specialization -*- C++ -*-
3 // Copyright (C) 2002, 2003 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 // Gabriel Dos Reis <gdr@integrable-solutions.net>
31 // Benjamin Kosnik <bkoz@redhat.com>
33 #ifndef _POD_CHAR_TRAITS_H
34 #define _POD_CHAR_TRAITS_H 1
36 #include <string>
38 namespace __gnu_cxx
40 template<typename V, typename I, typename S = mbstate_t>
41 struct character
43 typedef V value_type;
44 typedef I int_type;
45 typedef S state_type;
46 value_type value;
49 template<typename V, typename I>
50 inline bool
51 operator==(const character<V, I>& lhs, const character<V, I>& rhs)
52 { return lhs.value == rhs.value; }
54 template<typename V, typename I>
55 inline bool
56 operator<(const character<V, I>& lhs, const character<V, I>& rhs)
57 { return lhs.value < rhs.value; }
58 } // namespace __gnu_cxx
60 namespace std
62 // Provide std::char_traits specialization.
63 template<typename V, typename I, typename S>
64 struct char_traits<__gnu_cxx::character<V, I, S> >
66 typedef __gnu_cxx::character<V, I, S> char_type;
68 // NB: This type should be bigger than char_type, so as to
69 // properly hold EOF values in addition to the full range of
70 // char_type values.
71 // Also, assumes
72 // int_type(value_type) is valid.
73 // int_type(-1) is possible.
74 typedef typename char_type::int_type int_type;
75 typedef typename char_type::state_type state_type;
76 typedef fpos<state_type> pos_type;
77 typedef streamoff off_type;
79 static void
80 assign(char_type& __c1, const char_type& __c2)
81 { __c1 = __c2; }
83 static bool
84 eq(const char_type& __c1, const char_type& __c2)
85 { return __c1 == __c2; }
87 static bool
88 lt(const char_type& __c1, const char_type& __c2)
89 { return __c1 < __c2; }
91 static int
92 compare(const char_type* __s1, const char_type* __s2, size_t __n)
94 for (size_t __i = 0; __i < __n; ++__i)
95 if (!eq(__s1[__i], __s2[__i]))
96 return lt(__s1[__i], __s2[__i]) ? -1 : 1;
97 return 0;
100 static size_t
101 length(const char_type* __s)
103 const char_type* __p = __s;
104 while (__p->value)
105 ++__p;
106 return (__p - __s);
109 static const char_type*
110 find(const char_type* __s, size_t __n, const char_type& __a)
112 for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p)
113 if (*__p == __a)
114 return __p;
115 return 0;
118 static char_type*
119 move(char_type* __s1, const char_type* __s2, size_t __n)
120 { return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); }
122 static char_type*
123 copy(char_type* __s1, const char_type* __s2, size_t __n)
124 { return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); }
126 static char_type*
127 assign(char_type* __s, size_t __n, char_type __a)
129 for (char_type* __p = __s; __p < __s + __n; ++__p)
130 assign(*__p, __a);
131 return __s;
134 static char_type
135 to_char_type(const int_type& __c)
137 char_type __r = { __c };
138 return __r;
141 static int_type
142 to_int_type(const char_type& __c)
143 { return int_type(__c.value); }
145 static bool
146 eq_int_type(const int_type& __c1, const int_type& __c2)
147 { return __c1 == __c2; }
149 static int_type
150 eof() { return static_cast<int_type>(-1); }
152 static int_type
153 not_eof(const int_type& __c)
154 { return eq_int_type(__c, eof()) ? int_type(0) : __c; }
158 #endif