ucn_string.hh

Go to the documentation of this file.
00001 /*
00002    The lestes compiler suite
00003    Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy
00004    Copyright (C) 2002, 2003, 2004, 2005 Petr Zika
00005    Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala
00006    Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina
00007    Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda
00008    Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar
00009    Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas
00010 
00011    This program is free software; you can redistribute it and/or modify
00012    it under the terms of the GNU General Public License as published by
00013    the Free Software Foundation; version 2 of the License.
00014 
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019 
00020    See the full text of the GNU General Public License version 2, and
00021    the limitations in the file doc/LICENSE.
00022 
00023    By accepting the license the licensee waives any and all claims
00024    against the copyright holder(s) related in whole or in part to the
00025    work, its use, and/or the inability to use it.
00026  
00027  */
00028 #ifndef lestes__std___ucn_string_hh___included
00029 #define lestes__std___ucn_string_hh___included
00030 
00031 /*! \file
00032   \brief String of ucn characters.
00033 
00034   Declaration of standard string template specialized for ucn character type.
00035 */
00036 #include <lestes/common.hh>
00037 #include <lestes/std/ucn_traits.hh>
00038 #include <string>
00039 #include <iosfwd>
00040 
00041 package(lestes);
00042 package(std);
00043 
00044 //! Defines templated predecessor of ucn string.
00045 typedef ::std::basic_string<ucn> basic_ucn_string;
00046 
00047 /*!
00048   \brief String of ucn characters.
00049 
00050   Represents string of ucn characters. The string is intended for
00051   storing internal representation of identifiers and literals.
00052   It shall not be used for ordinary messages or texts.
00053   All data is implicitly stored in superset of ASCII and has to be
00054   converted to host character set before displaying
00055 */
00056 class ucn_string : public basic_ucn_string {
00057 public:
00058         //! Creates empty string.
00059         ucn_string(void);
00060         //! Creates ucn string, initializes with other string.
00061         ucn_string(const ucn_string &str);
00062         //! Creates string, initializes with part of string.
00063         ucn_string(const ucn_string &str, size_type pos, size_type n = npos);
00064         // TODO pt remove
00065 #if 0
00066         //! creates ucn string, initializes with part of string and allocator
00067         inline ucn_string(const value_type *s, size_type n, const allocator_type &a = allocator_type()):
00068                 basic_ucn_string(checked(s),n,a) {}
00069         //! creates ucn string, initializes with string and allocator
00070         inline ucn_string(const value_type *s, const allocator_type &a = allocator_type()):
00071                 basic_ucn_string(checked(s),a) {}
00072 #endif
00073         //! Creates string, fills with character.
00074         ucn_string(size_type n, value_type c);
00075         //! Creates ucn string, initializes with iterator.
00076         template <class InputIterator>
00077         ucn_string(InputIterator beg, InputIterator end);
00078         //! Creates string, initializes with host characters.
00079         ucn_string(const char *data);
00080         //! Returns escaped host representation.
00081         lstring to_host_string(void) const;
00082 };
00083 
00084 /*!
00085   Creates empty ucn string.
00086 */
00087 inline ucn_string::ucn_string(void):
00088         basic_ucn_string()
00089 {
00090 }
00091 
00092 /*!
00093   Creates ucn string, initializes with another string.
00094   \param str  The initializer.
00095 */
00096 inline ucn_string::ucn_string(const ucn_string &str):
00097         basic_ucn_string(str)
00098 {
00099 }
00100 
00101 /*!
00102   Creates ucn string, initializes with a portion of another string.
00103   \param str  The initializer.
00104   \param pos  The starting position in the initializer.
00105   \param n  The length of the portion.
00106 */
00107 inline ucn_string::ucn_string(const ucn_string &str, size_type pos, size_type n):
00108         basic_ucn_string(str,pos,n)
00109 {
00110 }
00111 
00112 /*!
00113   Creates ucn string, fills with characters.
00114   \param n  The length of the string.
00115   \param c  The character to fill.
00116 */
00117 inline ucn_string::ucn_string(size_type n, value_type c):
00118         basic_ucn_string(n,c,allocator_type())
00119 {
00120 }
00121 
00122 /*!
00123   Creates ucn string, initializes with iterator.
00124   \param InputIterator  The type of the iterator.
00125   \param beg  The starting position of the iterator.
00126   \param end  The ending position of the iterator.
00127 */
00128 template <class InputIterator>
00129 inline ucn_string::ucn_string(InputIterator beg, InputIterator end):
00130         basic_ucn_string(beg,end,allocator_type())
00131 {
00132 }
00133 
00134 /*!
00135   Creates ucn string from regular characters ASCIIZ string.
00136   \param s  The characters to convert.
00137 */
00138 inline ucn_string::ucn_string(const char *s):
00139         basic_ucn_string(strlen(s),0xdeadbeef)
00140 {
00141         for (ucn_string::iterator it = this->begin(), end = this->end(); it != end; ++it, ++s) {
00142                 *it = character::create_from_host(*s);
00143         }
00144 }
00145 
00146 //! Prints ucn string to stream.
00147 ::std::ostream& operator<<(::std::ostream &os, const ucn_string &us);
00148 
00149 end_package(std);
00150 end_package(lestes);
00151 
00152 #endif
00153 /* vim: set ft=lestes : */

Generated on Mon Feb 12 18:23:44 2007 for lestes by doxygen 1.5.1-20070107