Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Strings.h"
- Stringg::Stringg() {};
- Stringg::Stringg(const char* ss)
- {
- //*str = new char[MAX + 1];
- int i;
- for (i = 0; i < MAX && ss[i] != '\0'; i++)
- {
- str[i] = ss[i];
- }
- str[i] = '\0';
- len = i - 1;
- }
- Stringg::Stringg(const Stringg& ss)//////////////////////////////////
- {
- int i;
- for (i = 0; i < ss.len; i++)//<=
- {
- str[i] = ss.str[i];//
- }
- str[i] = '\0';
- len = ss.len;
- }
- int Stringg::Length()
- {
- /*int i = 0;
- len = 0;
- while (ss.str[i] != '\0')
- {
- len++;
- i++;
- }
- return len;*/
- if (str == 0)
- {
- len = 0;
- }
- else
- {
- int i;
- for (i = 0; str[i] != '\0'; i++);
- len = i;
- }
- return len;
- }
- void Stringg::clear()
- {
- delete str;
- len = 0;
- str = new char[1];
- str[0] = '\0';
- }
- void Stringg::get_str()
- {
- for (int i = 0; i < len; i++)
- {
- std::cout << str[i];
- }
- std::cout << std::endl;
- }
- Stringg& Stringg::operator=(Stringg ss)
- {
- this->len = ss.len;
- this->str = ss.str;
- return *this;
- }
- char Stringg::operator[](int i)
- {
- return str[i];
- }
- Stringg::~Stringg() {};
- String_ident::String_ident() {};
- String_ident::String_ident(const char* ss)
- {
- /*if (!(isalpha(ss[0])) || (ss[0] == '_'))//проходит в условие, даже если норм
- {
- len = 0;
- //ss = new char[1];
- ss = 0;
- }
- len = 0;
- for (int i = 0; i < MAX && ss[i] != '\0'; i++)
- {
- len++;
- }
- //len -= 1;
- strcpy(str, ss);*/
- if (!(isalpha(ss[0])) || (ss[0] == '_'))//проходит в условие, даже если норм
- {
- len = 0;
- //ss = new char[1];
- ss = 0;
- str = 0;
- return;
- }
- else
- {
- len = 0;
- for (int i = 0; i < MAX && ss[i] != '\0'; i++)
- {
- len++;
- }
- }
- //len -= 1;
- strcpy(str, ss);
- }
- String_ident::String_ident(const String_ident& ss) :Stringg(ss) {};
- void String_ident::to_upper()
- {
- //char ch;
- for (int i = 0; str[i] != '\0'; i++)
- {
- str[i] = toupper(str[i]);
- //ch = str[i];
- //str[i] = (char)toupper(ch);
- }
- }
- void String_ident::to_lower()
- {
- for (int i = 0; str[i] != '\0'; i++)
- {
- str[i] = tolower(str[i]);
- }
- }
- /*char**/int String_ident::str_chr(char c)
- {
- for (int i = 0; str[i] != '\0'; i++)
- {
- if (str[i] == c)
- return i;
- }
- return -1;
- }
- String_ident::~String_ident() {};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement