⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 strings.hpp

📁 SecurityLib一个user-rights系统控件
💻 HPP
📖 第 1 页 / 共 2 页
字号:
		}

		string mid(word start=0) const {
			word ile=len()-start;
			string out=ile;
			memcpy(out,s+start,ile);
			return out;
		}
		string &mid_(word start=0) {
			word ile=len()-start;
			string out=ile;
			memcpy(out,s+start,ile);
			swap(out);
			return *this;
		}

		string get(word skad) const {
			word dokad=len();
			if (skad>dokad || !len()) return string();
			string out=word(dokad-skad+1);
			memcpy(out,s+skad,dokad-skad+1);
			return out;
		}
		string &get_(word skad) {
			word dokad=len();
			if (skad>dokad) return *this=string();
			string out=word(dokad-skad+1);
			memcpy(out,s+skad,dokad-skad+1);
			swap(out);
			return *this;
		}

		string left(word ile) const {
			string out=ile;
			memcpy(out,s,ile);
			return out;
		}
		string &left_(word ile) {
			string out=ile;
			memcpy(out,s,ile);
			swap(out);
			return *this;
		}

		string right(word ile) const  {
			string out=ile;
			memcpy(out,s+len()-ile,ile);
			return out;
		}
		string &right_(word ile) {
			string out=ile;
			memcpy(out,s+len()-ile,ile);
			swap(out);
			return *this;
		}

		string leftr(word ile) const {
			string out=word(len()-ile);
			memcpy(out,s,len()-ile);
			return out;
		}
		string &leftr_(word ile) {
			string out=word(len()-ile);
			memcpy(out,s,len()-ile);
			swap(out);
			return *this;
		}

		string rightr(word ile) const  {
			string out=word(len()-ile);
			memcpy(out,s+ile,len()-ile);
			return out;
		}
		string &rightr_(word ile) {
			string out=word(len()-ile);
			memcpy(out,s+ile,len()-ile);
			swap(out);
			return *this;
		}

		string put(word w,const string &co,word odkad=0,word ile=65535u) const {
			if (ile==65535u) ile=len()-w<co.len()-odkad?len()-w:co.len()-odkad;
			string out=*this;
			memcpy(out+w,co+odkad,ile);
			return out;
		}
		string &put_(word w,const string &co,word odkad=0,word ile=65535u) {
			if (ile==65535u) ile=len()-w<co.len()-odkad?len()-w:co.len()-odkad;
			memcpy(s+w,co+odkad,ile);
			return *this;
		}

		string fill(char czym,word w=0,word ile=65535u) const {
			if (ile==65535u) ile=len()-w;
			string out=*this;
			memset(out+w,czym,ile);
			return out;
		}
		string &fill_(char czym,word w=0,word ile=65535u) {
			if (ile==65535u) ile=len()-w;
			memset(s+w,czym,ile);
			return *this;
		}

		string &del(word w=0,word ile=65535u) {
			if (ile==65535u) ile=len()-w;
			string out=word(len()-ile);
			memcpy(out,s,w);
			memcpy(out+w,s+w+ile,len()-ile-w);
			swap(out);
			return *this;

		}
		string &cut(word w=0,word dokad=65535u) {
			if (dokad==65535u) dokad=len();
			string out=word(len()-dokad+w-1);
			memcpy(out,s,w);
			memcpy(out+w,s+dokad+1,len()-dokad+w-1);
			swap(out);
			return *this;
		}

		string &operator=(const string &co) {
			if (&co!=this) {
				delete s;
				check(s=new char[co.len()+1]);
				strcpy(s,co);
			}
			return *this;
		}

		string &operator=(const char *co) {
			delete s;
			check(s=new char[strlen(co)+1]);
			memcpy(s,co,strlen(co)+1);
			return *this;
		}


		bool operator==(const string &co) const { return !strcmp(s,co); }
		bool operator!=(const string &co) const { return  strcmp(s,co); }
		bool operator==(const char *co) const { return !strcmp(s,co); }
		bool operator!=(const char *co) const { return  strcmp(s,co); }

		string operator+(const string &co) const {
			string out=word(co.len()+len());
			memcpy(out,s,len());
			memcpy(out+len(),co,co.len());
			return out;
		}
		string &operator+=(const string &co) {
			string out=word(co.len()+len());
			memcpy(out,s,len());
			memcpy(out+len(),co,co.len());
			swap(out);
			return *this;
		}

		string operator-(word ile) const {
			string out=word(len()-ile);
			memcpy(out,s,len()-ile);
			return out;
		}
		string &operator-=(word ile) {
			string out=word(len()-ile);
			memcpy(out,s,len()-ile);
			swap(out);
			return *this;
		}

		char& operator[](word co) const { return s[co]; }

		char *operator+(word co) const { return s+co; }

		string operator()(word tart,word ile) const { return mid(tart,ile); }

		friend string   operator+ (const string &co,const char *co2);
		friend string   operator+ (const char *co,const string &co2);

		friend ostream& operator<<(ostream &out,const string &co) ;
		friend istream& operator>>(istream &in,string& co);

		friend bool operator==(const char *co,const string &co2);
		friend bool operator!=(const char *co,const string &co2);

		friend word operator-(char *, const string &);
		friend word operator-(const string &, char *);

		word operator-(const string &co) { return s-co.s; }

		//operator word () const;

		static string *newobject(word ile=1) { return check(new string[ile]); }

};

inline word operator-(char *co, const string &w) { return co-w.s; }
inline word operator-(const string &co, char *w) { return co.s-w; }


inline bool operator==(const char *co,const string &co2) { return !strcmp(co,co2); }
inline bool operator!=(const char *co,const string &co2) { return  strcmp(co,co2); }


inline string str(const dword co,byte radix=10) {
	string out(word(32u));
	ultoa(co,out,radix);
	return out.left(out.len());
}

inline string str(const long co,byte radix=10) {
	string out(word(32u));
	ltoa(co,out,radix);
	return out.left(out.len());
}

inline string str(const int co,byte radix=10) {
	string out(word(32u));
	itoa(co,out,radix);
	return out.left(out.len());
}

#undef s


	/*
		err
		0 - brak
		1 - b垾d alokacji
	*/


template<word size> class smallstr {
	public:

		class proplen {
			friend smallstr<size>;
			private:
				char s[size +1];

			public:
				proplen() {}

				operator word()   { return strlen(s); }
				word operator()() { return strlen(s); }
		} len;

		#define str (len.s)

		smallstr() { *str=0; }

		#ifdef __BCPPB__
		template <word s2>
			smallstr(const smallstr<s2> &co) {
				strncpy(str, co, size)[size]=0;
			}
		#endif

		smallstr(const string &co) {
			strncpy(str, co, size)[size]=0;
		}

		smallstr(const char *co) {
			strncpy(str, co, size)[size]=0;
		}

	#ifdef DSTRING_H
		template<word s2>
			smallstr(const SmallString<s2> &co) {
				if (!memccpy(str, &co[0], 0, size))
					str[size] = 0;
			}

		smallstr(const AnsiString &co) {
			strncpy(str, co.c_str(), size)[size]=0;
		}

		operator AnsiString() const {
			return AnsiString(str);
		}

		template<word s2>
			operator SmallString<s2>() const {
				return SmallString(str);
			}


		operator Variant() const{ return Variant(str); }

		bool operator==(const AnsiString &co) const { return !strcmp(str, co.c_str() ); }
		bool operator!=(const AnsiString &co) const { return  strcmp(str, co.c_str() ); }


	#endif

	#ifdef __BCPPB__
		template<word s2>
			smallstr<size> &operator=(const smallstr<s2> &co) {
				if (&co != this)
					strncpy(str, co, size)[size]=0;

				return me;
			}
	#endif

		smallstr<size> &operator=(const string &co) {
			strncpy(str, co, size)[size]=0;

			return me;
		}

		smallstr<size> &operator=(const char *co) {
			if (co != str) strncpy(str, co, size)[size] = 0;
			return me;
		}


		char& operator[](word co) const { return (char &)str[co]; }
		char& operator*() const { return *(char *)str; }
		operator char *() const { return (char *)str; }


		#ifdef __BCPPB__
		template<word s2>
			bool operator==(const smallstr<s2> &co) const { return !strcmp(str, co); }
		template<word s2>
			bool operator!=(const smallstr<s2> &co) const { return !strcmp(str, co); }
		#endif

		bool operator==(const string &co) const { return !strcmp(str, co); }
		bool operator!=(const string &co) const { return  strcmp(str, co); }

		bool operator==(const char *co) const { return !strcmp(str, co); }
		bool operator!=(const char *co) const { return  strcmp(str, co); }

		smallstr<size> operator+(const char *co) {
			smallstr<size> out = me;
			dword sz = strlen(str);
			strncpy(out.len.s + sz, co, size - sz);
			out.len.s[size]=0;
			return out;
		}

		#undef str

		static word ssize() { return size; }

};

typedef smallstr<16> smallstr16;
typedef smallstr<32> smallstr32;
typedef smallstr<64> smallstr64;
typedef smallstr<50> smallstr50;
typedef smallstr<255> smallstr255;



template<word size> class pswdsstr /*: public smallstr<size> */ /* ctors do not work */ {
	private:
		char s[size+1];
	public:
		word len() const { return strlen(s); }
		word ssize() const { return size; }

		operator char *&() const { return (char *&)s; }

		pswdsstr()/* : smallstr<size>() */ {}

		#ifdef __BCPPB__
/*		template <word s2>
			pswdsstr(const smallstr<s2> &co) : smallstr<size>(co) {
//				word l = len(); memset(me + l, 0, size - l +1);
			}
		template <word s2>
			pswdsstr(const pswdsstr<s2> &co) {
				memcpy(me, co, size+1);
			}*/
		#endif
		pswdsstr(const pswdsstr<size> &co) {
			memcpy(me, co, size+1);
		}

		pswdsstr(const char *co) {
			strncpy(me, co, size)[size]=0;
		}


/*		pswdsstr(const string &co) : smallstr<size>(co) {
//			word l = len(); memset(me + l, 0, size - l +1);
		}

		pswdsstr(const char *co) {
			memcpy(me, co, size+1);
//			word l = len(); memset(me + l, 0, size - l +1);
		}

		#ifdef DSTRING_H
		template<word s2>
			pswdsstr(const SmallString<s2> &co) : smallstr<size>(co) {
//				word l = len(); memset(me + l, 0, size - l +1);
			}

		pswdsstr(const AnsiString &co) : smallstr<size>(co) {
//			word l = len(); memset(me + l, 0, size - l +1);
		}
		#endif*/

		#ifdef __BCPPB__
		template<word s2>
			bool operator==(const pswdsstr<s2> &co) const { return !memcmp(me, co, size+1); }
		template<word s2>
			bool operator!=(const pswdsstr<s2> &co) const { return  memcmp(me, co, size+1); }
		#endif
		bool operator==(const char *co) const { return !strcmp(me, co); }
		bool operator!=(const char *co) const { return  strcmp(me, co); }

		#ifdef __BCPPB__
		template<word s2>
			pswdsstr<size> &operator=(const pswdsstr<s2> &co) {
				memcpy(me, co, size+1);
				return me;
			}
		#endif
		pswdsstr<size> &operator=(const pswdsstr<size> &co) {
			memcpy(me, co, size+1);
			return me;
		}
		pswdsstr<size> &operator=(const char *co) {
			memcpy(me, co, size+1);
			return me;
		}

};


#ifdef __BCPPB__
} // namespace mar

using namespace mar;

#endif

#ifdef __BCPPB__
#	pragma option pop
#else
#	pragma warn .sig
#endif

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -