mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
introduce a header to forward declare std::string.
hope there are only conforming implementaions out there ;-} git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21312 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
e91114cdcb
commit
a5263e0f92
@ -32,6 +32,8 @@
|
||||
|
||||
#include "Color.h"
|
||||
|
||||
#include "support/docstring.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include "Dimension.h"
|
||||
#include "update_flags.h"
|
||||
|
||||
#include "support/docstring.h"
|
||||
#include "support/strfwd.h"
|
||||
#include "support/types.h"
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
@ -16,6 +16,7 @@
|
||||
#define CHANGES_H
|
||||
|
||||
#include "support/docstream.h"
|
||||
#include "support/types.h"
|
||||
#include "support/lyxtime.h"
|
||||
|
||||
#include <vector>
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
#include "ColorCode.h"
|
||||
|
||||
#include "support/docstring.h"
|
||||
#include "support/strfwd.h"
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
|
@ -14,9 +14,11 @@
|
||||
#ifndef CUTANDPASTE_H
|
||||
#define CUTANDPASTE_H
|
||||
|
||||
#include "support/docstring.h"
|
||||
#include "TextClass.h"
|
||||
|
||||
#include "support/types.h"
|
||||
#include "support/docstring.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace lyx {
|
||||
|
@ -23,6 +23,8 @@
|
||||
#include "support/lstrings.h"
|
||||
#include "support/unicode.h"
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#ifndef CXX_GLOBAL_CSTD
|
||||
|
@ -12,6 +12,7 @@
|
||||
#ifndef ERRORLIST_H
|
||||
#define ERRORLIST_H
|
||||
|
||||
#include "support/types.h"
|
||||
#include "support/docstring.h"
|
||||
|
||||
#include <vector>
|
||||
|
@ -13,7 +13,6 @@
|
||||
#ifndef LATEXFEATURES_H
|
||||
#define LATEXFEATURES_H
|
||||
|
||||
|
||||
#include "OutputParams.h"
|
||||
#include "support/docstring.h"
|
||||
|
||||
@ -125,7 +124,7 @@ private:
|
||||
///
|
||||
UsedFloats usedFloats_;
|
||||
///
|
||||
typedef std::map<docstring , std::string> FileMap;
|
||||
typedef std::map<docstring, std::string> FileMap;
|
||||
///
|
||||
FileMap IncludedFiles_;
|
||||
/** Buffer of the file being processed.
|
||||
|
@ -59,6 +59,13 @@ Length::Length(string const & data)
|
||||
}
|
||||
|
||||
|
||||
void Length::swap(Length & rhs)
|
||||
{
|
||||
std::swap(val_, rhs.val_);
|
||||
std::swap(unit_, rhs.unit_);
|
||||
}
|
||||
|
||||
|
||||
string const Length::asString() const
|
||||
{
|
||||
ostringstream os;
|
||||
|
12
src/Length.h
12
src/Length.h
@ -15,7 +15,7 @@
|
||||
#ifndef LENGTH_H
|
||||
#define LENGTH_H
|
||||
|
||||
#include "support/docstring.h"
|
||||
#include "support/strfwd.h"
|
||||
|
||||
|
||||
namespace lyx {
|
||||
@ -67,12 +67,8 @@ public:
|
||||
/// "data" must be a decimal number, followed by a unit
|
||||
explicit Length(std::string const & data);
|
||||
|
||||
void swap(Length & rhs)
|
||||
{
|
||||
std::swap(val_, rhs.val_);
|
||||
std::swap(unit_, rhs.unit_);
|
||||
}
|
||||
|
||||
///
|
||||
void swap(Length & rhs);
|
||||
///
|
||||
double value() const;
|
||||
///
|
||||
@ -100,7 +96,7 @@ public:
|
||||
|
||||
private:
|
||||
///
|
||||
double val_;
|
||||
double val_;
|
||||
///
|
||||
Length::UNIT unit_;
|
||||
};
|
||||
|
11
src/Lexer.h
11
src/Lexer.h
@ -17,9 +17,7 @@
|
||||
#ifndef LEXER_H
|
||||
#define LEXER_H
|
||||
|
||||
#include "support/docstring.h"
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include "support/strfwd.h"
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
@ -55,7 +53,7 @@ struct keyword_item {
|
||||
|
||||
@see LyXRC.cpp for an example of usage.
|
||||
*/
|
||||
class Lexer : boost::noncopyable {
|
||||
class Lexer {
|
||||
public:
|
||||
///
|
||||
Lexer(keyword_item *, int);
|
||||
@ -175,6 +173,11 @@ public:
|
||||
static std::string const quoteString(std::string const &);
|
||||
|
||||
private:
|
||||
/// noncopiable
|
||||
Lexer(Lexer const &);
|
||||
void operator=(Lexer const &);
|
||||
|
||||
///
|
||||
class Pimpl;
|
||||
///
|
||||
Pimpl * pimpl_;
|
||||
|
@ -14,7 +14,10 @@
|
||||
|
||||
#include "ColorCode.h"
|
||||
#include "FontInfo.h"
|
||||
#include "support/docstring.h"
|
||||
|
||||
#include "support/strfwd.h"
|
||||
#include "support/types.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class BufferView;
|
||||
|
@ -21,7 +21,8 @@
|
||||
|
||||
#include "insets/InsetCode.h"
|
||||
|
||||
#include "support/docstring.h"
|
||||
#include "support/strfwd.h"
|
||||
#include "support/types.h"
|
||||
// FIXME: would be nice to forward declare odocstream instead of
|
||||
// including this:
|
||||
#include "support/docstream.h"
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "SpellBase.h"
|
||||
#include "gettext.h"
|
||||
#include "support/docstring.h"
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
@ -13,7 +13,7 @@
|
||||
#ifndef SPELL_BASE_H
|
||||
#define SPELL_BASE_H
|
||||
|
||||
#include "support/docstring.h"
|
||||
#include "support/strfwd.h"
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
@ -14,6 +14,8 @@
|
||||
|
||||
#include "Color.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace lyx {
|
||||
|
||||
const QColor grey40(0x66, 0x66, 0x66);
|
||||
|
@ -13,7 +13,7 @@
|
||||
#ifndef GETTEXT_H
|
||||
#define GETTEXT_H
|
||||
|
||||
#include "support/docstring.h"
|
||||
#include "support/strfwd.h"
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
@ -13,9 +13,10 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "Length.h"
|
||||
|
||||
#include "gettext.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
#ifndef LYXFIND_H
|
||||
#define LYXFIND_H
|
||||
|
||||
#include "support/docstring.h"
|
||||
#include "support/strfwd.h"
|
||||
|
||||
namespace lyx {
|
||||
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
ExceptionMessage(ExceptionType type, docstring const & title,
|
||||
docstring const & details)
|
||||
: type_(type), title_(title), details_(details),
|
||||
message_(to_utf8(title_ + '\n' + details_)) {}
|
||||
message_(to_utf8(title_ + docstring::value_type('\n') + details_)) {}
|
||||
|
||||
virtual const char * what() const throw() { return message_.c_str(); }
|
||||
virtual ~ExceptionMessage() throw() {}
|
||||
|
@ -77,6 +77,7 @@ liblyxsupport_la_SOURCES = \
|
||||
rename.cpp \
|
||||
socktools.cpp \
|
||||
socktools.h \
|
||||
strfwd.h \
|
||||
std_istream.h \
|
||||
std_ostream.h \
|
||||
Systemcall.cpp \
|
||||
|
@ -194,7 +194,9 @@ lyx::docstring operator+(char const * l, lyx::docstring const & r)
|
||||
lyx::docstring operator+(lyx::docstring const & l, char r)
|
||||
{
|
||||
BOOST_ASSERT(static_cast<unsigned char>(r) < 0x80);
|
||||
return l + lyx::docstring::value_type(r);
|
||||
docstring s = l;
|
||||
s += docstring::value_type(r);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
#ifndef LYX_DOCSTRING_H
|
||||
#define LYX_DOCSTRING_H
|
||||
|
||||
#include "support/types.h"
|
||||
#include "support/strfwd.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -22,70 +22,6 @@ namespace lyx {
|
||||
/// String type for storing the main text in UCS4 encoding
|
||||
typedef std::basic_string<char_type> docstring;
|
||||
|
||||
/// Creates a docstring from a C string of ASCII characters
|
||||
docstring const from_ascii(char const *);
|
||||
|
||||
/// Creates a docstring from a std::string of ASCII characters
|
||||
docstring const from_ascii(std::string const &);
|
||||
|
||||
/// Creates a std::string of ASCII characters from a docstring
|
||||
std::string const to_ascii(docstring const &);
|
||||
|
||||
/// Creates a docstring from a UTF8 string. This should go eventually.
|
||||
docstring const from_utf8(std::string const &);
|
||||
|
||||
/// Creates a UTF8 string from a docstring. This should go eventually.
|
||||
std::string const to_utf8(docstring const &);
|
||||
|
||||
/// convert \p s from the encoding of the locale to ucs4.
|
||||
docstring const from_local8bit(std::string const & s);
|
||||
|
||||
/**
|
||||
* Convert \p s from ucs4 to the encoding of the locale.
|
||||
* This may fail and throw an exception, the caller is expected to act
|
||||
* appropriately.
|
||||
*/
|
||||
std::string const to_local8bit(docstring const & s);
|
||||
|
||||
/// convert \p s from the encoding of the file system to ucs4.
|
||||
docstring const from_filesystem8bit(std::string const & s);
|
||||
|
||||
/// convert \p s from ucs4 to the encoding of the file system.
|
||||
std::string const to_filesystem8bit(docstring const & s);
|
||||
|
||||
/// normalize \p s to precomposed form c
|
||||
docstring const normalize_c(docstring const & s);
|
||||
|
||||
/// Compare a docstring with a C string of ASCII characters
|
||||
bool operator==(lyx::docstring const &, char const *);
|
||||
|
||||
/// Compare a C string of ASCII characters with a docstring
|
||||
inline bool operator==(char const * l, lyx::docstring const & r) { return r == l; }
|
||||
|
||||
/// Compare a docstring with a C string of ASCII characters
|
||||
inline bool operator!=(lyx::docstring const & l, char const * r) { return !(l == r); }
|
||||
|
||||
/// Compare a C string of ASCII characters with a docstring
|
||||
inline bool operator!=(char const * l, lyx::docstring const & r) { return !(r == l); }
|
||||
|
||||
/// Concatenate a docstring and a C string of ASCII characters
|
||||
lyx::docstring operator+(lyx::docstring const &, char const *);
|
||||
|
||||
/// Concatenate a C string of ASCII characters and a docstring
|
||||
lyx::docstring operator+(char const *, lyx::docstring const &);
|
||||
|
||||
/// Concatenate a docstring and a single ASCII character
|
||||
lyx::docstring operator+(lyx::docstring const & l, char r);
|
||||
|
||||
/// Concatenate a single ASCII character and a docstring
|
||||
lyx::docstring operator+(char l, lyx::docstring const & r);
|
||||
|
||||
/// Append a C string of ASCII characters to a docstring
|
||||
lyx::docstring & operator+=(lyx::docstring &, char const *);
|
||||
|
||||
/// Append a single ASCII character to a docstring
|
||||
lyx::docstring & operator+=(lyx::docstring & l, char r);
|
||||
|
||||
} // namespace lyx
|
||||
|
||||
|
||||
|
@ -518,6 +518,19 @@ std::basic_string<Ch> const subst_char(std::basic_string<Ch> const & a,
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/// Substitute all \a oldchar with \a newchar
|
||||
docstring const subst_char(docstring const & a,
|
||||
docstring::value_type oldchar, docstring::value_type newchar)
|
||||
{
|
||||
docstring tmp(a);
|
||||
docstring::iterator lit = tmp.begin();
|
||||
docstring::iterator end = tmp.end();
|
||||
for (; lit != end; ++lit)
|
||||
if ((*lit) == oldchar)
|
||||
(*lit) = newchar;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
/// substitutes all instances of \a oldstr with \a newstr
|
||||
template<typename String> inline
|
||||
@ -536,6 +549,21 @@ String const subst_string(String const & a,
|
||||
return lstr;
|
||||
}
|
||||
|
||||
docstring const subst_string(docstring const & a,
|
||||
docstring const & oldstr, docstring const & newstr)
|
||||
{
|
||||
BOOST_ASSERT(!oldstr.empty());
|
||||
docstring lstr = a;
|
||||
docstring::size_type i = 0;
|
||||
docstring::size_type const olen = oldstr.length();
|
||||
while ((i = lstr.find(oldstr, i)) != string::npos) {
|
||||
lstr.replace(i, olen, newstr);
|
||||
i += newstr.length(); // We need to be sure that we dont
|
||||
// use the same i over and over again.
|
||||
}
|
||||
return lstr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -681,6 +709,25 @@ String const doSplit(String const & a, String & piece, Char delim)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template<typename Char> inline
|
||||
docstring const doSplit(docstring const & a, docstring & piece, Char delim)
|
||||
{
|
||||
docstring tmp;
|
||||
typename docstring::size_type i = a.find(delim);
|
||||
if (i == a.length() - 1) {
|
||||
piece = a.substr(0, i);
|
||||
} else if (i != docstring::npos) {
|
||||
piece = a.substr(0, i);
|
||||
tmp = a.substr(i + 1);
|
||||
} else if (i == 0) {
|
||||
piece.erase();
|
||||
tmp = a.substr(i + 1);
|
||||
} else {
|
||||
piece = a;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,7 +14,8 @@
|
||||
#ifndef OS_H
|
||||
#define OS_H
|
||||
|
||||
#include "support/docstring.h"
|
||||
#include "support/strfwd.h"
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
@ -43,7 +44,7 @@ std::string const python();
|
||||
|
||||
/// Extract the path common to both @c p1 and @c p2. DBCS aware!
|
||||
/// \p p1, \p p2 and the return value are encoded in utf8.
|
||||
docstring::size_type common_path(docstring const & p1, docstring const & p2);
|
||||
std::size_t common_path(docstring const & p1, docstring const & p2);
|
||||
|
||||
/// Converts a unix style path to host OS style.
|
||||
/// \p p and the return value are encoded in utf8.
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "support/os.h"
|
||||
#include "support/docstring.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <Carbon/Carbon.h>
|
||||
|
118
src/support/strfwd.h
Normal file
118
src/support/strfwd.h
Normal file
@ -0,0 +1,118 @@
|
||||
// -*- C++ -*-
|
||||
|
||||
// Heavily inspired by /usr/include/c++/4.1/bits
|
||||
//
|
||||
// Copyright (C) 2001, 2002 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 2, or (at your option)
|
||||
// any later version.
|
||||
|
||||
#ifndef STRFWD_H
|
||||
#define STRFWD_H
|
||||
|
||||
namespace std {
|
||||
|
||||
template<typename Char> struct char_traits;
|
||||
template<> struct char_traits<char>;
|
||||
template<> struct char_traits<wchar_t>;
|
||||
|
||||
template<typename Alloc> class allocator;
|
||||
|
||||
template<typename Char, typename Traits, typename Alloc> class basic_string;
|
||||
|
||||
typedef basic_string<char, char_traits<char>, allocator<char> > string;
|
||||
|
||||
}
|
||||
|
||||
|
||||
#ifdef USE_WCHAR_T
|
||||
|
||||
// Prefer this if possible because GNU libstdc++ has usable
|
||||
// std::ctype<wchar_t> locale facets but not
|
||||
// std::ctype<boost::uint32_t>. gcc older than 3.4 is also missing
|
||||
// usable std::char_traits<boost::uint32_t>.
|
||||
namespace lyx { typedef wchar_t char_type; }
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
namepace lyx { typedef boost::uint32_t char_type; }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
typedef std::basic_string<char_type, std::char_traits<char_type>,
|
||||
std::allocator<char_type> > docstring;
|
||||
|
||||
/// Creates a docstring from a C string of ASCII characters
|
||||
docstring const from_ascii(char const *);
|
||||
|
||||
/// Creates a docstring from a std::string of ASCII characters
|
||||
docstring const from_ascii(std::string const &);
|
||||
|
||||
/// Creates a std::string of ASCII characters from a docstring
|
||||
std::string const to_ascii(docstring const &);
|
||||
|
||||
/// Creates a docstring from a UTF8 string. This should go eventually.
|
||||
docstring const from_utf8(std::string const &);
|
||||
|
||||
/// Creates a UTF8 string from a docstring. This should go eventually.
|
||||
std::string const to_utf8(docstring const &);
|
||||
|
||||
/// convert \p s from the encoding of the locale to ucs4.
|
||||
docstring const from_local8bit(std::string const & s);
|
||||
|
||||
/**
|
||||
* Convert \p s from ucs4 to the encoding of the locale.
|
||||
* This may fail and throw an exception, the caller is expected to act
|
||||
* appropriately.
|
||||
*/
|
||||
std::string const to_local8bit(docstring const & s);
|
||||
|
||||
/// convert \p s from the encoding of the file system to ucs4.
|
||||
docstring const from_filesystem8bit(std::string const & s);
|
||||
|
||||
/// convert \p s from ucs4 to the encoding of the file system.
|
||||
std::string const to_filesystem8bit(docstring const & s);
|
||||
|
||||
/// normalize \p s to precomposed form c
|
||||
docstring const normalize_c(docstring const & s);
|
||||
|
||||
/// Compare a docstring with a C string of ASCII characters
|
||||
bool operator==(docstring const &, char const *);
|
||||
|
||||
/// Compare a C string of ASCII characters with a docstring
|
||||
inline bool operator==(char const * l, docstring const & r) { return r == l; }
|
||||
|
||||
/// Compare a docstring with a C string of ASCII characters
|
||||
inline bool operator!=(docstring const & l, char const * r) { return !(l == r); }
|
||||
|
||||
/// Compare a C string of ASCII characters with a docstring
|
||||
inline bool operator!=(char const * l, docstring const & r) { return !(r == l); }
|
||||
|
||||
/// Concatenate a docstring and a C string of ASCII characters
|
||||
docstring operator+(docstring const &, char const *);
|
||||
|
||||
/// Concatenate a C string of ASCII characters and a docstring
|
||||
docstring operator+(char const *, docstring const &);
|
||||
|
||||
/// Concatenate a docstring and a single ASCII character
|
||||
docstring operator+(docstring const & l, char r);
|
||||
|
||||
/// Concatenate a single ASCII character and a docstring
|
||||
docstring operator+(char l, docstring const & r);
|
||||
|
||||
/// Append a C string of ASCII characters to a docstring
|
||||
docstring & operator+=(docstring &, char const *);
|
||||
|
||||
/// Append a single ASCII character to a docstring
|
||||
docstring & operator+=(docstring & l, char r);
|
||||
|
||||
} // namespace lyx
|
||||
|
||||
#endif
|
@ -15,17 +15,13 @@
|
||||
#ifndef TEXTUTILS_H
|
||||
#define TEXTUTILS_H
|
||||
|
||||
#include "support/types.h"
|
||||
#include "support/strfwd.h"
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
/// return true if the char is a line separator
|
||||
inline
|
||||
bool isLineSeparatorChar(char_type c)
|
||||
{
|
||||
return c == ' ';
|
||||
}
|
||||
inline bool isLineSeparatorChar(char_type c) { return c == ' '; }
|
||||
|
||||
/// return true if a char is alphabetical (including accented chars)
|
||||
bool isLetterChar(char_type c);
|
||||
|
@ -16,23 +16,10 @@
|
||||
#ifndef LYX_TYPES_H
|
||||
#define LYX_TYPES_H
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace lyx {
|
||||
|
||||
/// The type used to hold characters in paragraphs
|
||||
#ifdef USE_WCHAR_T
|
||||
// Prefer this if possible because GNU libstdc++ has usable
|
||||
// std::ctype<wchar_t> locale facets but not
|
||||
// std::ctype<boost::uint32_t>. gcc older than 3.4 is also missing
|
||||
// usable std::char_traits<boost::uint32_t>.
|
||||
typedef wchar_t char_type;
|
||||
#else
|
||||
typedef boost::uint32_t char_type;
|
||||
#endif
|
||||
|
||||
/// a type for positions used in paragraphs
|
||||
// needs to be signed for a while to hold the special value -1 that is
|
||||
// used there
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
#include <iconv.h>
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#include <cerrno>
|
||||
#include <iomanip>
|
||||
#include <map>
|
||||
|
@ -13,7 +13,7 @@
|
||||
#ifndef LYX_SUPPORT_UNICODE_H
|
||||
#define LYX_SUPPORT_UNICODE_H
|
||||
|
||||
#include "support/types.h"
|
||||
#include "support/strfwd.h"
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
#ifndef USERINFO_H
|
||||
#define USERINFO_H
|
||||
|
||||
#include "support/docstring.h"
|
||||
#include "support/strfwd.h"
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
Loading…
Reference in New Issue
Block a user