2012-01-08 17:35:29 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2011 Birunthan Mohanathas
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2012-01-23 06:36:15 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2012-01-08 17:35:29 +00:00
|
|
|
*/
|
|
|
|
|
2013-05-31 14:34:36 +00:00
|
|
|
#ifndef RM_COMMON_RAWSTRING_H_
|
|
|
|
#define RM_COMMON_RAWSTRING_H_
|
2012-01-08 17:35:29 +00:00
|
|
|
|
2013-12-24 11:20:19 +00:00
|
|
|
#include <malloc.h>
|
2012-01-08 17:35:29 +00:00
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
class RawString
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-05-31 14:18:52 +00:00
|
|
|
RawString() :
|
2012-01-08 17:35:29 +00:00
|
|
|
m_String()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-12-24 11:20:19 +00:00
|
|
|
RawString(const wchar_t* str) :
|
2012-01-08 17:35:29 +00:00
|
|
|
m_String(str_alloc(str))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
RawString(const RawString& rhs) :
|
2012-03-17 12:23:49 +00:00
|
|
|
m_String(str_alloc(rhs.c_str()))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
~RawString()
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2013-12-24 11:20:19 +00:00
|
|
|
RawString& operator=(const wchar_t* rhs)
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
m_String = str_alloc(rhs);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
RawString& operator=(const RawString& rhs)
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
|
|
|
if (&rhs != this)
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
m_String = str_alloc(rhs.m_String);
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-12-24 11:20:19 +00:00
|
|
|
const wchar_t* c_str() const
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
|
|
|
return m_String ? m_String : L"";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool empty() const
|
|
|
|
{
|
|
|
|
return !m_String || !(*m_String);
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
if (m_String)
|
|
|
|
{
|
|
|
|
free(m_String);
|
2013-05-31 14:28:39 +00:00
|
|
|
m_String = nullptr;
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-12-24 11:20:19 +00:00
|
|
|
wchar_t* str_alloc(const wchar_t* str)
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
return str ? _wcsdup(str) : nullptr;
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
|
|
|
|
2013-12-24 11:20:19 +00:00
|
|
|
wchar_t* m_String;
|
2012-01-08 17:35:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|