|
//////////////////////////////////////////////////////////////////////////////////////////////////////
// AUTHOR : Ganesh.M.Ramaswamy
// VERSION : 1.0
// BRIEF : Definition for class that has all String manipulation routines
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) - Ganesh.M.Ramaswamy
// All rights reserved
///////////////////////////////////////////////////////////////////////////////////////////////////////
/* DESCRIPTION
CXString : This class provides all the functionalities needed for string manipulation. Other than
performing all the normal operations this class provides a few special operations.
Many functions accepts a flag (bFlag). If this flag is et to false then the actual inner lying string will
not be affected in the operations. Only a shallow operation is performed instead of a deep operation.
For example if the CXString contains "Test" (case sensitive). If an operation say MakeUpper is performed
in this object with the flag set to false to actually u get a CXString object as an output that hs the
case changed to upper(TEST). But still the value in the original object remains the same("Test"). Actually
I had a need somethign like this. SO i think it may be useful. Default value is _true_.
Moreover it accepts most common datatypes in the constructor (say int,float) and has corresponding conversion
routines
*/
#ifndef __CXSTRING__
#define __CXSTRING__
#pragma once
#include <string.h> // for string and memory routines
#include <stdlib.h> // for data conversions
class CXString
{
public:
// constructors
CXString(); // default constructor
CXString(const CXString &xString); // copy constructor
CXString(char ch, int nRepeat); // for repeating the character the 'nRepeat' times
CXString(char *pszString); // for char* - thats it
CXString(int nVal); // accepting a integer and converting it into a string
CXString(long lVal); // accepting a long and converting it into a string
CXString(float fVal,int nDec); // accepting a float and converting it into a string
CXString(double dblVal,int nDec); // accepting a integer and converting it into a string
CXString(wchar_t wcsVal); // for wide-character string
// manipulation functions
int Length() const;
char GetAt(int nPos); // for getting a character at the specified position
void Empty(); // makes the string empty
bool IsEmpty(); // checking the string has characters
void SetAt(char nChar,int nPos); // overrides the character at the specified position if buffer available
// comparison functions
int Compare(char *pszNewString); // comparison without case
int Compare(CXString *cxsNewString); // for comparing objects
int CompareNoCase(char *pszNewString); // comparison without case
int CompareNoCase(CXString *cxsNewString); // comparison without case
// extraction functions
CXString Mid(int nFirst,int nCount = 0); // for extracting the characters from the string
CXString Left(int nCount); // come on no explanations needed i suppose
CXString Right(int nCount);
// conversion function
CXString MakeUpper(bool bFlag = true); // makes the string in upper case and returns the converted string
CXString MakeLower(bool bFlag = true); // makes the string in lower case and returns the converted string
CXString MakeReverse(bool bFlag = true); // reversal of the string
CXString Replace(char chOld,char chNew, bool bFlag = true,int nOccur = 0); // replaces a character with the new character
CXString Replace(char* pszOld, char *pszNew, bool bFlag = true, int nOccur = 0); // replaces a set of characters
CXString Remove(char chChar); // removes the specified character from the string
// other conversion functions
int ToInt(); // converts the string to integer
float ToFloat(); // converts to float
double ToDouble(); // converts to double
wchar_t ToWideChar(); // converts to wide character format
// other functions
void Insert(char chChar, int nPos); // inserts the character at the specified position. Size grows
void Insert(char *pszString,int nPos); // inserts a set of charecters at the specified position
CXString TrimLeft(char chChar = ' ', bool bFlag = true); // trims the specified character from the left of the string
CXString TrimRight(char chChar = ' ', bool bFlag = true); // trims the specified character from the right of the string
char* GetCharString() const; // one of the most important functions because it returns the actual char* value
// searching functions
int Find(char chChar,int nPos = 0); // finds the specified character and returns the first position of the same
int Find(char *pszString,int nPos = 0); // finds the specified set of characters and returns the first position of the first character
int ReverseFind(char chChar, int nPos = 0); // finds the specified character from the last and returns the first position
int ReverseFind(char* pszString,int nPos = 0); // finds the specified set of characters from the last and returns the first position of the first character
// overlaoded operators
CXString operator =(CXString xString);
CXString operator =(char *pszString);
CXString operator =(char chChar);
int operator ==(CXString xString);
int operator ==(char *pszString);
int operator ==(char chChar);
CXString operator +(CXString xString);
CXString operator +(char *pszString);
CXString operator +(char chChar);
private:
char *m_pszString; // the most used member variable
void InsertPrivate(char *pszOldString, char *pszNewString,int nPos); // used for making a insertion of charecters. this can insert charecters into any string provided and not only to the member variable string
CXString MidPrivate(char *pszString,int nFirst,int nCount = 0); // used for getting the mid of charecters. this can get mid of charecters from any string provided and not only to the member variable string
};
#endif // __CXSTRING__
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.