Skip to content

Commit 3989f81

Browse files
committed
Use pov_base::UCS2toSysString instead of own function.
1 parent b5ef870 commit 3989f81

File tree

1 file changed

+5
-37
lines changed

1 file changed

+5
-37
lines changed

source/parser/ImageCache.cpp

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737

3838
// C++ variants of C standard header files
3939
#include <map>
40-
#include <uchar.h>
41-
#include <cstring>
4240

4341
#include <sys/types.h>
4442
#include <sys/stat.h>
@@ -59,6 +57,7 @@
5957
#include "base/textstream_fwd.h"
6058
#include "base/textstreambuffer.h"
6159
#include "base/image/image_fwd.h"
60+
#include "base/stringutilities.h"
6261

6362
// this must be the last file included
6463
#include "base/povdebug.h"
@@ -68,9 +67,7 @@ namespace pov_image_cache
6867
{
6968
using namespace pov_base;
7069
using namespace std;
71-
static inline std::string U16toString(const std::u16string& wstr);
72-
static inline char* StrToChar(const std::string str);
73-
static inline char* U16toChar(const std::u16string& wstr);
70+
//static inline char* StrToChar(const std::string str);
7471

7572
struct ImageCacheEntry final
7673
{
@@ -83,22 +80,20 @@ namespace pov_image_cache
8380
// Gets the last modified time from the filesystem
8481
__time64_t GetLastModifiedTime(const std::string filename)
8582
{
86-
char* cstrFilename = StrToChar(filename);
83+
const char* cstrFilename = filename.c_str();
8784

8885
struct stat result;
8986
if (stat(cstrFilename, &result) == 0)
9087
{
91-
delete cstrFilename;
9288
return result.st_mtime;
9389
}
94-
delete cstrFilename;
9590
return 0;
9691
}
9792

9893
// Try to get the image from the cache
9994
Image* GetCachedImage(const UCS2* filename)
10095
{
101-
std::string lookupFilename = U16toString(filename);
96+
std::string lookupFilename = pov_base::UCS2toSysString(filename);
10297

10398
std::map<std::string, ImageCacheEntry>::iterator idx = Cache.find(lookupFilename);
10499
if (idx != Cache.end())
@@ -118,7 +113,7 @@ namespace pov_image_cache
118113
// Store a new image into cache
119114
void StoreImageInCache(const UCS2* filename, Image* image)
120115
{
121-
std::string lookupFilename = U16toString(filename);
116+
std::string lookupFilename = pov_base::UCS2toSysString(filename);
122117
__time64_t lastModified = GetLastModifiedTime(lookupFilename);
123118
Cache[lookupFilename] = ImageCacheEntry{ image = image, lastModified = lastModified };
124119
}
@@ -136,31 +131,4 @@ namespace pov_image_cache
136131
Cache.erase(it);
137132
}
138133
}
139-
140-
static inline std::string U16toString(const std::u16string& wstr)
141-
{
142-
std::string str = "";
143-
char cstr[3] = "\0";
144-
mbstate_t mbs;
145-
for (const auto& it : wstr) {
146-
memset(&mbs, 0, sizeof(mbs));//set shift state to the initial state
147-
memmove(cstr, "\0\0\0", 3);
148-
c16rtomb(cstr, it, &mbs);
149-
str.append(std::string(cstr));
150-
}//for
151-
return str;
152-
}
153-
154-
static inline char* StrToChar(const std::string str)
155-
{
156-
char* cstring = new char[str.length() + 1];
157-
strcpy(cstring, str.c_str());
158-
return cstring;
159-
}
160-
161-
static inline char* U16toChar(const std::u16string& wstr)
162-
{
163-
return StrToChar(U16toString(wstr));
164-
}
165-
166134
}

0 commit comments

Comments
 (0)