37
37
38
38
// C++ variants of C standard header files
39
39
#include < map>
40
- #include < uchar.h>
41
- #include < cstring>
42
40
43
41
#include < sys/types.h>
44
42
#include < sys/stat.h>
59
57
#include " base/textstream_fwd.h"
60
58
#include " base/textstreambuffer.h"
61
59
#include " base/image/image_fwd.h"
60
+ #include " base/stringutilities.h"
62
61
63
62
// this must be the last file included
64
63
#include " base/povdebug.h"
@@ -68,9 +67,7 @@ namespace pov_image_cache
68
67
{
69
68
using namespace pov_base ;
70
69
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);
74
71
75
72
struct ImageCacheEntry final
76
73
{
@@ -83,22 +80,20 @@ namespace pov_image_cache
83
80
// Gets the last modified time from the filesystem
84
81
__time64_t GetLastModifiedTime (const std::string filename)
85
82
{
86
- char * cstrFilename = StrToChar ( filename);
83
+ const char * cstrFilename = filename. c_str ( );
87
84
88
85
struct stat result;
89
86
if (stat (cstrFilename, &result) == 0 )
90
87
{
91
- delete cstrFilename;
92
88
return result.st_mtime ;
93
89
}
94
- delete cstrFilename;
95
90
return 0 ;
96
91
}
97
92
98
93
// Try to get the image from the cache
99
94
Image* GetCachedImage (const UCS2* filename)
100
95
{
101
- std::string lookupFilename = U16toString (filename);
96
+ std::string lookupFilename = pov_base::UCS2toSysString (filename);
102
97
103
98
std::map<std::string, ImageCacheEntry>::iterator idx = Cache.find (lookupFilename);
104
99
if (idx != Cache.end ())
@@ -118,7 +113,7 @@ namespace pov_image_cache
118
113
// Store a new image into cache
119
114
void StoreImageInCache (const UCS2* filename, Image* image)
120
115
{
121
- std::string lookupFilename = U16toString (filename);
116
+ std::string lookupFilename = pov_base::UCS2toSysString (filename);
122
117
__time64_t lastModified = GetLastModifiedTime (lookupFilename);
123
118
Cache[lookupFilename] = ImageCacheEntry{ image = image, lastModified = lastModified };
124
119
}
@@ -136,31 +131,4 @@ namespace pov_image_cache
136
131
Cache.erase (it);
137
132
}
138
133
}
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
-
166
134
}
0 commit comments