~vbursian/research-assistant/intervers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
////////////////////////////////////////////////////////////////////////////////
/*! @file String.h   Class sString and related.
- Part of RANet - Research Assistant Net Library.
- Copyright(C) 1994-2017, Viktor E. Bursian, St.Petersburg, Russia.
                          VBursian@gmail.com
*///////////////////////////////////////////////////////////////////////////////
#ifndef Strings_H
#define Strings_H
#include "General.h"
#include <iostream>
#include <utility>
namespace RA {
//------------------------------------------------------------------------------

ANNOUNCE_CLASS(sString)

//std::ostream &  operator << (std::ostream &  ,rcsString);
//std::istream &  operator >> (std::istream &  ,rsString);

//using namespace std::rel_ops; NEVER EVER USE using IN HEADERS!!!

//------------------------------------------------------------------ sString ---
/*! A string class specific for RANet.

@note It is not intended to be a universal string class, rather, it is
      a string class with minimal interface as required by RANet.

@par Why not @c std::string or QString or QByteArray?
-# It appeared in my texts when the @c string template was not yet
   in C++ standard, and also way before Qt was born.
-# I wish to keep the very basics of RANet independent from a third party
   non-standard library, like Qt. (However, it should probably be rewritten
   with, say, C++11 std::u16string).
-# It has some specific features; so, I would anyway need at least a thin
   wrapper over a standard string.

@bug Some of its functionality works bad with UTF-8 strings (allthough, one
can initialize sString with a UTF-8 literal). Same applies to the null chars
inside the string (allthough, they can be put into sString's body
programmaticaly).
*/
class RANet_EXPORT  sString
{
  public://static
    static sString            FromReal (real                number
                                       ,unsigned short int  digits_after_dot);
    static sString            FromInteger (integer  number);

  public:
    virtual                   ~sString ();
                              sString ();
                              sString (rcsString);
                              sString (literal);
                              sString (char);
    bool                      Empty () const;
    size_t                    Length () const;
//    char                      operator [] (size_t) const; //first char index==0
    char                      operator [] (int) const; //first char index==0
    /*!< @todo{elegancy} op[] must return char& ? */
//                              operator literal () const;
                              operator ptr_to_const_char () const;
    sString                   Substr (size_t from ,size_t length) const;
    sString                   Tail (size_t from) const;
    size_t                    Pos (rcsString) const;
    size_t                    Pos (literal) const;
    rsString                  operator =  (rcsString);
    rsString                  operator =  (literal);
    sString                   operator + (rcsString) const;
    sString                   operator + (literal) const;
//    sString                   operator + (char) const;
    rsString                  operator += (rcsString);
    rsString                  operator += (literal);
    rsString                  operator += (const char);
    rsString                  operator << (integer);
//    rsString                  operator << (const int);
//    rsString                  operator << (const unsigned int);
//    rsString                  operator << (const long int);
//    rsString                  operator << (const unsigned long int);
    rsString                  operator << (real);
//    rsString                  operator << (const double);
    rsString                  operator >> (integer &);
    rsString                  operator >> (real &);
    bool                      operator == (rcsString) const;
    bool                      operator == (literal) const;
    bool                      operator != (rcsString) const;
    bool                      operator != (literal) const;
    bool                      operator < (rcsString) const;
    /*!< @todo{elegancy}  ==(char)  <,>,<=,>=  >>int/float */
    sString                   UpperCase () const;
    sString                   Trim () const;
    sString                   TrimSyntactic (literal Delimiters
                                                     = DefaultDelimiters) const;
    sString                   Translate (char O ,char N) const;
    void                      EatLeadingSpaces ();
    int                       WipeOut (literal  substring
                                      ,bool     only_first = false);
    int                       Replace (literal  substring
                                      ,literal  replacement
                                      ,bool     only_first = false);
    virtual void              Read (std::istream &);
    virtual void              Write (std::ostream &) const;
//    virtual void              InputTextLine (std::istream &);
  protected:
    void                      SetValue (literal);

  private: //fields
    char *                    Body;
    size_t                    CurrentLength;
//    size_t                    CurrentSpace;

  private: //constants
    static literal           EmptyLiteral;
    static literal           DefaultDelimiters;
    static const sString     PlusInfinity;
    static const sString     MinusInfinity;
};


inline  rsString  sString::operator =  (literal V)
{
  SetValue(V); return *this;
}


inline  bool  sString::operator != (rcsString S) const
{
  return !( operator==(S) );
}


inline  bool  sString::operator != (literal L) const
{
  return !( operator==(L) );
}


inline  rsString  sString::operator << (integer  number)
{
  operator+=( FromInteger(number) );
  return *this;
}


//inline  std::ostream &  operator<< (std::ostream & a_stream ,rcsString a_string)
//{
//  a_string.Write(a_stream);
//  return  a_stream;
//}

//inline  std::istream &  operator>> (std::istream & a__stream ,rsString a_string)
//{
//  a_string.Read(a__stream);
//  return  a__stream;
//}

//------------------------------------------------------------------------------
} //namespace RA
#endif