-
Notifications
You must be signed in to change notification settings - Fork 0
/
STR_W.HPP
126 lines (90 loc) · 4.48 KB
/
STR_W.HPP
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
/*==================================================== The Beginning of the Copyright Notice=================================================
' The AUTHOR of this file is Alexander Borisovich Prokopyev born on December 20,1977 resident at Uritskogo str., Kurgan, Russia
' More info can be found at the AUTHOR's website: http://www.aulix.com/resume
' Contact: alexander.prokopyev at aulix dot com
' Copyright (c) Alexander B. Prokopyev, 1995
' Copyright notice improved in 2021
'
' All materials contained in this file are protected by copyright law.
' Nobody except the AUTHOR may alter or remove this copyright notice from copies of the content.
'
' The AUTHOR explicitly prohibits to use this content by any method without a prior authentic written hand-signed permission of the AUTHOR.
'================================= The End of the Copyright Notice ========================================================================*/
/***************************************************************************
* Êëàññ äëÿ ðàáîòû ñî ñòðîêàìè *
* (c) Ïðîêîïüåâ À. 7.03.95 *
***************************************************************************/
#include <stdlib.h>
#include <math.h>
//#include <ctype.h>
#include <iostream.h>
#include <conio.h>
//#include <windows.h>
#include <string.h>
#include <mem.h>
#if !defined(__STR_H)
#define __STR_H
// Êëàññ äëÿ ðàáîòû ñî ñòðîêàìè
class Str
{
protected:
char *place; // Óêàçàòåëü íà ñòðîêó
size_t place_len;
public:
Str(const char *st="",size_t len_=unsigned(-1)); // Êîíñòðóêòîð èíèöèàëèçàöèè îò char*
Str(const Str &str); // Êîñòðóêòîð êîïèðîâàíèÿ
Str& Str::operator =( const Str& sourceStr ); //Îïåðàòîð êîïèðîâàíèÿ
virtual ~Str() { delete place; }
size_t len() { return place_len-1; } // Äëèíà ñòðîêè
const char* st() { return place; }
void resize(size_t new_len);
char& operator[](size_t ind); // Äîñòóï ê ñèìâîëàì ñòðîêè
Str operator+(Str &str); // Êîíêàòåíàöèÿ ñòðîê
Str& operator+=(Str &str) // Ïðèñîåäèíåíèå äðóãîé ñòðîêè ê äàííîé
{ return *this=*this+str; }
Str mid(size_t beg, size_t count=unsigned(-1)); // Âîçâðàùàåò count ñèìâîëîâ, íà÷èíàÿ ñ beg
// Çàìåíÿåò count ñèìâîëîâ, íà÷èíàÿ ñ beg íà str
Str &mid(size_t beg, size_t count, Str &str);
// Ïîçèöèÿ âõîæäåíèÿ ñòðîêè str â äàííóþ
long inStr(size_t start, Str &str);
// Âñòàâëëëÿåò str, íà÷èíàÿ ñ beg
void ins(size_t beg,Str &str); // Âñòàâëÿåò ñòðîêó str, íà÷èíàÿ ñ beg
// Óäàëÿåò èç äàííîé ñòðîêè count ñèìâîëîâ, íà÷èíàÿ ñ beg
void del(size_t beg, size_t count);
Str left(int count); // Âîçâðàùàåò count ëåâûõ ñèìâîëîâ äàííîé ñòðîêè
Str right(int count); // Âîçâðàùàåò count ïðàâûõ ñèìâîëîâ äàííîé ñòðîêè
void lTrimSelf(); // Óäàëÿåò ëåâûå ïðîáåëû
void rTrimSelf(); // Óäàëÿåò ïðàâûå ïðîáåëû
// Óäàëÿåò ïðîáåëû ñïðàâà è ñëåâà
void TrimSelf() { lTrimSelf(); rTrimSelf(); }
//Âîçâðàùàåò ñòðîêó ñ óäàëåííûìè ëåâûìè ïðîáåëàìè
Str lTrim();
//Âîçâðàùàåò ñòðîêó ñ óäàëåííûìè ïðîáåëàìè ïðîáåëàìè
Str rTrim();
//Âîçâðàùàåò ñòðîêó ñ óäàëåííûìè ëåâûìè è ïðàâûìè ïðîáåëàìè
Str Trim();
// Äîïîëíÿåò äàííóþ ñòðîêó äî äëèíû newSize, äîáàâëÿÿ ñëåâà ñèìâîëû padCh
void lPadSelf(size_t newSize, char padCh=' ');
// Äîïîëíÿåò äàííóþ ñòðîêó äî äëèíû newSize, äîáàâëÿÿ ñïðàâà ñèìâîëû padCh
void rPadSelf(size_t newSize, char padCh=' ');
// Äîïîëíÿåò äàííóþ ñòðîêó äî äëèíû newSize,
// äîáàâëÿÿ ñèììåòðè÷íî ñëåâà è ñïðàâà ñèìâîëû padCh
void padSelf(size_t newSize, char padCh=' ');
// Òî æå, ÷òî padLSelf, íî äîïîëíåííóþ ñòðîêó âîçâðàùàåò
Str lPad(size_t newSize, char padCh=' ');
// Òî æå, ÷òî padLSelf, íî äîïîëíåííóþ ñòðîêó âîçâðàùàåò
Str rPad(size_t newSize, char padCh=' ');
// Òî æå, ÷òî padCSelf, íî äîïîëíåííóþ ñòðîêó âîçâðàùàåò
Str pad(size_t newSize, char padCh=' ');
// Ïðèñâàèâàåò äàííîé ñòðîêå ïðåäñòàâëåíèå ÷èñëà value,
// ãäå ndig - îáùåå êîëè÷åñòâî ñèìâîëîâ â ôîðìèðóåìîé ñòðîêå
Str &str(double value, unsigned short ndig=10);
// Ïðåîáðàçóåò äàííóþ ñòðîêó â ÷èñëî
double val() { return atof(st()); }
int words(); // Âîçâðàùàåò êîë-âî ñëîâ â ñòðîêå
Str word(int needW); // Âîçâðàùàåò needW-îå ñëîâî, åñëè íå íàõîäèò, òî ""
static Str space(size_t count) { return string(count,' '); }
static Str string(size_t count, char fillCh=' ');
};
istream& operator>>(istream& i, Str& str); // Ââîäèò ñòðîêó èç ïîòîêà
#endif