#include <lyxstring.h>
This is a permanent String class. It is modeled closely after the C++ STL 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.
Notes for usage:
When you declare an lyxstring, it is initially empty. There is no need to do things like lyxstring a= "";#, especially not in constructors.
If you want to use a default empty lyxstring as a parameter, use
void foo(lyxstring par = lyxstring()); // Correct#
rather than
void foo(lyxstring par = ""); // WRONG!# void foo(lyxstring par = 0); // WRONG!#
(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}
It is important that you declare lyxstring as const if possible, because some methods are much more efficient in const versions.
If you want to check whether a string is empty, do
if (foo.empty()) something right#
rather than something along the lines of
if (!foo) completely wrong#
When you want to copy an lyxstring, just do
lyxstring a, b = "String";# a = b; // That's it!#
not something like
lyxstring a, b = "String";# a = b.copy(); // This leaks. // and does not work either. #
The class automatically handles deep copying when required.
Definition at line 89 of file lyxstring.h.
|
|
Definition at line 114 of file lyxstring.h. |
|
|
Definition at line 103 of file lyxstring.h. |
|
|
Definition at line 109 of file lyxstring.h. |
|
|
Definition at line 112 of file lyxstring.h. |
|
|
Definition at line 97 of file lyxstring.h. |
|
|
Definition at line 100 of file lyxstring.h. |
|
|
Definition at line 106 of file lyxstring.h. Referenced by find, find_first_not_of, find_first_of, find_last_not_of, find_last_of, insert, length, max_size, lyx::string::Srep::replace, resize, lyx::string::Srep::resize, and rfind. |
|
|
Definition at line 94 of file lyxstring.h. Referenced by append, lyx::string::Srep::append, lyx::string::Srep::assign, insert, lyx::string::Srep::insert, operator=, lyx::string::Srep::push_back, replace, lyx::string::Srep::replace, lyx::string::Srep::resize, and lyx::string::Srep::Srep. |
|
|
string x;#.
Definition at line 402 of file lyxstring.C. Referenced by clear, and substr.
|
|
||||||||||||||||
|
Definition at line 410 of file lyxstring.C. References lyx::support::Assert, rep, and Srep.
|
|
||||||||||||
|
string x("abc", 2) -> "ab"#.
Definition at line 422 of file lyxstring.C. References lyx::support::Assert, npos, rep, and Srep.
|
|
|
Definition at line 435 of file lyxstring.C. References lyx::support::Assert, rep, and Srep.
|
|
||||||||||||
|
string(5, 'n') -> "nnnnn".
Definition at line 448 of file lyxstring.C. References lyx::support::Assert, npos, rep, and Srep.
|
|
||||||||||||||||
|
Definition at line 172 of file lyxstring.h. References begin, end, and push_back.
|
|
|
Definition at line 465 of file lyxstring.C. References lyx::string::Srep::ref, and rep.
|
|
||||||||||||
|
Definition at line 801 of file lyxstring.C. References lyx::string::Srep::append, lyx::string::Srep::get_own_copy, rep, and TeststringInvariant.
00802 {
00803 TeststringInvariant(this);
00804
00805 rep = rep->get_own_copy();
00806 rep->append(last - first, first);
00807 return *this;
00808 }
|
|
||||||||||||
|
Definition at line 788 of file lyxstring.C. References lyx::string::Srep::append, lyx::string::Srep::get_own_copy, rep, TeststringInvariant, and value_type.
00789 {
00790 TeststringInvariant(this);
00791
00792 value_type * tmp = new value_type[n];
00793 memset(tmp, c, n);
00794 rep = rep->get_own_copy();
00795 rep->append(n, tmp);
00796 delete[] tmp;
00797 return *this;
00798 }
|
|
|
Definition at line 781 of file lyxstring.C. References append, and lyx::support::Assert.
|
|
||||||||||||
|
Definition at line 769 of file lyxstring.C. References lyx::string::Srep::append, lyx::support::Assert, lyx::string::Srep::get_own_copy, rep, and TeststringInvariant.
00770 {
00771 Assert(p); // OURS!
00772 TeststringInvariant(this);
00773
00774 if (!*p || !n) return *this;
00775 rep = rep->get_own_copy();
00776 rep->append(n, p);
00777 return *this;
00778 }
|
|
||||||||||||||||
|
Definition at line 760 of file lyxstring.C. References append, lyx::support::Assert, and TeststringInvariant.
00761 {
00762 Assert(pos <= x.rep->sz); // STD!
00763 TeststringInvariant(this);
00764
00765 return append(x.substr(pos, n));
00766 }
|
|
|
Definition at line 749 of file lyxstring.C. References lyx::string::Srep::append, lyx::string::Srep::get_own_copy, rep, and TeststringInvariant. Referenced by append, and operator+=.
00750 {
00751 TeststringInvariant(this);
00752
00753 if (x.empty()) return *this;
00754 rep = rep->get_own_copy();
00755 rep->append(x.length(), x.rep->s);
00756 return *this;
00757 }
|
|
||||||||||||
|
Definition at line 653 of file lyxstring.C. References lyx::string::Srep::assign, lyx::string::Srep::get_own_copy, rep, and TeststringInvariant.
00654 {
00655 TeststringInvariant(this);
00656
00657 rep = rep->get_own_copy();
00658 rep->assign(last - first, first);
00659 return *this;
00660 }
|
|
||||||||||||
|
Definition at line 643 of file lyxstring.C. References lyx::string::Srep::assign, lyx::string::Srep::get_own_copy, rep, and TeststringInvariant.
00644 {
00645 TeststringInvariant(this);
00646
00647 rep = rep->get_own_copy();
00648 rep->assign(n, ch);
00649 return *this;
00650 }
|
|
|
Definition at line 634 of file lyxstring.C. References lyx::support::Assert, assign, and TeststringInvariant.
00635 {
00636 Assert(s); // OURS!
00637 TeststringInvariant(this);
00638
00639 return assign(s, strlen(s));
00640 }
|
|
||||||||||||
|
Definition at line 619 of file lyxstring.C. References lyx::support::Assert, lyx::string::Srep::assign, npos, lyx::string::Srep::ref, rep, Srep, and TeststringInvariant.
|
|
||||||||||||||||
|
Definition at line 610 of file lyxstring.C. References lyx::support::Assert, assign, and TeststringInvariant.
00611 {
00612 Assert(pos <= x.rep->sz); // STD!
00613 TeststringInvariant(this);
00614
00615 return assign(x.substr(pos, n));
00616 }
|
|
|
Definition at line 599 of file lyxstring.C. References lyx::string::Srep::ref, rep, and TeststringInvariant. Referenced by assign, and operator=.
00600 {
00601 TeststringInvariant(this);
00602
00603 x.rep->ref++; // protect against ``st = st''
00604 if (--rep->ref == 0) delete rep;
00605 rep = x.rep; // share representation
00606 return *this;
00607 }
|
|
|
checked access.
Definition at line 700 of file lyxstring.C. References lyx::support::Assert, lyx::string::Srep::get_own_copy, rep, lyx::string::Srep::s, and TeststringInvariant.
00701 {
00702 Assert(n < rep->sz); // STD!
00703 TeststringInvariant(this);
00704
00705 rep = rep->get_own_copy();
00706 return rep->s[n];
00707 }
|
|
|
checked access.
Definition at line 693 of file lyxstring.C. References lyx::support::Assert, rep, and lyx::string::Srep::s.
|
|
|
Definition at line 481 of file lyxstring.C. References rep, and lyx::string::Srep::s.
|
|
|
Definition at line 474 of file lyxstring.C. References lyx::string::Srep::get_own_copy, rep, and lyx::string::Srep::s. Referenced by erase, insert, replace, and string.
00475 {
00476 rep = rep->get_own_copy();
00477 return rep->s;
00478 }
|
|
|
Definition at line 1448 of file lyxstring.C. References length, rep, and lyx::string::Srep::s.
|
|
|
size of the memory (in number of elements) allocated.
Definition at line 546 of file lyxstring.C. References rep, and lyx::string::Srep::res.
|
|
|
Definition at line 470 of file lyxstring.h. References erase, npos, and string.
|
|
||||||||||||||||||||
|
Definition at line 1541 of file lyxstring.C. References lyx::support::Assert, internal_compare, and TeststringInvariant.
01543 {
01544 Assert(s && pos <= rep->sz); // OURS!
01545 TeststringInvariant(this);
01546 return internal_compare(pos, n, s, (!s) ? 0 : strlen(s), n2);
01547 }
|
|
||||||||||||||||||||||||
|
Definition at line 1529 of file lyxstring.C. References lyx::support::Assert, internal_compare, and TeststringInvariant.
01531 {
01532 Assert(pos <= rep->sz); // OURS!
01533 Assert(pos2 <= str.rep->sz); // OURS!
01534 TeststringInvariant(this);
01535 return internal_compare(pos, n,
01536 str.rep->s + pos2,
01537 str.rep->sz - pos2, n2);
01538 }
|
|
||||||||||||||||
|
Definition at line 1520 of file lyxstring.C. References lyx::support::Assert, internal_compare, and TeststringInvariant.
01522 {
01523 Assert(pos <= rep->sz); // OURS!
01524 TeststringInvariant(this);
01525 return internal_compare(pos, n, str.rep->s, str.rep->sz, str.rep->sz);
01526 }
|
|
|
Definition at line 1511 of file lyxstring.C. References lyx::support::Assert, internal_compare, rep, lyx::string::Srep::sz, and TeststringInvariant.
01512 {
01513 Assert(s); //OURS!
01514 TeststringInvariant(this);
01515 int n = (!s) ? 0 : strlen(s);
01516 return internal_compare(0, rep->sz, s, n, n);
01517 }
|
|
|
Definition at line 1503 of file lyxstring.C. References internal_compare, rep, lyx::string::Srep::sz, and TeststringInvariant.
01504 {
01505 TeststringInvariant(this);
01506 return internal_compare(0, rep->sz, str.rep->s,
01507 str.rep->sz, str.rep->sz);
01508 }
|
|
||||||||||||||||
|
Definition at line 1461 of file lyxstring.C. References lyx::support::Assert, length, rep, lyx::string::Srep::s, and TeststringInvariant.
|
|
|
Definition at line 1455 of file lyxstring.C. References rep, and lyx::string::Srep::s.
|
|
|
Definition at line 192 of file lyxstring.h. References size. Referenced by createInset, initSymbols, InsetBibitem::InsetBibitem, and isEndOfData.
00192 { return size() == 0; }
|
|
|
Definition at line 494 of file lyxstring.C. References rep, lyx::string::Srep::s, and lyx::string::Srep::sz.
|
|
|
Definition at line 487 of file lyxstring.C. References lyx::string::Srep::get_own_copy, rep, lyx::string::Srep::s, and lyx::string::Srep::sz. Referenced by string.
|
|
||||||||||||
|
Definition at line 1435 of file lyxstring.C. References begin, erase, and TeststringInvariant.
01436 {
01437 TeststringInvariant(this);
01438
01439 erase(first - begin(), last - first);
01440 return begin(); // BUG
01441 }
|
|
|
Definition at line 1424 of file lyxstring.C. References begin, erase, and TeststringInvariant.
01425 {
01426 TeststringInvariant(this);
01427
01428 // what iterator is this supposed to return?
01429 // the iterator after the one erased
01430 erase(i - begin(), 1);
01431 return begin(); // BUG
01432 }
|
|
||||||||||||
|
Erase n chars from position i.
Definition at line 1407 of file lyxstring.C. References lyx::support::Assert, lyx::string::Srep::get_own_copy, rep, lyx::string::Srep::s, lyx::string::Srep::sz, and TeststringInvariant. Referenced by clear, and erase.
01408 {
01409 Assert(i <= rep->sz); // STD!
01410 TeststringInvariant(this);
01411
01412 rep = rep->get_own_copy();
01413 if (i == 0 && n >= rep->sz) {
01414 rep->sz = 0;
01415 } else {
01416 n = min(n, rep->sz - i);
01417 memmove(&(rep->s[i]), &(rep->s[i + n]), rep->sz - i - n);
01418 rep->sz -= n;
01419 }
01420 return *this;
01421 }
|
|
||||||||||||
|
Definition at line 972 of file lyxstring.C. References npos, rep, lyx::string::Srep::s, size_type, lyx::string::Srep::sz, and TeststringInvariant.
|
|
||||||||||||
|
Definition at line 960 of file lyxstring.C. References lyx::support::Assert, find, npos, rep, lyx::string::Srep::sz, and TeststringInvariant.
|