📄 jstring.h
字号:
/*
This library was downloaded from: http://www.mike95.com
This library is copyright. It may freely be used for personal purposes
if the restriction listed below is adhered to.
Author: Michael Olivero
Email: mike95@mike95.com
//===============================
//Start of Restriction Definition
//===============================
Anyone can have full use of the library provided they keep this complete comment
with the source. Also I would like to ask if any changes are made to the
code for efficiency reasons, please let me know so I may look into your change and
likewise incorporate it into library. If a suggestion makes it into the library,
your credits will be added to this information.
Authors of Computer related books are welcome to include this source code as part
of their publishing, provided credit the Author and make note of where the source
code was obtained from: http://www.mike95.com
//=============================
//End of Restriction Definition
//=============================
Description:
Visit http://www.mike95.com/c_plusplus/classes/JString/
This library avoids the need to use pointers to char or manual
memory manipulation while working with Strings. This class has been
based on the Java String class, and thus has all of the Java public functionality
with a few extras [replace()] needed for useful functionality.
//The following people have contributed to the solution
//of bugs or improvements in this library
//=====================================================
//Carl Pupa, [pumacat@erols.com]
//Thomas Watson, [w@tson.dk]
//Subbiah, Venkat [vsubbiah@corvis.com]
//Oren Tirosh [mailto:oren@hishome.net]
*/
#ifndef _JString
#define _JString
#include "AEEStdLib.h"
//#include "Ducati.h"
typedef unsigned int UINT;
class JString
{
public:
// Constructor(s) / Destructors
//-----------------------------
JString( const char *Value = "" );
JString( const JString &Value );
virtual ~JString() {
FREE(Buffer);
}
//Operators
//----------
const JString & operator = ( const JString &Rhs );
const JString & operator +=( const JString &Rhs );
const JString & operator +=( const char );
const JString & operator +=( int aNum );
const JString & operator +=( long aNum );
int operator ==( const JString &Rhs ) const;
int operator !=( const JString &Rhs ) const;
int operator < ( const JString &Rhs ) const;
int operator > ( const JString &Rhs ) const;
int operator <=( const JString &Rhs ) const;
int operator >=( const JString &Rhs ) const;
char operator []( UINT Index ) const;
char& operator []( UINT Index );
//Methods
//-------
//INSPECTORS
//==========
char charAt( UINT index ) const;
int compareTo( const JString &anotherString ) const;
const char* cstr( ) const { return Buffer; }
int endsWith( const JString &suffix ) const;
int equals( const JString &anObject ) const;
int equalsIgnoreCase( const JString &anotherString ) const;
int indexOf( char ch ) const;
int indexOf( char ch, UINT fromIndex ) const;
int indexOf( const JString &str ) const;
int indexOf( const JString &str, UINT fromIndex ) const;
int lastIndexOf( char ch ) const;
int lastIndexOf( char ch, UINT fromIndex ) const;
int lastIndexOf( const JString &str ) const;
int lastIndexOf( const JString &str, UINT fromIndex ) const;
const UINT length( ) const { return Length; }
int startsWith( const JString &prefix ) const;
int startsWith( const JString &prefix, UINT toffset ) const;
JString substring( UINT beginIndex ) const;
JString substring( UINT beginIndex, UINT endIndex ) const;
JString toLowerCase( ) const;
JString toUpperCase( ) const;
JString trim( ) const;
//Methods
//-------
//MODIFIERS
//=========
const JString& concat( const JString &str );
JString replace( char oldChar, char newChar );
char *Buffer; // Stores the chars
protected:
//Members
//-------
UINT BufferLen; // Max strlen for Buffer
UINT Length; // Length of string
void GetBuffer(UINT MaxStrLen);
void Double( );
};
//Class Functions
//===============
inline void JString::GetBuffer(UINT MaxStrLen)
{
BufferLen = MaxStrLen;
Buffer = (char*) MALLOC((BufferLen+1)*sizeof(char));
}
inline void JString::Double( )
{
char *temp = Buffer;
GetBuffer( ++BufferLen * 2 );
STRCPY( Buffer, temp );
FREE(temp);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -