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

📄 superstr.h

📁 用bcg库编写的java IDE 源码
💻 H
📖 第 1 页 / 共 3 页
字号:
	SS& toUpper ();
	SS& toUpper (int pos);

	SS toHex     () const;
	SS fromHex   () const;
	SS outputHex () const;  // pretty print in hex

	SS trim () const;
	SS dup (int n=1) const; // new string of n copies

	char* extract ();       // take over memory management of rep

	long hash () const;

	SS& become (SS& s);     // arg is left as ""
	SS& swap   (SS& s);
	SS& swap   (int pos0, int pos1);

	static void copy     (void       * dst, void const * src, int n);
	static void copy     (void       * dst, int l0, void const * src, int l1);
	static int  compare  (void const * bf0, void const * bf1, int n);
	static int  compare  (void const * bf0, int l0, void const * bf1, int l1);
	static void fill     (void       * dst, char c, int n);
	static int  findNext (void const * dat, char c, int n);

	// zero out arbitrary object
	template <class T>
	static inline void zero       (T& t) { SS::fill (&t, nullchar, sizeof(T)); }
	template <class T>
	static inline void fillObject (T& t, char c) { SS::fill (&t, c, sizeof(T)); }
	template <class T>
	static inline SS   fromObject (T& t) { SS ss; return ss.assignFromObject (t); }

	// beg refers to string object
	SS const & copyTo     (void* dst, int n=fullength, int beg=0) const;
	SS       & copyFrom   (void* src, int n=fullength, int beg=0);  // won't extend string
	SS       & assignFrom (void* src, int n);                       // reassigns string
	template <class T>
	SS const & copyToObject     (T& t, int beg=0) const {return copyTo    (&t, sizeof(T), beg);}
	template <class T>
	SS       & copyFromObject   (T& t, int beg=0)       {return copyFrom  (&t, sizeof(T), beg);}
	template <class T>
	SS       & assignFromObject (T& t)                  {return assignFrom(&t, sizeof(T));     }

	static SS concatenate (SS const & u, SS const & w);
	static SS concatenate (std::vector<SS>& s);

	static long hash (void const * v, int n);
	static int  strLen (char const * s);
	static int  strLen (signed char const * s);
	static int  strLen (unsigned char const * s);

	static bool upperP     (char c);
	static bool lowerP     (char c);
	static bool whiteP     (char c);
	static bool blackP     (char c);
	static bool alphaP     (char c);
	static bool digitP     (char c);
	static bool alphanumP  (char c);
	static bool punctP     (char c);
	static bool printableP (char c);
	static bool hexDigitP  (char c);
	static bool cntrlP     (char c);
	static bool graphP     (char c);

	static void to_lower (char& c);
	static void to_upper (char& c);
	static char getLower (char c);
	static char getUpper (char c);

	// allow conversions to be added by user and explicitly invoked
	template <class T>
	inline static SS toSS (T const & t) { SS s; SSconvert (t,s); return s; }

	template <class T>
	SS const & toType (T & t) const { SSconvertFrom (*this,t); return *this; }

	// number conversions
	bool           toBool      ()         const;
	short          toShort     ()         const;
	unsigned short toUShort    ()         const;
	int            toInt       ()         const;
	unsigned int   toUInt      ()         const;
	long           toLong      ()         const;
	unsigned long  toULong     ()         const;
	LongLong       toLongLong  ()         const;
	ULongLong      toULongLong ()         const;
	short          toShort     (int base) const;
	unsigned short toUShort    (int base) const;
	int            toInt       (int base) const;
	unsigned int   toUInt      (int base) const;
	long           toLong      (int base) const;
	unsigned long  toULong     (int base) const;
	LongLong       toLongLong  (int base) const;
	ULongLong      toULongLong (int base) const;
	float          toFloat     ()         const;
	double         toDouble    ()         const;
	long double    toLongDouble()         const;

	string         toString    ()         const;
	std::vector<char> toVector ()         const;

	void toInteger (short          & number) const;
	void toInteger (unsigned short & number) const;
	void toInteger (int            & number) const;
	void toInteger (unsigned int   & number) const;
	void toInteger (long           & number) const;
	void toInteger (unsigned long  & number) const;
	void toInteger (LongLong       & number) const;
	void toInteger (ULongLong      & number) const;
	void toInteger (short          & number, int base) const;
	void toInteger (unsigned short & number, int base) const;
	void toInteger (int            & number, int base) const;
	void toInteger (unsigned int   & number, int base) const;
	void toInteger (long           & number, int base) const;
	void toInteger (unsigned long  & number, int base) const;
	void toInteger (LongLong       & number, int base) const;
	void toInteger (ULongLong      & number, int base) const;

	static SS toBase (short          number, int base=10);
	static SS toBase (unsigned short number, int base=10);
	static SS toBase (int            number, int base=10);
	static SS toBase (unsigned int   number, int base=10);
	static SS toBase (long           number, int base=10);
	static SS toBase (unsigned long  number, int base=10);
	static SS toBase (LongLong       number, int base=10);
	static SS toBase (ULongLong      number, int base=10);

	static SS sprint (const char * fmt, ...);

	// exceptions that can be thrown
#ifndef SS_STANDALONE
	typedef Urror Error;
	typedef UrrorBadArg ErrorBadArg;
	typedef UrrorBadState ErrorBadState;
	typedef UrrorNumberFormat ErrorNumberFormat;
	typedef UrrorOutOfRange ErrorOutOfRange;
	typedef UrrorOverflow ErrorOverflow;
	typedef UrrorNotFound ErrorNotFound;
#else
	class Error {
	  public:
		Error (SS const & s) : _s(s) { }
		char const * what() const { return *_s; }
	  private:
		SSCopyPointer _s;
	};
	typedef Error ErrorBadArg;
	typedef Error ErrorBadState;
	typedef Error ErrorNumberFormat;
	typedef Error ErrorOutOfRange;
	typedef Error ErrorOverflow;
	typedef Error ErrorNotFound;
#endif

	// see if args are positive and in range
	bool verify (int ind) const;
	bool verify (int beg, int len) const;
	// these aren't part of the api but are needed in the impl
	void adjust (int& beg, int& len) const;  // adjusts beg and len to fit
	void adjust (Pair<int>& beglen)  const;
	static bool alreadySorted (std::vector<int> const & v);
	static bool alreadySorted (std::vector< Pair<int> > const & v);
	static void sortBegLenVect (std::vector<int> const & v, std::vector<int> & o);
	static void sortBegLenVect (std::vector< Pair<int> > const & v, std::vector<int> & o);

  protected:

    int   _len;
    char* _rep;
	int   _flags;
	int   _allocLength;

	enum Flags {Alloc=1, Ref=2};
	static SS& nullref;
	static char const * formatStringLongLong;
	static char const * formatStringULongLong;

	int translateIndex (int ind) const;
	int translateLength (int len) const;
	int translateCheck (int ind) const;  // produces an out-of-range error
	void check  (int  ind)           const;  // produces an out-of-range error
	void adjust (int& ind)           const;  // adjusts ind to be inside string
	bool findCheck (int beg, int end, int inc) const;
	void lenAdjust (int& len) const;         // check for invalid length
	void pasteAdjust (int& ind) const;         // paste index can be length
	void modAdjust (int& beg, int& end, int inc) const;
	bool matchAdjust (int& beg) const;
	bool verify3 (SS const & s, int pos, int beg, int len) const;
	bool adjust3 (SS const & s, int& p, int& b, int& l) const;
	int _tryInd (int i) const;

	bool isAlloc    () const;
	void setAlloc   ();
	void setNoAlloc ();
	bool isRef      () const;
	void setRef     ();
	void setNoRef   ();
	void checkFlags () const;

	bool addressInside (void const * p) const;

	enum { HeadSample=20 };

	// give subclass a way in
	class DoNothing { };
    SS (DoNothing);

    virtual void destroy();

	void  _leng  (int n);
	void  _data  (void const * s);
	void  _data  (string const & s);
	void  _data  (std::vector<char> const & v);
	void  _setData (char * rep, int len, int flags, int allocLength);
	void  _setData (SS const & s);
	void  _zero  ();
	void  _null  ();

	// maybe put this into a separate "Umber" class
	template <class T> static inline int compareNumeric (T a, T b) {
		if (a>b) return 1;
		if (a<b) return -1;
		return 0;
	}
	static int compareBool (bool a, bool b);
	static int compareString (char const * a, int l0, string const & b);
	static int compareVector (char const * a, int l0, std::vector<char> const & b);
	int compareChar (char b) const;

	int findChar (char c, int beg, int end, int inc) const;
	int findFinder (Find const & finder, int beg, int end, int inc, int* len) const;
	int findString (SS const & s, int beg, int end, int inc) const;
	int findStringHelper (SS const & s, int beg, int end, int inc) const;
	bool matchString (char const * s, int len, int pos) const;
	int doFind (Find const & finder, int beg, SS& result, int inc) const;
	int doFindString (SS const & s, int beg, SS& result, int inc) const;
	Pair<int> doFindMatch (Find const & finder, int beg, int inc) const;
	Pair<int> doFindStringMatch (SS const & s, int beg, int inc) const;

	SS makeHeadSample () const;

	friend class SubSS;
	friend struct FindString;
	friend void SSconvert (SubSS const & u, SS & w) { w = u.get(); }

};

#ifdef SS_STANDALONE
template <class T>
struct Pair { T _0; T _1; Pair(T t0,T t1) : _0(t0),_1(t1) {} Pair () {} };
#endif

// non-member conversion functions
void SSconvert (SS const & u,                SS & w);
void SSconvert (char const * u,              SS & w);
void SSconvert (unsigned char const * u,     SS & w);
void SSconvert (signed char const * u,       SS & w);
void SSconvert (char u,                      SS & w);
void SSconvert (unsigned char u,             SS & w);
void SSconvert (signed char u,               SS & w);
void SSconvert (bool u,                      SS & w);
void SSconvert (short u,                     SS & w);
void SSconvert (unsigned short u,            SS & w);
void SSconvert (int u,                       SS & w);
void SSconvert (unsigned int u,              SS & w);
void SSconvert (long u,                      SS & w);
void SSconvert (unsigned long u,             SS & w);
void SSconvert (SS::LongLong u,              SS & w);
void SSconvert (SS::ULongLong u,             SS & w);
void SSconvert (float u,                     SS & w);
void SSconvert (double u,                    SS & w);
void SSconvert (long double u,               SS & w);
void SSconvert (SS::string        const & u, SS & w);
void SSconvert (std::vector<char> const & u, SS & w);
void SSconvert (SS::Buffer        const & u, SS & w);

void SSconvertFrom (SS const & u, SS                    & w);
void SSconvertFrom (SS const & u, char const          * & w);
void SSconvertFrom (SS const & u, unsigned char const * & w);
void SSconvertFrom (SS const & u, signed char const   * & w);
void SSconvertFrom (SS const & u, char                  & w);
void SSconvertFrom (SS const & u, unsigned char         & w);
void SSconvertFrom (SS const & u, signed char           & w);
void SSconvertFrom (SS const & u, bool                  & w);
void SSconvertFrom (SS const & u, short                 & w);
void SSconvertFrom (SS const & u, unsigned short        & w);
void SSconvertFrom (SS const & u, int                   & w);
void SSconvertFrom (SS const & u, unsigned int          & w);
void SSconvertFrom (SS const & u, long                  & w);
void SSconvertFrom (SS const & u, unsigned long         & w);
void SSconvertFrom (SS const & u, SS::LongLong          & w);
void SSconvertFrom (SS const & u, SS::ULongLong         & w);
void SSconvertFrom (SS const & u, float                 & w);
void SSconvertFrom (SS const & u, double                & w);
void SSconvertFrom (SS const & u, long double           & w);
void SSconvertFrom (SS const & u, SS::string            & w);
void SSconvertFrom (SS const & u, std::vector<char>     & w);
void SSconvertFrom (SS const & u, SS::Buffer            & w);

// non-member comparison functions
int SScompare (SS const & u, SS                const & w);
int SScompare (SS const & u, char              const * w);
int SScompare (SS const & u, unsigned char     const * w);
int SScompare (SS const & u, signed char       const * w);
int SScompare (SS const & u, char                      w);
int SScompare (SS const & u, unsigned char             w);
int SScompare (SS const & u, signed char               w);
int SScompare (SS const & u, bool                      w);
int SScompare (SS const & u, short                     w);
int SScompare (SS const & u, unsigned short            w);
int SScompare (SS const & u, int                       w);
int SScompare (SS const & u, unsigned int              w);
int SScompare (SS const & u, long                      w);
int SScompare (SS const & u, unsigned long             w);
int SScompare (SS const & u, SS::LongLong              w);
int SScompare (SS const & u, SS::ULongLong             w);
int SScompare (SS const & u, float                     w);
int SScompare (SS const & u, double                    w);
int SScompare (SS const & u, long double               w);
int SScompare (SS const & u, SS::string        const & w);
int SScompare (SS const & u, std::vector<char> const & w);

// non-member concatenation
template <class T>
inline SS operator + (T const & u, SS const & w) { return SS::concatenate (u,w); }

// non-member relational operators
template <class T>
inline bool operator == (T const & u, SS const & w) { return SScompare (w,u) == 0; }
template <class T>
inline bool operator != (T const & u, SS const & w) { return SScompare (w,u) != 0; }
template <class T>
inline bool operator <  (T const & u, SS const & w) { return SScompare (w,u) >  0; }
template <class T>
inline bool operator >  (T const & u, SS const & w) { return SScompare (w,u) <  0; }
template <class T>
inline bool operator <= (T const & u, SS const & w) { return SScompare (w,u) >= 0; }
template <class T>
inline bool operator >= (T const & u, SS const & w) { return SScompare (w,u) <= 0; }


// insert string into an ostream
std::ostream& operator << (std::ostream& os, SS const & s);

// inlines
inline int SS::length () const { return _len; }
inline int SS::size () const { return _len; }
inline bool SS::empty  () const { return _len==0; }
inline SS::operator char* () { return _rep; }
inline SS::operator char const * () const { return _rep; }
inline char* SS::c_str () { return _rep; }
inline char const * SS::c_str () const { return _rep; }
inline char* SS::data () { return _rep; }
inline char const * SS::data () const { return _rep; }
inline char * SS::begin () { return _rep; }
inline char const * SS::begin () const { return _rep; }
inline char * SS::end () { return _rep + _len; }
inline char const * SS::end () const { return _rep + _len; }
inline int SS::_tryInd (int i) const { return i>=0 && i<_len ? i : translateCheck(i); }
inline char & SS::operator [] (int ind) { return _rep[_tryInd(ind)]; }
inline char const & SS::operator [] (int ind) const { return _rep[_tryInd(ind)]; }
inline char & SS::at (int ind) { return _rep[_tryInd(ind)]; }
inline char const & SS::at (int ind) const { return _rep[_tryInd(ind)]; }

// end SUPER_STRING_HH
#endif

⌨️ 快捷键说明

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