Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
#172: moved class WString to NString.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
hugbug committed Feb 26, 2016
1 parent 232c1a5 commit 7fc6d9e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
1 change: 0 additions & 1 deletion daemon/feed/FeedFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "Log.h"
#include "DownloadInfo.h"
#include "Options.h"
#include "FileSystem.h"
#include "Util.h"

FeedFile::FeedFile(const char* fileName)
Expand Down
10 changes: 0 additions & 10 deletions daemon/util/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,16 +834,6 @@ CString FileSystem::WidePathToUtfPath(const wchar_t* wpath)
#endif


#ifdef WIN32
WString::WString(const char* utfstr)
{
int len = MultiByteToWideChar(CP_UTF8, 0, utfstr, -1, nullptr, 0);
m_data = (wchar_t*)malloc((len + 1) * sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8, 0, utfstr, -1, m_data, len);
}
#endif


#ifdef WIN32
DirBrowser::DirBrowser(const char* path)
{
Expand Down
17 changes: 0 additions & 17 deletions daemon/util/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,4 @@ class DiskFile
bool Sync(CString& errmsg);
};

#ifdef WIN32
class WString
{
private:
wchar_t* m_data = nullptr;
public:
WString(wchar_t* wstr) : m_data(_wcsdup(wstr)) {}
WString(const char* utfstr);
~WString() { free(m_data); }
WString(WString&& other) noexcept { m_data = other.m_data; other.m_data = nullptr; }
WString(WString& other) = delete;
operator wchar_t*() const { return m_data; }
wchar_t* operator*() const { return m_data; }
int Length() { return wcslen(m_data); }
};
#endif

#endif
10 changes: 10 additions & 0 deletions daemon/util/NString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,16 @@ void CString::TrimRight()
}


#ifdef WIN32
WString::WString(const char* utfstr)
{
int len = MultiByteToWideChar(CP_UTF8, 0, utfstr, -1, nullptr, 0);
m_data = (wchar_t*)malloc((len + 1) * sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8, 0, utfstr, -1, m_data, len);
}
#endif


void StringBuilder::Clear()
{
free(m_data);
Expand Down
20 changes: 20 additions & 0 deletions daemon/util/NString.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,26 @@ class CString
void TrimRight();
};

#ifdef WIN32
/*
Wide-character string, Windows specific.
*/
class WString
{
private:
wchar_t* m_data = nullptr;
public:
WString(wchar_t* wstr) : m_data(_wcsdup(wstr)) {}
WString(const char* utfstr);
~WString() { free(m_data); }
WString(WString&& other) noexcept { m_data = other.m_data; other.m_data = nullptr; }
WString(WString& other) = delete;
operator wchar_t*() const { return m_data; }
wchar_t* operator*() const { return m_data; }
int Length() { return wcslen(m_data); }
};
#endif

/*
StringBuilder preallocates storage space and is best suitable for often "Append"s.
*/
Expand Down

0 comments on commit 7fc6d9e

Please sign in to comment.