1999-10-02 16:21:10 +00:00
|
|
|
|
// -*- C++ -*-
|
2002-09-25 10:03:41 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file lyxstring.h
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 10:03:41 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 10:03:41 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS
|
|
|
|
|
*/
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
|
|
// This one is heavily based on the string class in The C++
|
|
|
|
|
// Programming Language by Bjarne Stroustrup
|
|
|
|
|
|
1999-10-22 02:26:50 +00:00
|
|
|
|
// This class is supposed to be functionaly equivalent to a
|
|
|
|
|
// standard conformant string. This mean among others that we
|
|
|
|
|
// are useing the same requirements. Before you change anything
|
|
|
|
|
// in this file consult me and/or the standard to discover the
|
|
|
|
|
// right behavior.
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#ifndef LYXSTRING_H
|
2002-03-21 17:09:55 +00:00
|
|
|
|
#define LYXSTRING_H
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
|
#pragma interface
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
|
#include <iosfwd>
|
1999-10-22 09:45:25 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#if 0
|
|
|
|
|
#include <iterator>
|
|
|
|
|
#endif
|
|
|
|
|
|
1999-10-22 02:26:50 +00:00
|
|
|
|
#include <cstring> // for size_t
|
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
|
/** A string class for LyX
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
This is a permanent String class. It is modeled closely after the C++ STL
|
1999-10-22 02:26:50 +00:00
|
|
|
|
string class. In comparison with STL string lyxstring lack support for
|
|
|
|
|
reverse iterators and allocators, also char_traits is not used. In most
|
|
|
|
|
other senses it is written to be a drop in replacement for STL string
|
|
|
|
|
(or as a transition tool). So documentation for STL string should be
|
|
|
|
|
valid for lyxstring too.
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
|
|
Notes for usage:
|
|
|
|
|
|
1999-10-22 02:26:50 +00:00
|
|
|
|
When you declare an lyxstring, it is initially empty. There is no need to
|
|
|
|
|
do things like #lyxstring a= "";#, especially not in constructors.
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
1999-10-22 02:26:50 +00:00
|
|
|
|
If you want to use a default empty lyxstring as a parameter, use
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
|
|
|
|
#void foo(lyxstring par = lyxstring()); // Correct#
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
rather than
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
#void foo(lyxstring par = ""); // WRONG!#
|
|
|
|
|
#void foo(lyxstring par = 0); // WRONG!#
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
|
|
(The last one is only wrong because some compilers can't handle it.)
|
|
|
|
|
|
|
|
|
|
Methods that take an index as parameter all follow this rule: Valid indexes
|
|
|
|
|
go from 0 to length()-1.
|
|
|
|
|
\begin{tabular}{rl}
|
|
|
|
|
Correct: & #foo.substring(0, length()-1);# \\
|
|
|
|
|
Wrong: & #bar.substring(0, length());#
|
|
|
|
|
\end{tabular}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-22 02:26:50 +00:00
|
|
|
|
It is important that you declare lyxstring as const if possible, because
|
1999-10-02 16:21:10 +00:00
|
|
|
|
some methods are much more efficient in const versions.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
If you want to check whether a string is empty, do
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
#if (foo.empty()) something right#
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
|
|
rather than something along the lines of
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
#if (!foo) completely wrong#
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
1999-10-22 02:26:50 +00:00
|
|
|
|
When you want to copy an lyxstring, just do
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-22 02:26:50 +00:00
|
|
|
|
#lyxstring a, b = "String";#
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#a = b; // That's it!#
|
|
|
|
|
|
|
|
|
|
not something like
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
|
|
|
|
#lyxstring a, b = "String";#
|
|
|
|
|
#a = b.copy(); // This leaks. // and does not work either. #
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
The class automatically handles deep copying when required.
|
|
|
|
|
*/
|
|
|
|
|
class lyxstring {
|
|
|
|
|
public:
|
2000-07-15 23:51:46 +00:00
|
|
|
|
/* Typedefs */
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
typedef char value_type;
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
typedef value_type * pointer;
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
typedef value_type & reference;
|
|
|
|
|
|
|
|
|
|
///
|
1999-10-20 01:53:59 +00:00
|
|
|
|
typedef value_type const & const_reference;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
typedef size_t size_type;
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
typedef int difference_type;
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
typedef value_type * iterator;
|
|
|
|
|
///
|
|
|
|
|
typedef const value_type * const_iterator;
|
|
|
|
|
#if 0
|
|
|
|
|
///
|
|
|
|
|
typedef reverse_iterator<iterator, value_type, reference>
|
1999-10-22 02:26:50 +00:00
|
|
|
|
reverse_iterator;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
typedef reverse_iterator<const_iterator, const value_type,
|
1999-10-22 02:26:50 +00:00
|
|
|
|
const_reference> const_reverse_iterator;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
iterator begin();
|
|
|
|
|
///
|
|
|
|
|
const_iterator begin() const;
|
|
|
|
|
///
|
|
|
|
|
iterator end();
|
|
|
|
|
///
|
|
|
|
|
const_iterator end() const;
|
|
|
|
|
#if 0
|
|
|
|
|
///
|
|
|
|
|
reverse_iterator rbegin();
|
|
|
|
|
///
|
|
|
|
|
const_reverse_iterator rbegin() const;
|
|
|
|
|
///
|
|
|
|
|
reverse_iterator rend();
|
|
|
|
|
///
|
|
|
|
|
const_reverse_iterator rend() const;
|
|
|
|
|
#endif
|
2000-07-15 23:51:46 +00:00
|
|
|
|
/* Constructors and Deconstructors. lyxstring has the same
|
1999-10-02 16:21:10 +00:00
|
|
|
|
constructors as STL, except the one using iterators, one other
|
|
|
|
|
difference is that lyxstring, do not allow the optional allocator
|
|
|
|
|
parameter. */
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
/// "all characters" marker
|
|
|
|
|
static const size_type npos;
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
/// #lyxstring x;#
|
1999-10-21 23:27:31 +00:00
|
|
|
|
lyxstring();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
|
|
|
|
/// #lyxstring x(lyxstring ...)#
|
1999-10-02 16:21:10 +00:00
|
|
|
|
lyxstring(lyxstring const &, size_type pos = 0, size_type n = npos);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
/// #lyxstring x("abc", 2) -> "ab"#
|
|
|
|
|
lyxstring(value_type const *, size_type n);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
|
// #lyxstring x("abc")#
|
1999-10-02 16:21:10 +00:00
|
|
|
|
lyxstring(value_type const *);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
/// lyxstring(5, 'n') -> "nnnnn"
|
|
|
|
|
lyxstring(size_type n, value_type c);
|
|
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
|
#if 1
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
1999-11-22 16:19:48 +00:00
|
|
|
|
lyxstring(const_iterator first, const_iterator last);
|
|
|
|
|
#else
|
|
|
|
|
///
|
|
|
|
|
template<class InputIterator>
|
|
|
|
|
lyxstring::lyxstring(InputIterator begin, InputIterator end) {
|
|
|
|
|
while (begin != end) {
|
|
|
|
|
push_back((*begin));
|
|
|
|
|
++begin;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
1999-10-22 02:26:50 +00:00
|
|
|
|
~lyxstring();
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
|
|
/// number of characters
|
1999-10-22 02:26:50 +00:00
|
|
|
|
size_type size() const;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
|
|
/// largest possible string
|
1999-12-07 00:44:53 +00:00
|
|
|
|
size_type max_size() const { return npos - 1; }
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
size_type length() const { return size(); }
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
bool empty() const { return size() == 0; }
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
void resize(size_type n, value_type c);
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
void resize(size_type n) { resize(n, ' '); }
|
|
|
|
|
|
|
|
|
|
/// size of the memory (in number of elements) allocated.
|
|
|
|
|
size_type capacity() const;
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
void reserve(size_type res_arg = 0);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
lyxstring & operator=(lyxstring const &);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
lyxstring & operator=(value_type const *);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
lyxstring & operator=(value_type);
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
lyxstring & assign(lyxstring const &);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
lyxstring & assign(lyxstring const &, size_type pos, size_type n);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
lyxstring & assign(value_type const * p, size_type n);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
lyxstring & assign(value_type const * p);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
lyxstring & assign(size_type n, value_type c);
|
|
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
|
#if 1
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
1999-11-22 16:19:48 +00:00
|
|
|
|
lyxstring & assign(const_iterator first, const_iterator last);
|
|
|
|
|
#else
|
|
|
|
|
///
|
|
|
|
|
template<class InputIterator>
|
|
|
|
|
lyxstring & assign(InputIterator begin, InputIterator end) {
|
|
|
|
|
clear;
|
|
|
|
|
while (begin != end) {
|
|
|
|
|
push_back((*begin));
|
|
|
|
|
++begin;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
|
|
/// unchecked access
|
|
|
|
|
const_reference operator[](size_type) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
/// unchecked access
|
|
|
|
|
reference operator[](size_type);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
/// checked access
|
|
|
|
|
const_reference at(size_type) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
/// checked access
|
|
|
|
|
reference at(size_type);
|
|
|
|
|
|
|
|
|
|
// add characters after (*this)[length()-1]:
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
lyxstring & operator+=(lyxstring const &);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
lyxstring & operator+=(value_type const *);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
1999-10-21 23:27:31 +00:00
|
|
|
|
lyxstring & operator+=(value_type);
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
void push_back(value_type);
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
lyxstring & append(lyxstring const &);
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
lyxstring & append(lyxstring const &, size_type pos, size_type n);
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
lyxstring & append(value_type const *, size_type n);
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
lyxstring & append(value_type const *);
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
lyxstring & append(size_type n, value_type);
|
|
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
|
#if 1
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
lyxstring & append(iterator first, iterator last);
|
1999-11-22 16:19:48 +00:00
|
|
|
|
#else
|
|
|
|
|
///
|
|
|
|
|
template<class InputIterator>
|
|
|
|
|
lyxstring & append(InputIterator begin, InputIterator end) {
|
|
|
|
|
while (begin != end) {
|
|
|
|
|
push_back((*begin));
|
|
|
|
|
++begin;
|
|
|
|
|
}
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
1999-10-02 16:21:10 +00:00
|
|
|
|
// insert characters before (*this)[pos]:
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
lyxstring & insert(size_type pos, lyxstring const &);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
lyxstring & insert(size_type pos, lyxstring const &,
|
|
|
|
|
size_type pos2, size_type n);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
lyxstring & insert(size_type pos, value_type const * p,
|
|
|
|
|
size_type n);
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
lyxstring & insert(size_type pos, value_type const * p);
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
lyxstring & insert(size_type pos, size_type n, value_type c);
|
|
|
|
|
|
|
|
|
|
// insert characters before p
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
iterator insert(iterator p, value_type c);
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
void insert(iterator p, size_type n , value_type c);
|
|
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
|
#if 1
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
void insert(iterator p, iterator first, iterator last);
|
1999-11-22 16:19:48 +00:00
|
|
|
|
#else
|
|
|
|
|
///
|
|
|
|
|
template<class InputIterator>
|
|
|
|
|
void insert(iterator p, InputIterator begin, InputIterator end) {
|
|
|
|
|
iterator it;
|
|
|
|
|
while (begin != end) {
|
|
|
|
|
it = insert(p, (*begin));
|
|
|
|
|
++begin;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
size_type find(lyxstring const &, size_type i = 0) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
size_type find(value_type const * p,
|
|
|
|
|
size_type i, size_type n) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
size_type find(value_type const * p, size_type i = 0) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
size_type find(value_type c, size_type i = 0) const;
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
size_type rfind(lyxstring const &, size_type i = npos) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
size_type rfind(value_type const * p, size_type i, size_type n) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
size_type rfind(value_type const * p, size_type i = npos) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
size_type rfind(value_type c, size_type i = npos) const;
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
size_type find_first_of(lyxstring const &, size_type i = 0) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
1999-10-22 02:26:50 +00:00
|
|
|
|
size_type find_first_of(value_type const * p, size_type i,
|
|
|
|
|
size_type n) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
size_type find_first_of(value_type const * p, size_type i = 0) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
size_type find_first_of(value_type c, size_type i = 0) const;
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
size_type find_last_of(lyxstring const &, size_type i = npos) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
1999-10-22 02:26:50 +00:00
|
|
|
|
size_type find_last_of(value_type const * p, size_type i,
|
|
|
|
|
size_type n) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
size_type find_last_of(value_type const * p, size_type i = npos) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
size_type find_last_of(value_type c, size_type i = npos) const;
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
size_type find_first_not_of(lyxstring const &, size_type i = 0) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
size_type find_first_not_of(value_type const * p, size_type i,
|
|
|
|
|
size_type n) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
1999-10-22 02:26:50 +00:00
|
|
|
|
size_type find_first_not_of(value_type const * p,
|
|
|
|
|
size_type i = 0) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
size_type find_first_not_of(value_type c, size_type i = 0) const;
|
|
|
|
|
|
|
|
|
|
///
|
1999-10-22 02:26:50 +00:00
|
|
|
|
size_type find_last_not_of(lyxstring const &,
|
|
|
|
|
size_type i = npos) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
size_type find_last_not_of(value_type const * p, size_type i,
|
|
|
|
|
size_type n) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
1999-10-22 02:26:50 +00:00
|
|
|
|
size_type find_last_not_of(value_type const * p,
|
|
|
|
|
size_type i = npos) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
size_type find_last_not_of(value_type c, size_type i = npos) const;
|
|
|
|
|
|
|
|
|
|
// replace [(*this)[i], (*this)[i+n]] with other characters:
|
|
|
|
|
|
|
|
|
|
///
|
1999-11-15 10:54:16 +00:00
|
|
|
|
lyxstring & replace(size_type i, size_type n, lyxstring const & str);
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
|
|
///
|
1999-11-15 10:54:16 +00:00
|
|
|
|
lyxstring & replace(size_type i, size_type n, lyxstring const & s,
|
1999-10-02 16:21:10 +00:00
|
|
|
|
size_type i2, size_type n2);
|
|
|
|
|
|
|
|
|
|
///
|
1999-11-15 10:54:16 +00:00
|
|
|
|
lyxstring & replace(size_type i, size_type n, value_type const * p,
|
1999-10-02 16:21:10 +00:00
|
|
|
|
size_type n2);
|
|
|
|
|
|
|
|
|
|
///
|
1999-11-15 10:54:16 +00:00
|
|
|
|
lyxstring & replace(size_type i, size_type n, value_type const * p);
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
|
|
///
|
1999-10-22 02:26:50 +00:00
|
|
|
|
lyxstring & replace(size_type i, size_type n,
|
|
|
|
|
size_type n2, value_type c);
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
/// FY! FY! FY! go away !
|
|
|
|
|
lyxstring & replace(size_type i, size_type n,
|
|
|
|
|
value_type c);
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
lyxstring & replace(iterator i, iterator i2, const lyxstring & str);
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
lyxstring & replace(iterator i, iterator i2,
|
|
|
|
|
value_type const * p, size_type n);
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
lyxstring & replace(iterator i, iterator i2, value_type const * p);
|
|
|
|
|
|
|
|
|
|
///
|
1999-10-22 02:26:50 +00:00
|
|
|
|
lyxstring & replace(iterator i, iterator i2,
|
|
|
|
|
size_type n , value_type c);
|
1999-11-22 16:19:48 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
lyxstring & replace(iterator i, iterator i2, iterator j, iterator j2);
|
1999-10-07 18:44:17 +00:00
|
|
|
|
|
1999-11-15 14:45:17 +00:00
|
|
|
|
///
|
|
|
|
|
void swap(lyxstring & str);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
/// Erase n chars from position i.
|
|
|
|
|
lyxstring & erase(size_type i = 0, size_type n = npos);
|
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
|
///
|
|
|
|
|
lyxstring & clear() {
|
|
|
|
|
return erase(0, npos);
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
iterator erase(iterator i);
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
iterator erase(iterator first, iterator last);
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
|
value_type const * c_str() const;
|
|
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
/* Note that this is STL compilant, so you can not assume
|
1999-10-02 16:21:10 +00:00
|
|
|
|
that the returned array has a trailing '\0'. */
|
|
|
|
|
value_type const * data() const;
|
|
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
/* This one returns a verbatim copy. Not the trailing '\0'
|
1999-10-02 16:21:10 +00:00
|
|
|
|
The caller must provide a buffer with engough room.
|
|
|
|
|
*/
|
1999-10-22 02:26:50 +00:00
|
|
|
|
size_type copy(value_type * buf, size_type len,
|
|
|
|
|
size_type pos = 0) const;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
2002-03-21 17:09:55 +00:00
|
|
|
|
int compare(lyxstring const & str) const;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
int compare(value_type const * p) const;
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
int compare(size_type pos, size_type n, lyxstring const & str) const;
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
int compare(size_type pos, size_type n, lyxstring const & str,
|
|
|
|
|
size_type pos2, size_type n2) const;
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
int compare(size_type pos, size_type n, value_type const * p,
|
|
|
|
|
size_type n2 = npos) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
///
|
|
|
|
|
lyxstring substr(size_type i = 0, size_type n = npos) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
private:
|
1999-10-23 23:35:37 +00:00
|
|
|
|
// These three operators can be used to discover erronous use of
|
|
|
|
|
// ints and strings. However a conforming C++ compiler will flag
|
1999-10-25 12:33:03 +00:00
|
|
|
|
// a lot of char operations as ambigous when they are compiled
|
1999-10-23 23:35:37 +00:00
|
|
|
|
// in. Use them for debugging only (or perhaps not even then.)
|
|
|
|
|
// Lgb.
|
|
|
|
|
//
|
|
|
|
|
//lyxstring & operator+(int);
|
|
|
|
|
//
|
|
|
|
|
//lyxstring & operator=(int);
|
|
|
|
|
//
|
|
|
|
|
//lyxstring & operator+=(int);
|
1999-11-05 06:02:34 +00:00
|
|
|
|
|
|
|
|
|
/// Compare this with s. works with embedded '\0' chars also.
|
|
|
|
|
int internal_compare(size_type pos, size_type n,
|
|
|
|
|
value_type const * s,
|
|
|
|
|
size_type slen, size_type n2) const;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-22 02:26:50 +00:00
|
|
|
|
/// Forward declaration of the string representation
|
|
|
|
|
struct Srep;
|
1999-10-25 12:33:03 +00:00
|
|
|
|
// DEC cxx requires this.
|
|
|
|
|
friend struct Srep;
|
1999-10-22 02:26:50 +00:00
|
|
|
|
|
|
|
|
|
/// A string is a pointer to it's representation
|
|
|
|
|
Srep * rep;
|
|
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
/* Note: The empty_rep is a local static in each function that
|
1999-10-02 16:21:10 +00:00
|
|
|
|
benefits from one. There is no "global" empty srep but lyxstring
|
|
|
|
|
doesn't need one (no code actually relies upon a single
|
|
|
|
|
empty srep).
|
|
|
|
|
This overcomes *all* "static initialization" problems,
|
|
|
|
|
at maximum speed, with a small overhead of a few local static
|
|
|
|
|
empty_reps.
|
1999-10-22 02:26:50 +00:00
|
|
|
|
*/
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
1999-12-16 14:16:42 +00:00
|
|
|
|
#ifdef ENABLE_ASSERTIONS
|
1999-10-02 16:21:10 +00:00
|
|
|
|
/// lyxstringInvariant is used to test the lyxstring Invariant
|
|
|
|
|
friend class lyxstringInvariant;
|
1999-10-22 02:26:50 +00:00
|
|
|
|
#endif
|
1999-10-02 16:21:10 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// The usual comparison operators ==, !=, >, <, >=, <= are
|
|
|
|
|
// provided for lyxstrings
|
|
|
|
|
|
|
|
|
|
bool operator==(lyxstring const &, lyxstring const &);
|
|
|
|
|
bool operator==(lyxstring::value_type const *, lyxstring const &);
|
|
|
|
|
bool operator==(lyxstring const &, lyxstring::value_type const *);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator!=(lyxstring const &, lyxstring const &);
|
|
|
|
|
bool operator!=(lyxstring::value_type const *, lyxstring const &);
|
|
|
|
|
bool operator!=(lyxstring const &, lyxstring::value_type const *);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator>(lyxstring const &, lyxstring const &);
|
|
|
|
|
bool operator>(lyxstring::value_type const *, lyxstring const &);
|
|
|
|
|
bool operator>(lyxstring const &, lyxstring::value_type const *);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator<(lyxstring const &, lyxstring const &);
|
|
|
|
|
bool operator<(lyxstring::value_type const *, lyxstring const &);
|
|
|
|
|
bool operator<(lyxstring const &, lyxstring::value_type const *);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator>=(lyxstring const &, lyxstring const &);
|
|
|
|
|
bool operator>=(lyxstring::value_type const *, lyxstring const &);
|
|
|
|
|
bool operator>=(lyxstring const &, lyxstring::value_type const *);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator<=(lyxstring const &, lyxstring const &);
|
|
|
|
|
bool operator<=(lyxstring::value_type const *, lyxstring const &);
|
|
|
|
|
bool operator<=(lyxstring const &, lyxstring::value_type const *);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Concatenation
|
|
|
|
|
|
|
|
|
|
lyxstring operator+(lyxstring const & a, lyxstring const & b);
|
|
|
|
|
lyxstring operator+(char const * a, lyxstring const & b);
|
|
|
|
|
lyxstring operator+(lyxstring::value_type a, lyxstring const & b);
|
|
|
|
|
lyxstring operator+(lyxstring const & a, lyxstring::value_type const * b);
|
|
|
|
|
lyxstring operator+(lyxstring const & a, lyxstring::value_type b);
|
|
|
|
|
|
1999-11-15 14:45:17 +00:00
|
|
|
|
void swap(lyxstring & s1, lyxstring & s2);
|
|
|
|
|
|
2000-04-06 09:17:40 +00:00
|
|
|
|
std::istream & operator>>(std::istream &, lyxstring &);
|
|
|
|
|
std::ostream & operator<<(std::ostream &, lyxstring const &);
|
|
|
|
|
std::istream & getline(std::istream &, lyxstring &, lyxstring::value_type delim = '\n');
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
|
|
#endif
|