afString.h
资源名称:AirForce.rar [点击查看]
上传用户:kaiguan
上传日期:2007-10-28
资源大小:1074k
文件大小:4k
源码类别:
其他游戏
开发平台:
Visual C++
- // afString.h: interface for the afString class.
- //
- //////////////////////////////////////////////////////////////////////
- #ifndef AF_STRING
- #define AF_STRING
- #pragma once
- #include <string.h>
- #include <assert.h>
- class afString
- {
- public:
- /// Creates an empty string
- afString(){ string = NULL;};
- /// Creates a string as a copy of another pgString object
- afString(const afString& other);
- /// Creates a string as a copy of a char pointer
- afString(const char *nString);
- ~afString();
- /// Formats the given string and stores it.
- afString&
- set(const char *nString,...);
- /// Formats the given string and adds it.
- afString&
- cat(const char *nString);
- /// Sets a new buffer directly
- /**
- * CAUTION: the pgString object takes the ownership of the buffer; so do not delete it.
- */
- void setBuffer(char* nBuffer);
- /// Returns the length of the string.
- int length() const;
- /// Returns the length of the string.
- int getLength() const { return length(); }
- /// Does the string consists just the chars of the cSet??
- /**
- * If the string only contains the characters in cSet
- * true is returned.
- */
- bool consistsJustOf(const afString& cSet) const;
- /// Returns the first/last occurence of c;
- int getIndex(const char c,bool forward=true) const;
- /// Returns the first/last occurence of c; after start.
- /**
- * If start is -1, then the search begins either at index 0 or Last()
- */
- int getIndex(int start,const char c,bool forward=true) const;
- /// Returns the first/last char that is not c.
- int getIndexNot(const char c,bool forward=true) const;
- /// Returns the first/last char that is not c.
- /// If start==-1, then the search begins either at index 0 or Last().
- int getIndexNot(int start,const char c,bool forward=true) const;
- /// Returns the first/last occurence of str;
- int getIndex(const afString& other,bool forward=true) const;
- /// Returns the first/last occurence of str
- /// If start==-1, then the search begins either at index 0 or Last()
- int getIndex(int start,const afString& other,bool forward=true) const;
- /// Returns the amount of occurence of c
- int getCNum(const char c) const;
- /// Gives direct access to the string's data
- const char *
- get() const { return (string!=NULL ? string : ""); }
- /// Returns a substring
- afString getSubString(int from,int count) const;
- /// Converts all charater to lower characters.
- afString& toLower();
- /// Converts all charater to upper characters.
- afString& toUpper();
- /// Returns the lower of the passed character
- static char toLower(char nC);
- /// Returns the upper of the passed character
- static char toUpper(char nC);
- /// Cuts all leading/ending c-s
- afString& cutC(const char c,bool forward=true);
- /// Cuts all chars c of
- afString& cut(char c);
- afString& cutS(const afString& cs, bool forward=true);
- afString& cut(const afString& cs);
- /// Returns the index of the substring. Returns -1 of not found
- int find(const afString& nSubString);
- /// concanates two strings
- friend inline afString
- operator+( const afString& left, const afString& right);
- bool
- operator<( const afString& ) const;
- bool
- operator>( const afString& ) const;
- bool
- operator==( const afString& ) const;
- bool
- operator==( const char* str ) const;
- bool
- operator!=( const afString& ) const;
- bool
- operator!=( const char* str ) const;
- afString&
- operator=( const afString& );
- afString&
- operator+=( const afString& );
- char
- operator[](int index) const
- { assert(index<length()&&index>=0);return string[index]; }
- operator const char *() const
- { return get(); }
- protected:
- char *string;
- };
- inline afString operator+( const afString& left, const afString& right)
- {
- afString ret(left);
- ret.cat(right);
- return ret;
- }
- #endif