2010-09-06 14:54:14 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2011-03-18 14:31:29 +08:00
|
|
|
#ifndef __CCSTRING_H__
|
|
|
|
#define __CCSTRING_H__
|
2012-04-07 12:02:40 +08:00
|
|
|
|
2010-09-06 14:54:14 +08:00
|
|
|
#include <string>
|
2011-03-07 17:11:57 +08:00
|
|
|
#include "CCObject.h"
|
2012-03-05 11:13:45 +08:00
|
|
|
|
2012-04-07 12:02:40 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
class CC_DLL CCString : public CCObject
|
|
|
|
{
|
|
|
|
public:
|
2012-04-14 19:11:57 +08:00
|
|
|
CCString();
|
|
|
|
CCString(const char* str);
|
|
|
|
CCString(const std::string& str);
|
|
|
|
CCString(const CCString& str);
|
|
|
|
|
|
|
|
virtual ~CCString();
|
2012-04-07 12:02:40 +08:00
|
|
|
|
2012-04-16 10:57:37 +08:00
|
|
|
/* override assignment operator */
|
2012-04-14 19:11:57 +08:00
|
|
|
CCString& operator= (const CCString& other);
|
|
|
|
|
|
|
|
/** init a string with format, it's similar with the c function 'sprintf' */
|
|
|
|
bool initWithFormat(const char* format, ...);
|
|
|
|
|
|
|
|
/** convert to int value */
|
2012-04-16 10:57:37 +08:00
|
|
|
int intValue() const;
|
2012-04-14 19:11:57 +08:00
|
|
|
|
|
|
|
/** convert to unsigned int value */
|
2012-04-16 10:57:37 +08:00
|
|
|
unsigned int uintValue() const;
|
2012-04-14 19:11:57 +08:00
|
|
|
|
|
|
|
/** convert to float value */
|
2012-04-16 10:57:37 +08:00
|
|
|
float floatValue() const;
|
2012-04-14 19:11:57 +08:00
|
|
|
|
|
|
|
/** convert to double value */
|
2012-04-16 10:57:37 +08:00
|
|
|
double doubleValue() const;
|
2012-04-14 19:11:57 +08:00
|
|
|
|
|
|
|
/** convert to bool value */
|
2012-04-16 10:57:37 +08:00
|
|
|
bool boolValue() const;
|
2012-04-14 19:11:57 +08:00
|
|
|
|
|
|
|
/** get the C string */
|
2012-04-16 10:57:37 +08:00
|
|
|
const char* getCString() const;
|
2012-04-14 19:11:57 +08:00
|
|
|
|
|
|
|
/** get the length of string */
|
2012-04-16 10:57:37 +08:00
|
|
|
unsigned int length() const;
|
2012-04-14 19:11:57 +08:00
|
|
|
|
2012-04-16 10:57:37 +08:00
|
|
|
/* override functions */
|
2012-04-14 19:11:57 +08:00
|
|
|
virtual CCObject* copyWithZone(CCZone* pZone);
|
|
|
|
virtual bool isEqual(const CCObject* pObject);
|
|
|
|
|
2012-04-16 10:57:37 +08:00
|
|
|
/* static funcitons */
|
|
|
|
/** create a string with c string
|
|
|
|
* @return A CCString pointer which is an autorelease object pointer,
|
|
|
|
* it means that you needn't do a release operation unless you retain it.
|
|
|
|
*/
|
2012-04-14 19:11:57 +08:00
|
|
|
static CCString* stringWithCString(const char* pStr);
|
|
|
|
|
2012-04-16 10:57:37 +08:00
|
|
|
/** create a string with format, it's similar with the c function 'sprintf', the default buffer size is (1024*100) bytes,
|
|
|
|
* if you want to change it, you should modify the kMaxStringLen macro in CCString.cpp file.
|
|
|
|
* @return A CCString pointer which is an autorelease object pointer,
|
|
|
|
* it means that you needn't do a release operation unless you retain it.
|
|
|
|
*/
|
2012-04-14 19:11:57 +08:00
|
|
|
static CCString* stringWithFormat(const char* format, ...);
|
|
|
|
|
2012-04-16 10:57:37 +08:00
|
|
|
/** create a string with binary data
|
|
|
|
* @return A CCString pointer which is an autorelease object pointer,
|
|
|
|
* it means that you needn't do a release operation unless you retain it.
|
|
|
|
*/
|
2012-04-14 19:11:57 +08:00
|
|
|
static CCString* stringWithData(unsigned char* pData, unsigned long nLen);
|
|
|
|
|
2012-04-16 10:57:37 +08:00
|
|
|
/** create a string with a file,
|
|
|
|
* @return A CCString pointer which is an autorelease object pointer,
|
|
|
|
* it means that you needn't do a release operation unless you retain it.
|
|
|
|
*/
|
2012-04-14 19:11:57 +08:00
|
|
|
static CCString* stringWithContentsOfFile(const char* pszFileName);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/** only for internal use */
|
|
|
|
bool initWithFormatAndValist(const char* format, va_list ap);
|
|
|
|
|
|
|
|
public:
|
|
|
|
std::string m_sString;
|
2012-04-07 12:02:40 +08:00
|
|
|
};
|
|
|
|
|
2012-04-16 18:58:43 +08:00
|
|
|
#define CCStringMake(str) CCString::stringWithCString(str)
|
|
|
|
|
2012-04-07 12:02:40 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
2011-03-18 14:31:29 +08:00
|
|
|
#endif //__CCSTRING_H__
|