]> git.lyx.org Git - features.git/blob - src/support/strfwd.h
introduce a header to forward declare std::string.
[features.git] / src / support / strfwd.h
1 // -*- C++ -*-
2
3 // Heavily inspired by /usr/include/c++/4.1/bits
4 //
5 // Copyright (C) 2001, 2002 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library.  This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 2, or (at your option)
11 // any later version.
12
13 #ifndef STRFWD_H
14 #define STRFWD_H
15
16 namespace std {
17
18 template<typename Char> struct char_traits;
19 template<> struct char_traits<char>;
20 template<> struct char_traits<wchar_t>;
21
22 template<typename Alloc> class allocator;
23
24 template<typename Char, typename Traits, typename Alloc> class basic_string;
25
26 typedef basic_string<char, char_traits<char>, allocator<char> > string;
27
28 }
29
30
31 #ifdef USE_WCHAR_T
32
33 // Prefer this if possible because GNU libstdc++ has usable
34 // std::ctype<wchar_t> locale facets but not
35 // std::ctype<boost::uint32_t>. gcc older than 3.4 is also missing
36 // usable std::char_traits<boost::uint32_t>.
37 namespace lyx { typedef wchar_t char_type; }
38
39 #else
40
41 #include <boost/cstdint.hpp>
42 namepace lyx { typedef boost::uint32_t char_type; }
43
44 #endif
45
46
47 namespace lyx {
48
49 typedef std::basic_string<char_type, std::char_traits<char_type>,
50         std::allocator<char_type> > docstring;
51
52 /// Creates a docstring from a C string of ASCII characters
53 docstring const from_ascii(char const *);
54
55 /// Creates a docstring from a std::string of ASCII characters
56 docstring const from_ascii(std::string const &);
57
58 /// Creates a std::string of ASCII characters from a docstring
59 std::string const to_ascii(docstring const &);
60
61 /// Creates a docstring from a UTF8 string. This should go eventually.
62 docstring const from_utf8(std::string const &);
63
64 /// Creates a UTF8 string from a docstring. This should go eventually.
65 std::string const to_utf8(docstring const &);
66
67 /// convert \p s from the encoding of the locale to ucs4.
68 docstring const from_local8bit(std::string const & s);
69
70 /**
71  * Convert \p s from ucs4 to the encoding of the locale.
72  * This may fail and throw an exception, the caller is expected to act
73  * appropriately.
74  */
75 std::string const to_local8bit(docstring const & s);
76
77 /// convert \p s from the encoding of the file system to ucs4.
78 docstring const from_filesystem8bit(std::string const & s);
79
80 /// convert \p s from ucs4 to the encoding of the file system.
81 std::string const to_filesystem8bit(docstring const & s);
82
83 /// normalize \p s to precomposed form c
84 docstring const normalize_c(docstring const & s);
85
86 /// Compare a docstring with a C string of ASCII characters
87 bool operator==(docstring const &, char const *);
88
89 /// Compare a C string of ASCII characters with a docstring
90 inline bool operator==(char const * l, docstring const & r) { return r == l; }
91
92 /// Compare a docstring with a C string of ASCII characters
93 inline bool operator!=(docstring const & l, char const * r) { return !(l == r); }
94
95 /// Compare a C string of ASCII characters with a docstring
96 inline bool operator!=(char const * l, docstring const & r) { return !(r == l); }
97
98 /// Concatenate a docstring and a C string of ASCII characters
99 docstring operator+(docstring const &, char const *);
100
101 /// Concatenate a C string of ASCII characters and a docstring
102 docstring operator+(char const *, docstring const &);
103
104 /// Concatenate a docstring and a single ASCII character
105 docstring operator+(docstring const & l, char r);
106
107 /// Concatenate a single ASCII character and a docstring
108 docstring operator+(char l, docstring const & r);
109
110 /// Append a C string of ASCII characters to a docstring
111 docstring & operator+=(docstring &, char const *);
112
113 /// Append a single ASCII character to a docstring
114 docstring & operator+=(docstring & l, char r);
115
116 } // namespace lyx
117
118 #endif